connect thumbnail selection signal to main controller; enhance thumbnail handling with media ID
This commit is contained in:
@@ -19,6 +19,7 @@ class MainController:
|
|||||||
|
|
||||||
self.color_list.colorSelected.connect(self.on_color_selected)
|
self.color_list.colorSelected.connect(self.on_color_selected)
|
||||||
self.color_list.editColor.connect(self.on_edit_color)
|
self.color_list.editColor.connect(self.on_edit_color)
|
||||||
|
self.thumbnail_list.selectedThumbnail.connect(self.on_thumbnail_selected)
|
||||||
|
|
||||||
def load_colors(self) -> None:
|
def load_colors(self) -> None:
|
||||||
colors = self.db.get_all_colors()
|
colors = self.db.get_all_colors()
|
||||||
@@ -37,9 +38,16 @@ class MainController:
|
|||||||
for media in media_items:
|
for media in media_items:
|
||||||
if media['file_type'] == 'photo':
|
if media['file_type'] == 'photo':
|
||||||
file_name = Path(media['media_path']).name
|
file_name = Path(media['media_path']).name
|
||||||
self.thumbnail_list.add_thumbnail(media['media_path'], file_name)
|
self.thumbnail_list.add_thumbnail(media['media_path'], file_name, media['id'])
|
||||||
else:
|
else:
|
||||||
print(f"Nie znaleziono koloru o nazwie: {color_name}")
|
print(f"Nie znaleziono koloru o nazwie: {color_name}")
|
||||||
|
|
||||||
def on_edit_color(self, color_name: str):
|
def on_edit_color(self, color_name: str):
|
||||||
print(f"Edycja koloru: {color_name}")
|
print(f"Edycja koloru: {color_name}")
|
||||||
|
|
||||||
|
def on_thumbnail_selected(self, media_id: int):
|
||||||
|
media = self.db.get_media(media_id)
|
||||||
|
if media:
|
||||||
|
print(f"Wybrano miniaturę o ID: {media_id}, ścieżka: {media['media_path']}")
|
||||||
|
else:
|
||||||
|
print(f"Nie znaleziono mediów o ID: {media_id}")
|
||||||
|
|||||||
@@ -125,6 +125,14 @@ class DatabaseManager:
|
|||||||
)
|
)
|
||||||
self.conn.commit()
|
self.conn.commit()
|
||||||
|
|
||||||
|
def get_media(self, media_id: int) -> dict | None:
|
||||||
|
if self.conn is None:
|
||||||
|
raise RuntimeError("Database not connected")
|
||||||
|
cur = self.conn.cursor()
|
||||||
|
cur.execute("SELECT * FROM media WHERE id = ?", (media_id,))
|
||||||
|
row = cur.fetchone()
|
||||||
|
return dict(row) if row else None
|
||||||
|
|
||||||
def get_media_for_color(self, color_id: int) -> list[dict]:
|
def get_media_for_color(self, color_id: int) -> list[dict]:
|
||||||
if self.conn is None:
|
if self.conn is None:
|
||||||
raise RuntimeError("Database not connected")
|
raise RuntimeError("Database not connected")
|
||||||
|
|||||||
@@ -46,11 +46,6 @@ class MainWindow(QMainWindow):
|
|||||||
self.color_list_widget = ColorListWidget(self.control_widget)
|
self.color_list_widget = ColorListWidget(self.control_widget)
|
||||||
control_layout.addWidget(self.color_list_widget)
|
control_layout.addWidget(self.color_list_widget)
|
||||||
|
|
||||||
self.thumbnail_widget.add_thumbnail("media/red/bolton_01092025.jpg", "model 1")
|
|
||||||
self.thumbnail_widget.add_thumbnail("media/red/bolton_01092025.jpg", "model 2")
|
|
||||||
self.thumbnail_widget.add_thumbnail("media/red/bolton_01092025.jpg", "model 3")
|
|
||||||
self.thumbnail_widget.add_thumbnail("empty", "model 4")
|
|
||||||
|
|
||||||
record_button = QPushButton("Nagraj Wideo")
|
record_button = QPushButton("Nagraj Wideo")
|
||||||
record_button.setMinimumHeight(40)
|
record_button.setMinimumHeight(40)
|
||||||
record_button.setStyleSheet("font-size: 12pt;")
|
record_button.setStyleSheet("font-size: 12pt;")
|
||||||
|
|||||||
@@ -3,7 +3,7 @@ from PySide6.QtWidgets import (
|
|||||||
QLabel, QHBoxLayout
|
QLabel, QHBoxLayout
|
||||||
)
|
)
|
||||||
from PySide6.QtGui import QPixmap, QIcon
|
from PySide6.QtGui import QPixmap, QIcon
|
||||||
from PySide6.QtCore import Qt, QSize
|
from PySide6.QtCore import Qt, QSize, Signal
|
||||||
import sys
|
import sys
|
||||||
|
|
||||||
def make_thumbnail(image_path: str, size: QSize) -> QPixmap:
|
def make_thumbnail(image_path: str, size: QSize) -> QPixmap:
|
||||||
@@ -56,6 +56,8 @@ class ThumbnailItemWidget(QWidget):
|
|||||||
|
|
||||||
|
|
||||||
class ThumbnailListWidget(QWidget):
|
class ThumbnailListWidget(QWidget):
|
||||||
|
selectedThumbnail = Signal(int) # sygnał z ID wybranego elementu
|
||||||
|
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
super().__init__()
|
super().__init__()
|
||||||
layout = QVBoxLayout(self)
|
layout = QVBoxLayout(self)
|
||||||
@@ -69,8 +71,9 @@ class ThumbnailListWidget(QWidget):
|
|||||||
|
|
||||||
self.list_widget.itemPressed.connect(self.on_item_pressed)
|
self.list_widget.itemPressed.connect(self.on_item_pressed)
|
||||||
|
|
||||||
def add_thumbnail(self, image_path: str, text: str):
|
def add_thumbnail(self, image_path: str, text: str, id: int):
|
||||||
item = QListWidgetItem()
|
item = QListWidgetItem()
|
||||||
|
item.setData(Qt.ItemDataRole.UserRole, id)
|
||||||
item.setSizeHint(QSize(192, 192)) # rozmiar „wiersza”
|
item.setSizeHint(QSize(192, 192)) # rozmiar „wiersza”
|
||||||
|
|
||||||
print(f"Adding thumbnail: {image_path} with text: {text}")
|
print(f"Adding thumbnail: {image_path} with text: {text}")
|
||||||
@@ -80,5 +83,7 @@ class ThumbnailListWidget(QWidget):
|
|||||||
|
|
||||||
def on_item_pressed(self, item: QListWidgetItem):
|
def on_item_pressed(self, item: QListWidgetItem):
|
||||||
row = self.list_widget.row(item)
|
row = self.list_widget.row(item)
|
||||||
print(f"Kliknięto miniaturę w wierszu: {row}")
|
id = item.data(Qt.ItemDataRole.UserRole)
|
||||||
|
print(f"Kliknięto miniaturę w wierszu: {row}, obiekt ID: {id}")
|
||||||
|
self.selectedThumbnail.emit(id)
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user