From 5bd2aaaf9ec9b570db2a3021bf5024487c07d025 Mon Sep 17 00:00:00 2001 From: Matheus Cirillo Date: Fri, 26 Apr 2024 22:04:40 -0300 Subject: [PATCH] context menu for thumbs --- tagstudio/src/qt/ts_qt.py | 35 +++++++++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) diff --git a/tagstudio/src/qt/ts_qt.py b/tagstudio/src/qt/ts_qt.py index 0a265e68..950d445b 100644 --- a/tagstudio/src/qt/ts_qt.py +++ b/tagstudio/src/qt/ts_qt.py @@ -2742,6 +2742,8 @@ class ItemThumb(FlowWidget): """ The thumbnail widget for a library item (Entry, Collation, Tag Group, etc.). """ + on_click = Signal() + on_edit = Signal() update_cutoff: float = time.time() @@ -2871,6 +2873,14 @@ class ItemThumb(FlowWidget): # self.bg_button.setMinimumSize(*thumb_size) # self.bg_button.setMaximumSize(*thumb_size) + self.thumb_button.setContextMenuPolicy(Qt.ContextMenuPolicy.ActionsContextMenu) + open_file_action = QAction('Open file', self) + open_file_action.triggered.connect(self.open_file) + open_explorer_action = QAction('Open file in explorer', self) + open_explorer_action.triggered.connect(self.open_explorer) + self.thumb_button.addAction(open_file_action) + self.thumb_button.addAction(open_explorer_action) + # Static Badges ======================================================== # Item Type Badge ------------------------------------------------------ @@ -2970,6 +2980,31 @@ class ItemThumb(FlowWidget): self.set_mode(mode) + def open_file(self): + entry = self.lib.get_entry(self.item_id) + filepath = os.path.normpath(f'{self.lib.library_dir}/{entry.path}/{entry.filename}') + if os.path.exists(filepath): + os.startfile(filepath) + logging.info(f'Opening file: {filepath}') + else: + logging.error(f'File not found: {filepath}') + + def open_explorer(self): + entry = self.lib.get_entry(self.item_id) + filepath = os.path.normpath(f'{self.lib.library_dir}/{entry.path}/{entry.filename}') + if os.path.exists(filepath): + logging.info(f'Opening file: {filepath}') + if os.name == 'nt': # Windows + command = f'explorer /select,"{filepath}"' + subprocess.run(command, shell=True) + else: # macOS and Linux + command = f'nautilus --select "{filepath}"' # Adjust for your Linux file manager if different + if subprocess.run(command, shell=True).returncode == 0: + file_loc = os.path.dirname(filepath) + os.startfile(file_loc) + else: + logging.error(f'File not found: {filepath}') + def set_mode(self, mode: Optional[ItemType]) -> None: if mode is None: self.unsetCursor()