code cleanup

This commit is contained in:
Matheus Cirillo
2024-04-26 20:13:58 -03:00
parent 79e0263e97
commit 18dcedd6a0
2 changed files with 22 additions and 18 deletions

View File

@@ -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)

View File

@@ -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}')