diff --git a/tagstudio/src/qt/ts_qt.py b/tagstudio/src/qt/ts_qt.py index a63e970e5..93b025551 100644 --- a/tagstudio/src/qt/ts_qt.py +++ b/tagstudio/src/qt/ts_qt.py @@ -139,6 +139,8 @@ def __init__(self, backend, args): self.filter = FilterState() self.pages_count = 0 + self.menus = [] + self.scrollbar_pos = 0 self.thumb_size = 128 self.spacing = None @@ -193,6 +195,7 @@ def open_library_from_dialog(self): ) if dir not in (None, ""): self.open_library(Path(dir)) + self.update_menu_actions() def signal_handler(self, sig, frame): if sig in (SIGINT, SIGTERM, SIGQUIT): @@ -275,6 +278,7 @@ def start(self) -> None: # file_menu.addAction(QAction('&Open Library', menu_bar)) open_library_action = QAction("&Open/Create Library", menu_bar) + open_library_action.setProperty("disable", value=False) open_library_action.triggered.connect(lambda: self.open_library_from_dialog()) open_library_action.setShortcut( QtCore.QKeyCombination( @@ -400,6 +404,7 @@ def create_dupe_files_modal(): # Macros Menu ========================================================== self.autofill_action = QAction("Autofill", menu_bar) + self.autofill_action.setProperty("enable", value=False) self.autofill_action.triggered.connect( lambda: ( self.run_macros(MacroID.AUTOFILL, self.selected), @@ -438,6 +443,13 @@ def create_folders_tags_modal(): help_menu.addAction(self.repo_action) self.set_macro_menu_viability() + self.menus.append(file_menu) + self.menus.append(edit_menu) + self.menus.append(tools_menu) + self.menus.append(macros_menu) + + self.update_menu_actions() + menu_bar.addMenu(file_menu) menu_bar.addMenu(edit_menu) menu_bar.addMenu(tools_menu) @@ -474,7 +486,7 @@ def create_folders_tags_modal(): QColor("#9782ff"), ) self.open_library(path_result.library_path) - + self.update_menu_actions() app.exec() self.shutdown() @@ -492,6 +504,47 @@ def show_error_message(self, message: str): # Show the message box msg_box.exec() + def update_menu_actions(self): + # To override the enabling and disabling of buttons + # there are 2 data options that can be added to a button + # but are not necessary + + # name_of_action.setData({"enable":False}) + + # this one should be added to buttons that do not need to be enabled when a library + # is opened for example the autofil button only enables + # when clicked on a item not on library open + + # name_of_action.setData({"disable":False}) + # this one should be added to a button that needs to be enabled + # even when not in a library like the "open library button" + + # if the button should be controlled here then just do not add any data objects + + if self.lib.library_dir: # i think this should not return true when in a library? + # we are in a library! time to enable them. + for menu in self.menus: + for action in menu.actions(): + # scary but all this dose is check if the aforementioned "enable" option is + # set to false and if it is then do not enable the button + action.setDisabled( + False + if action.property("enable") is None + else not action.property("enable") + if action.property("enable") is False + else False + ) + else: + # if we are not in a library then we need to disable all the unneeded menu buttons + for menu in self.menus: + for action in menu.actions(): + # also scary but all this dose is check if the aforementioned "disable" option + # is set to false and if it is then do not disable this button + # when closing a library + action.setDisabled( + True if action.property("disable") is None else action.property("disable") + ) + def init_library_window(self): # self._init_landing_page() # Taken care of inside the widget now @@ -586,7 +639,6 @@ def close_library(self, is_shutdown: bool = False): self.lib.close() - self.thumb_job_queue.queue.clear() if is_shutdown: # no need to do other things on shutdown return @@ -606,6 +658,7 @@ def close_library(self, is_shutdown: bool = False): self.main_window.statusbar.showMessage( f"Library Closed ({format_timespan(end_time - start_time)})" ) + self.update_menu_actions() def backup_library(self): logger.info("Backing Up Library...") @@ -1139,4 +1192,5 @@ def open_library(self, path: Path) -> LibraryStatus: self.filter_items() self.main_window.toggle_landing_page(enabled=False) + self.update_menu_actions() return open_status