@@ -2009,6 +2009,46 @@ def save(self):
2009
2009
if ext and ext .text ():
2010
2010
self .lib .ignored_extensions .append (ext .text ())
2011
2011
2012
+ class FileOpenerHelper ():
2013
+ def __init__ (self , filepath :str ):
2014
+ self .filepath = filepath
2015
+
2016
+ def set_filepath (self , filepath :str ):
2017
+ self .filepath = filepath
2018
+
2019
+ def open_file (self ):
2020
+ if os .path .exists (self .filepath ):
2021
+ os .startfile (self .filepath )
2022
+ logging .info (f'Opening file: { self .filepath } ' )
2023
+ else :
2024
+ logging .error (f'File not found: { self .filepath } ' )
2025
+
2026
+ def open_explorer (self ):
2027
+ if os .path .exists (self .filepath ):
2028
+ logging .info (f'Opening file: { self .filepath } ' )
2029
+ if os .name == 'nt' : # Windows
2030
+ command = f'explorer /select,"{ self .filepath } "'
2031
+ subprocess .run (command , shell = True )
2032
+ else : # macOS and Linux
2033
+ command = f'nautilus --select "{ self .filepath } "' # Adjust for your Linux file manager if different
2034
+ if subprocess .run (command , shell = True ).returncode == 0 :
2035
+ file_loc = os .path .dirname (self .filepath )
2036
+ file_loc = os .path .normpath (file_loc )
2037
+ os .startfile (file_loc )
2038
+ else :
2039
+ logging .error (f'File not found: { self .filepath } ' )
2040
+ class FileOpenerLabel (QLabel ):
2041
+ def __init__ (self , text , parent = None ):
2042
+ super ().__init__ (text , parent )
2043
+
2044
+ def setFilePath (self , filepath ):
2045
+ self .filepath = filepath
2046
+
2047
+ def mousePressEvent (self , event ):
2048
+ super ().mousePressEvent (event )
2049
+ opener = FileOpenerHelper (self .filepath )
2050
+ opener .open_explorer ()
2051
+
2012
2052
class PreviewPanel (QWidget ):
2013
2053
"""The Preview Panel Widget."""
2014
2054
tags_updated = Signal ()
@@ -2044,6 +2084,14 @@ def __init__(self, library: Library, driver:'QtDriver'):
2044
2084
self .preview_img = QPushButton ()
2045
2085
self .preview_img .setMinimumSize (* self .img_button_size )
2046
2086
self .preview_img .setFlat (True )
2087
+
2088
+ self .preview_img .setContextMenuPolicy (Qt .ContextMenuPolicy .ActionsContextMenu )
2089
+ self .opener = FileOpenerHelper ('' )
2090
+ self .open_file_action = QAction ('Open file' , self )
2091
+ self .open_explorer_action = QAction ('Open file in explorer' , self )
2092
+
2093
+ self .preview_img .addAction (self .open_file_action )
2094
+ self .preview_img .addAction (self .open_explorer_action )
2047
2095
self .tr = ThumbRenderer ()
2048
2096
self .tr .updated .connect (lambda ts , i , s : (self .preview_img .setIcon (i )))
2049
2097
self .tr .updated_ratio .connect (lambda ratio : (self .set_image_ratio (ratio ),
@@ -2055,7 +2103,7 @@ def __init__(self, library: Library, driver:'QtDriver'):
2055
2103
image_layout .addWidget (self .preview_img )
2056
2104
image_layout .setAlignment (self .preview_img , Qt .AlignmentFlag .AlignCenter )
2057
2105
2058
- self .file_label = QLabel ('Filename' )
2106
+ self .file_label = FileOpenerLabel ('Filename' )
2059
2107
self .file_label .setWordWrap (True )
2060
2108
self .file_label .setTextInteractionFlags (
2061
2109
Qt .TextInteractionFlag .TextSelectableByMouse )
@@ -2262,7 +2310,9 @@ def update_widgets(self):
2262
2310
if len (self .driver .selected ) == 0 :
2263
2311
if len (self .selected ) != 0 or not self .initialized :
2264
2312
self .file_label .setText (f"No Items Selected" )
2313
+ self .file_label .setFilePath ('' )
2265
2314
self .dimensions_label .setText ("" )
2315
+ self .preview_img .setContextMenuPolicy (Qt .ContextMenuPolicy .NoContextMenu )
2266
2316
ratio : float = self .devicePixelRatio ()
2267
2317
self .tr .render_big (time .time (), '' , (512 , 512 ), ratio , True )
2268
2318
try :
@@ -2285,11 +2335,17 @@ def update_widgets(self):
2285
2335
if (len (self .selected ) == 0
2286
2336
or self .selected != self .driver .selected ):
2287
2337
filepath = os .path .normpath (f'{ self .lib .library_dir } /{ item .path } /{ item .filename } ' )
2338
+ self .file_label .setFilePath (filepath )
2288
2339
window_title = filepath
2289
2340
ratio : float = self .devicePixelRatio ()
2290
2341
self .tr .render_big (time .time (), filepath , (512 , 512 ), ratio )
2291
2342
self .file_label .setText ("\u200b " .join (filepath ))
2292
2343
2344
+ self .preview_img .setContextMenuPolicy (Qt .ContextMenuPolicy .ActionsContextMenu )
2345
+ self .opener = FileOpenerHelper (filepath )
2346
+ self .open_file_action .triggered .connect (self .opener .open_file )
2347
+ self .open_explorer_action .triggered .connect (self .opener .open_explorer )
2348
+
2293
2349
# TODO: Do this somewhere else, this is just here temporarily.
2294
2350
extension = os .path .splitext (filepath )[1 ][1 :].lower ()
2295
2351
try :
@@ -2362,7 +2418,9 @@ def update_widgets(self):
2362
2418
elif len (self .driver .selected ) > 1 :
2363
2419
if self .selected != self .driver .selected :
2364
2420
self .file_label .setText (f"{ len (self .driver .selected )} Items Selected" )
2421
+ self .file_label .setFilePath ('' )
2365
2422
self .dimensions_label .setText ("" )
2423
+ self .preview_img .setContextMenuPolicy (Qt .ContextMenuPolicy .NoContextMenu )
2366
2424
ratio : float = self .devicePixelRatio ()
2367
2425
self .tr .render_big (time .time (), '' , (512 , 512 ), ratio , True )
2368
2426
try :
@@ -2757,7 +2815,6 @@ class ItemThumb(FlowWidget):
2757
2815
"""
2758
2816
The thumbnail widget for a library item (Entry, Collation, Tag Group, etc.).
2759
2817
"""
2760
-
2761
2818
update_cutoff : float = time .time ()
2762
2819
2763
2820
collation_icon_128 : Image .Image = Image .open (os .path .normpath (
@@ -2886,6 +2943,15 @@ def __init__(self, mode: Optional[ItemType], library: Library, panel: PreviewPan
2886
2943
# self.bg_button.setMinimumSize(*thumb_size)
2887
2944
# self.bg_button.setMaximumSize(*thumb_size)
2888
2945
2946
+ self .thumb_button .setContextMenuPolicy (Qt .ContextMenuPolicy .ActionsContextMenu )
2947
+ self .opener = FileOpenerHelper ('' )
2948
+ open_file_action = QAction ('Open file' , self )
2949
+ open_file_action .triggered .connect (self .opener .open_file )
2950
+ open_explorer_action = QAction ('Open file in explorer' , self )
2951
+ open_explorer_action .triggered .connect (self .opener .open_explorer )
2952
+ self .thumb_button .addAction (open_file_action )
2953
+ self .thumb_button .addAction (open_explorer_action )
2954
+
2889
2955
# Static Badges ========================================================
2890
2956
2891
2957
# Item Type Badge ------------------------------------------------------
@@ -3080,7 +3146,15 @@ def update_badges(self):
3080
3146
3081
3147
3082
3148
def set_item_id (self , id : int ):
3149
+ '''
3150
+ also sets the filepath for the file opener
3151
+ '''
3083
3152
self .item_id = id
3153
+ if (id == - 1 ):
3154
+ return
3155
+ entry = self .lib .get_entry (self .item_id )
3156
+ filepath = os .path .normpath (f'{ self .lib .library_dir } /{ entry .path } /{ entry .filename } ' )
3157
+ self .opener .set_filepath (filepath )
3084
3158
3085
3159
def assign_favorite (self , value : bool ):
3086
3160
# Switching mode to None to bypass mode-specific operations when the
0 commit comments