Vorschau-Bilder werden generiert und mit voll Ansicht verknüpft
This commit is contained in:
+70
-26
@@ -1,7 +1,8 @@
|
|||||||
import os
|
import os
|
||||||
from PySide6.QtWidgets import QMainWindow
|
import glob
|
||||||
from PySide6.QtGui import QPixmap
|
from PySide6.QtWidgets import QMainWindow, QLabel
|
||||||
# from PySide6.QtCore import Qt
|
from PySide6.QtGui import QPixmap, QCursor
|
||||||
|
from PySide6.QtCore import Qt
|
||||||
from ui.MainWinddow_ui import Ui_MainWindow
|
from ui.MainWinddow_ui import Ui_MainWindow
|
||||||
|
|
||||||
|
|
||||||
@@ -19,42 +20,85 @@ class MainWindow(QMainWindow):
|
|||||||
self.ui = Ui_MainWindow()
|
self.ui = Ui_MainWindow()
|
||||||
self.ui.setupUi(self)
|
self.ui.setupUi(self)
|
||||||
|
|
||||||
# Bilder korrekt laden
|
# Dict zum Speichern der Beziehung zwischen Thumbnails und großen Bildern
|
||||||
|
self.thumbnail_to_full_image = {}
|
||||||
|
|
||||||
|
# Bilder laden
|
||||||
self._load_images()
|
self._load_images()
|
||||||
|
|
||||||
# Signale und Slots verbinden
|
# Signale und Slots verbinden
|
||||||
self._connect_signals()
|
self._connect_signals()
|
||||||
|
|
||||||
def _load_images(self):
|
def _load_images(self):
|
||||||
"""Lädt die Bilder mit absoluten Pfaden."""
|
"""Lädt alle GIF-Dateien aus dem Ressourcen-Verzeichnis."""
|
||||||
|
# Entferne bestehende Widgets aus den Layouts
|
||||||
|
self._clear_layout(self.ui.verticalLayout_2)
|
||||||
|
self._clear_layout(self.ui.verticalLayout_3)
|
||||||
|
|
||||||
|
# Pfad zum Ressourcen-Ordner
|
||||||
base_dir = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
|
base_dir = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
|
||||||
|
res_dir = os.path.join(base_dir, "src", "ui", "res")
|
||||||
|
|
||||||
# Absolute Pfade zu den Bildern erstellen
|
# Alle GIF-Dateien finden
|
||||||
img1_path = os.path.join(base_dir, "src", "ui", "res", "graf_1.gif")
|
gif_files = glob.glob(os.path.join(res_dir, "*.gif"))
|
||||||
img2_path = os.path.join(base_dir, "src", "ui", "res", "graf_3.gif")
|
gif_files.sort() # Dateien alphabetisch sortieren
|
||||||
|
|
||||||
print(repr(self.ui.label), img2_path)
|
print(f"Gefundene GIF-Dateien: {gif_files}")
|
||||||
|
|
||||||
# Bilder setzen, wenn die Dateien existieren
|
# Für jede GIF-Datei:
|
||||||
if os.path.exists(img1_path):
|
for gif_file in gif_files:
|
||||||
self.ui.label.setPixmap(QPixmap(img1_path).scaledToWidth(200))
|
filename = os.path.basename(gif_file)
|
||||||
self.ui.label_3.setPixmap(QPixmap(img1_path))
|
|
||||||
else:
|
|
||||||
self.ui.label.setText(f"Fehler: Bild nicht gefunden: {img1_path}")
|
|
||||||
self.ui.label_3.setText(f"Fehler: Bild nicht gefunden: {img1_path}")
|
|
||||||
|
|
||||||
if os.path.exists(img2_path):
|
# Thumbnail erstellen und zur linken Spalte hinzufügen
|
||||||
self.ui.label_2.setPixmap(QPixmap(img2_path).scaledToWidth(200))
|
thumbnail = QLabel()
|
||||||
self.ui.label_4.setPixmap(QPixmap(img2_path))
|
thumbnail.setObjectName(f"thumbnail_{filename}")
|
||||||
else:
|
thumbnail.setPixmap(QPixmap(gif_file).scaledToWidth(200))
|
||||||
self.ui.label_2.setText(f"Fehler: Bild nicht gefunden: {img2_path}")
|
thumbnail.setCursor(QCursor(Qt.CursorShape.PointingHandCursor))
|
||||||
self.ui.label_4.setText(f"Fehler: Bild nicht gefunden: {img2_path}")
|
thumbnail.setMouseTracking(True)
|
||||||
|
self.ui.verticalLayout_2.addWidget(thumbnail)
|
||||||
|
|
||||||
|
# Vollbild-Version erstellen und zur rechten Spalte hinzufügen
|
||||||
|
fullsize = QLabel()
|
||||||
|
fullsize.setObjectName(f"fullsize_{filename}")
|
||||||
|
fullsize.setPixmap(QPixmap(gif_file))
|
||||||
|
self.ui.verticalLayout_3.addWidget(fullsize)
|
||||||
|
|
||||||
|
# Beziehung zwischen Thumbnail und Vollbild speichern
|
||||||
|
self.thumbnail_to_full_image[thumbnail] = fullsize
|
||||||
|
|
||||||
|
# Click-Event für das Thumbnail einrichten
|
||||||
|
thumbnail.mousePressEvent = lambda event, t=thumbnail: self.on_thumbnail_clicked(event, t)
|
||||||
|
|
||||||
|
def _clear_layout(self, layout):
|
||||||
|
"""Entfernt alle Widgets aus einem Layout."""
|
||||||
|
if layout is not None:
|
||||||
|
while layout.count():
|
||||||
|
item = layout.takeAt(0)
|
||||||
|
widget = item.widget()
|
||||||
|
if widget is not None:
|
||||||
|
widget.deleteLater()
|
||||||
|
|
||||||
def _connect_signals(self):
|
def _connect_signals(self):
|
||||||
"""Verbindet Signale mit den entsprechenden Slots."""
|
"""Verbindet Signale mit den entsprechenden Slots."""
|
||||||
# Beispiel für Signal-Verbindung:
|
# Button-Klicks verbinden
|
||||||
# self.ui.pushButton.clicked.connect(self.on_button_clicked)
|
# self.ui.pushButton.clicked.connect(self.on_button_clicked)
|
||||||
|
|
||||||
# Beispiel für einen Slot:
|
def on_button_clicked(self):
|
||||||
# def on_button_clicked(self):
|
"""Wird ausgeführt, wenn der Button geklickt wird."""
|
||||||
# print("Button wurde geklickt!")
|
print("Button wurde geklickt!")
|
||||||
|
# Hier kann die gewünschte Aktion für den Button definiert werden
|
||||||
|
|
||||||
|
def on_thumbnail_clicked(self, event, thumbnail):
|
||||||
|
"""
|
||||||
|
Wird ausgeführt, wenn ein Thumbnail angeklickt wird.
|
||||||
|
|
||||||
|
Args:
|
||||||
|
event: Das Maus-Event
|
||||||
|
thumbnail: Das geklickte Thumbnail-Label
|
||||||
|
"""
|
||||||
|
print(f"Thumbnail {thumbnail.objectName()} wurde angeklickt: {event}")
|
||||||
|
|
||||||
|
# Zum entsprechenden Vollbild scrollen
|
||||||
|
full_image = self.thumbnail_to_full_image.get(thumbnail)
|
||||||
|
if full_image:
|
||||||
|
self.ui.scrollArea_2.ensureWidgetVisible(full_image)
|
||||||
|
|||||||
+15
-21
@@ -59,19 +59,6 @@
|
|||||||
<enum>QFrame::Shadow::Raised</enum>
|
<enum>QFrame::Shadow::Raised</enum>
|
||||||
</property>
|
</property>
|
||||||
<layout class="QHBoxLayout" name="horizontalLayout_2">
|
<layout class="QHBoxLayout" name="horizontalLayout_2">
|
||||||
<item>
|
|
||||||
<spacer name="horizontalSpacer">
|
|
||||||
<property name="orientation">
|
|
||||||
<enum>Qt::Orientation::Horizontal</enum>
|
|
||||||
</property>
|
|
||||||
<property name="sizeHint" stdset="0">
|
|
||||||
<size>
|
|
||||||
<width>40</width>
|
|
||||||
<height>20</height>
|
|
||||||
</size>
|
|
||||||
</property>
|
|
||||||
</spacer>
|
|
||||||
</item>
|
|
||||||
<item>
|
<item>
|
||||||
<widget class="QPushButton" name="pushButton">
|
<widget class="QPushButton" name="pushButton">
|
||||||
<property name="layoutDirection">
|
<property name="layoutDirection">
|
||||||
@@ -98,6 +85,19 @@
|
|||||||
</property>
|
</property>
|
||||||
</widget>
|
</widget>
|
||||||
</item>
|
</item>
|
||||||
|
<item>
|
||||||
|
<spacer name="horizontalSpacer">
|
||||||
|
<property name="orientation">
|
||||||
|
<enum>Qt::Orientation::Horizontal</enum>
|
||||||
|
</property>
|
||||||
|
<property name="sizeHint" stdset="0">
|
||||||
|
<size>
|
||||||
|
<width>40</width>
|
||||||
|
<height>20</height>
|
||||||
|
</size>
|
||||||
|
</property>
|
||||||
|
</spacer>
|
||||||
|
</item>
|
||||||
</layout>
|
</layout>
|
||||||
</widget>
|
</widget>
|
||||||
</item>
|
</item>
|
||||||
@@ -120,8 +120,8 @@
|
|||||||
<rect>
|
<rect>
|
||||||
<x>0</x>
|
<x>0</x>
|
||||||
<y>0</y>
|
<y>0</y>
|
||||||
<width>2480</width>
|
<width>574</width>
|
||||||
<height>7070</height>
|
<height>847</height>
|
||||||
</rect>
|
</rect>
|
||||||
</property>
|
</property>
|
||||||
<layout class="QVBoxLayout" name="verticalLayout_2">
|
<layout class="QVBoxLayout" name="verticalLayout_2">
|
||||||
@@ -130,9 +130,6 @@
|
|||||||
<property name="text">
|
<property name="text">
|
||||||
<string/>
|
<string/>
|
||||||
</property>
|
</property>
|
||||||
<property name="pixmap">
|
|
||||||
<pixmap>res/graf_1.gif</pixmap>
|
|
||||||
</property>
|
|
||||||
</widget>
|
</widget>
|
||||||
</item>
|
</item>
|
||||||
<item>
|
<item>
|
||||||
@@ -140,9 +137,6 @@
|
|||||||
<property name="text">
|
<property name="text">
|
||||||
<string/>
|
<string/>
|
||||||
</property>
|
</property>
|
||||||
<property name="pixmap">
|
|
||||||
<pixmap>res/graf_3.gif</pixmap>
|
|
||||||
</property>
|
|
||||||
</widget>
|
</widget>
|
||||||
</item>
|
</item>
|
||||||
<item>
|
<item>
|
||||||
|
|||||||
@@ -60,10 +60,6 @@ class Ui_MainWindow(object):
|
|||||||
self.frame_2.setFrameShadow(QFrame.Shadow.Raised)
|
self.frame_2.setFrameShadow(QFrame.Shadow.Raised)
|
||||||
self.horizontalLayout_2 = QHBoxLayout(self.frame_2)
|
self.horizontalLayout_2 = QHBoxLayout(self.frame_2)
|
||||||
self.horizontalLayout_2.setObjectName(u"horizontalLayout_2")
|
self.horizontalLayout_2.setObjectName(u"horizontalLayout_2")
|
||||||
self.horizontalSpacer = QSpacerItem(40, 20, QSizePolicy.Policy.Expanding, QSizePolicy.Policy.Minimum)
|
|
||||||
|
|
||||||
self.horizontalLayout_2.addItem(self.horizontalSpacer)
|
|
||||||
|
|
||||||
self.pushButton = QPushButton(self.frame_2)
|
self.pushButton = QPushButton(self.frame_2)
|
||||||
self.pushButton.setObjectName(u"pushButton")
|
self.pushButton.setObjectName(u"pushButton")
|
||||||
self.pushButton.setLayoutDirection(Qt.LayoutDirection.LeftToRight)
|
self.pushButton.setLayoutDirection(Qt.LayoutDirection.LeftToRight)
|
||||||
@@ -80,6 +76,10 @@ class Ui_MainWindow(object):
|
|||||||
|
|
||||||
self.horizontalLayout_2.addWidget(self.pushButton_2)
|
self.horizontalLayout_2.addWidget(self.pushButton_2)
|
||||||
|
|
||||||
|
self.horizontalSpacer = QSpacerItem(40, 20, QSizePolicy.Policy.Expanding, QSizePolicy.Policy.Minimum)
|
||||||
|
|
||||||
|
self.horizontalLayout_2.addItem(self.horizontalSpacer)
|
||||||
|
|
||||||
|
|
||||||
self.verticalLayout.addWidget(self.frame_2)
|
self.verticalLayout.addWidget(self.frame_2)
|
||||||
|
|
||||||
@@ -96,18 +96,16 @@ class Ui_MainWindow(object):
|
|||||||
self.scrollArea.setWidgetResizable(True)
|
self.scrollArea.setWidgetResizable(True)
|
||||||
self.scrollAreaWidgetContents = QWidget()
|
self.scrollAreaWidgetContents = QWidget()
|
||||||
self.scrollAreaWidgetContents.setObjectName(u"scrollAreaWidgetContents")
|
self.scrollAreaWidgetContents.setObjectName(u"scrollAreaWidgetContents")
|
||||||
self.scrollAreaWidgetContents.setGeometry(QRect(0, 0, 2480, 7070))
|
self.scrollAreaWidgetContents.setGeometry(QRect(0, 0, 574, 847))
|
||||||
self.verticalLayout_2 = QVBoxLayout(self.scrollAreaWidgetContents)
|
self.verticalLayout_2 = QVBoxLayout(self.scrollAreaWidgetContents)
|
||||||
self.verticalLayout_2.setObjectName(u"verticalLayout_2")
|
self.verticalLayout_2.setObjectName(u"verticalLayout_2")
|
||||||
self.label = QLabel(self.scrollAreaWidgetContents)
|
self.label = QLabel(self.scrollAreaWidgetContents)
|
||||||
self.label.setObjectName(u"label")
|
self.label.setObjectName(u"label")
|
||||||
self.label.setPixmap(QPixmap(u"res/graf_1.gif"))
|
|
||||||
|
|
||||||
self.verticalLayout_2.addWidget(self.label)
|
self.verticalLayout_2.addWidget(self.label)
|
||||||
|
|
||||||
self.label_2 = QLabel(self.scrollAreaWidgetContents)
|
self.label_2 = QLabel(self.scrollAreaWidgetContents)
|
||||||
self.label_2.setObjectName(u"label_2")
|
self.label_2.setObjectName(u"label_2")
|
||||||
self.label_2.setPixmap(QPixmap(u"res/graf_3.gif"))
|
|
||||||
|
|
||||||
self.verticalLayout_2.addWidget(self.label_2)
|
self.verticalLayout_2.addWidget(self.label_2)
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user