diff --git a/tagstudio/src/qt/ts_qt.py b/tagstudio/src/qt/ts_qt.py index df53f4da..0e352a2a 100644 --- a/tagstudio/src/qt/ts_qt.py +++ b/tagstudio/src/qt/ts_qt.py @@ -46,6 +46,7 @@ from src.core.ts_core import (TagStudioCore, TAG_COLORS, DATE_FIELDS, TEXT_FIELD from src.core.utils.web import strip_web_protocol from src.qt.flowlayout import FlowLayout, FlowWidget from src.qt.main_window import Ui_MainWindow +from src.qt.utils.clickableLabels import FileOpenerLabel import src.qt.resources_rc # SIGQUIT is not defined on Windows @@ -2015,24 +2016,7 @@ class PreviewPanel(QWidget): image_layout.addWidget(self.preview_img) image_layout.setAlignment(self.preview_img, Qt.AlignmentFlag.AlignCenter) - class ClickableLabel(QLabel): - def __init__(self, text, parent=None): - super().__init__(text, parent) - - def setFilePath(self, filepath): - self.filepath = filepath - - def mousePressEvent(self, event): - super().mousePressEvent(event) - #open file - if hasattr(self, 'filepath'): - if os.path.exists(self.filepath): - os.startfile(self.filepath) - logging.info(f'Opening file: {self.filepath}') - else: - logging.error(f'File not found: {self.filepath}') - - self.file_label = ClickableLabel('Filename') + self.file_label = FileOpenerLabel('Filename') self.file_label.setWordWrap(True) self.file_label.setTextInteractionFlags( Qt.TextInteractionFlag.TextSelectableByMouse) diff --git a/tagstudio/src/qt/utils/clickableLabels.py b/tagstudio/src/qt/utils/clickableLabels.py new file mode 100644 index 00000000..12d4cba9 --- /dev/null +++ b/tagstudio/src/qt/utils/clickableLabels.py @@ -0,0 +1,20 @@ +import os +import logging +from PySide6.QtWidgets import QLabel + +class FileOpenerLabel(QLabel): + def __init__(self, text, parent=None): + super().__init__(text, parent) + + def setFilePath(self, filepath): + self.filepath = filepath + + def mousePressEvent(self, event): + super().mousePressEvent(event) + #open file + if hasattr(self, 'filepath'): + if os.path.exists(self.filepath): + os.startfile(self.filepath) + logging.info(f'Opening file: {self.filepath}') + else: + logging.error(f'File not found: {self.filepath}') \ No newline at end of file