88
99"""A Qt driver for TagStudio."""
1010
11- import contextlib
1211import ctypes
1312import math
1413import os
@@ -194,7 +193,7 @@ class QtDriver(DriverMixin, QObject):
194193 applied_theme : Theme
195194
196195 lib : Library
197- cache_manager : CacheManager
196+ cache_manager : CacheManager | None
198197
199198 browsing_history : History [BrowsingState ]
200199
@@ -539,7 +538,7 @@ def create_dupe_files_modal():
539538
540539 # TODO: Move this to a settings screen.
541540 self .main_window .menu_bar .clear_thumb_cache_action .triggered .connect (
542- lambda : self .cache_manager .clear_cache ()
541+ lambda : unwrap ( self .cache_manager ) .clear_cache ()
543542 )
544543
545544 # endregion
@@ -913,22 +912,21 @@ def delete_files_callback(self, origin_path: str | Path, origin_id: int | None =
913912 origin_id(id): The entry ID associated with the widget making the call.
914913 """
915914 entry : Entry | None = None
916- pending : list [tuple [int , Path ]] = []
915+ pending : list [tuple [int | None , Path ]] = []
917916 deleted_count : int = 0
918917
919918 selected = self .selected
920919 library_dir = unwrap (self .lib .library_dir )
921920
922921 if len (selected ) <= 1 and origin_path :
923922 origin_id_ = origin_id
924- if not origin_id_ :
925- with contextlib .suppress (IndexError ):
926- origin_id_ = selected [0 ]
923+ if origin_id_ is None :
924+ origin_id_ = selected [0 ] if len (selected ) > 0 else None
927925
928926 pending .append ((origin_id_ , Path (origin_path )))
929927 else :
930928 for item in selected :
931- entry = self .lib .get_entry (item )
929+ entry = unwrap ( self .lib .get_entry (item ) )
932930 filepath : Path = entry .path
933931 pending .append ((item , filepath ))
934932
@@ -950,7 +948,8 @@ def delete_files_callback(self, origin_path: str | Path, origin_id: int | None =
950948 self .main_window .status_bar .showMessage (msg )
951949 self .main_window .status_bar .repaint ()
952950
953- self .lib .remove_entries ([e_id ])
951+ if e_id is not None :
952+ self .lib .remove_entries ([e_id ])
954953 if delete_file (library_dir / f ):
955954 deleted_count += 1
956955
@@ -1226,10 +1225,10 @@ def paste_fields_action_callback(self):
12261225 for field in self .copy_buffer ["fields" ]:
12271226 exists = False
12281227 for e in existing_fields :
1229- if field . type_key == e . type_key and field . value == e . value :
1228+ if field == e :
12301229 exists = True
12311230 if not exists :
1232- self .lib .add_field_to_entries (id , field_id = field . type_key , value = field . value )
1231+ self .lib .add_field_to_entries (id , field = field )
12331232 self .lib .add_tags_to_entries (id , self .copy_buffer ["tags" ])
12341233 if len (self .selected ) > 1 :
12351234 if TAG_ARCHIVED in self .copy_buffer ["tags" ]:
0 commit comments