From 1f8f76958d5baba4d695f1121b4b2ca214a61704 Mon Sep 17 00:00:00 2001 From: Diego Garcia Gangl Date: Wed, 12 Jun 2024 14:41:06 -0300 Subject: [PATCH 1/3] Reconnect start tomorrow btn sensitivity fixes #1004 --- GTG/gtk/browser/main_window.py | 27 +++++++++++++++++---------- 1 file changed, 17 insertions(+), 10 deletions(-) diff --git a/GTG/gtk/browser/main_window.py b/GTG/gtk/browser/main_window.py index 57b5cf79b..8de8ebcd9 100644 --- a/GTG/gtk/browser/main_window.py +++ b/GTG/gtk/browser/main_window.py @@ -167,7 +167,7 @@ def __init__(self, app): # This needs to be called again after setting everything up, # so the buttons start disabled - self.on_cursor_changed() + self.on_selection_changed() # INIT HELPER FUNCTIONS ####################################################### def _init_context_menus(self): @@ -400,6 +400,10 @@ def _init_signal_connections(self): self.connect('notify::default-width', self.on_window_resize) self.connect('notify::default-height', self.on_window_resize) + for p in PANE_STACK_NAMES_MAP.keys(): + pane = self.stack_switcher.get_stack().get_child_by_name(p).get_first_child() + pane.task_selection.connect('selection-changed', self.on_selection_changed) + # # Active tasks TreeView # tsk_treeview_btn_press = self.on_task_treeview_click_begin # active_pane_gesture_single = Gtk.GestureSingle( @@ -693,16 +697,19 @@ def on_about_close(self, widget): self.about.hide() return True - def on_cursor_changed(self, widget=None): - """Callback when the treeview's cursor changes.""" - ... - # if self.has_any_selection(): - # self.defer_btn.set_sensitive(True) - # self.defer_menu_btn.set_sensitive(True) - # else: - # self.defer_btn.set_sensitive(False) - # self.defer_menu_btn.set_sensitive(False) + def on_selection_changed(self, position=None, n_items=None, user_data=None) -> None: + """Callback when selection changes.""" + + pane = self.get_pane() + + if pane.get_selected_number(): + self.defer_btn.set_sensitive(True) + self.defer_menu_btn.set_sensitive(True) + else: + self.defer_btn.set_sensitive(False) + self.defer_menu_btn.set_sensitive(False) + def on_tagcontext_deactivate(self, menushell): self.reset_cursor() From 243288c24b291e51520035d500e30a5432992648 Mon Sep 17 00:00:00 2001 From: Diego Garcia Gangl Date: Wed, 12 Jun 2024 15:28:20 -0300 Subject: [PATCH 2/3] Add signal for sidebar selection changes Lets us toggle the start tomorrow button when changing tags or saved searches --- GTG/gtk/browser/main_window.py | 13 +++++++++++++ GTG/gtk/browser/sidebar.py | 11 ++++++++++- 2 files changed, 23 insertions(+), 1 deletion(-) diff --git a/GTG/gtk/browser/main_window.py b/GTG/gtk/browser/main_window.py index 8de8ebcd9..cc892163d 100644 --- a/GTG/gtk/browser/main_window.py +++ b/GTG/gtk/browser/main_window.py @@ -404,6 +404,8 @@ def _init_signal_connections(self): pane = self.stack_switcher.get_stack().get_child_by_name(p).get_first_child() pane.task_selection.connect('selection-changed', self.on_selection_changed) + self.sidebar.connect('selection_changed', self.on_sidebar_select_changed) + # # Active tasks TreeView # tsk_treeview_btn_press = self.on_task_treeview_click_begin # active_pane_gesture_single = Gtk.GestureSingle( @@ -698,6 +700,17 @@ def on_about_close(self, widget): return True + def on_sidebar_select_changed(self, widget=None) -> None: + """Callback when the sidebar selection changes. """ + + for p in PANE_STACK_NAMES_MAP.keys(): + pane = self.stack_switcher.get_stack().get_child_by_name(p).get_first_child() + pane.task_selection.unselect_all() + + # This isn't called automatically for some reason + self.on_selection_changed() + + def on_selection_changed(self, position=None, n_items=None, user_data=None) -> None: """Callback when selection changes.""" diff --git a/GTG/gtk/browser/sidebar.py b/GTG/gtk/browser/sidebar.py index 5fb0af44e..aa75626fa 100644 --- a/GTG/gtk/browser/sidebar.py +++ b/GTG/gtk/browser/sidebar.py @@ -217,6 +217,11 @@ def change_pane(self, pane: str) -> None: self.tags_filter.changed(Gtk.FilterChange.DIFFERENT) + @GObject.Signal + def selection_changed(self) -> None: + """Selection of tags or searches has changed.""" + + def on_tag_RMB_click(self, gesture, sequence) -> None: """Callback when right-clicking on a tag.""" @@ -433,6 +438,8 @@ def on_general_box_selected(self, listbox, user_data=None): elif index == 1: self.app.browser.get_pane().set_filter_notags() + self.emit('selection_changed') + def on_search_selected(self, model, position, user_data=None): """Callback when selecting a saved search""" @@ -443,6 +450,7 @@ def on_search_selected(self, model, position, user_data=None): item = model.get_item(position) self.app.browser.get_pane().emit('expand-all') self.app.browser.get_pane().set_search_query(item.query) + self.emit('selection_changed') def select_tag(self, name: str, unselect_rest: bool = True) -> None: @@ -454,7 +462,6 @@ def select_tag(self, name: str, unselect_rest: bool = True) -> None: if item.name == name: self.tag_selection.select_item(i, unselect_rest) - def selected_tags(self, names_only: bool = False) -> list: """Get a list of selected tags""" @@ -487,6 +494,8 @@ def on_tag_selected(self, model, position, n_items, user_data=None): else: self.browser.config.set("selected_tag", '') + self.emit('selection_changed') + def on_tag_reveal(self, event) -> None: """Callback for clicking on the tags title button (revealer).""" From d6e52b23f36b269a000b908646e7d864d4565460 Mon Sep 17 00:00:00 2001 From: Diego Garcia Gangl Date: Wed, 17 Jul 2024 18:53:41 -0300 Subject: [PATCH 3/3] Add function to get pane by name --- GTG/gtk/browser/main_window.py | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/GTG/gtk/browser/main_window.py b/GTG/gtk/browser/main_window.py index cc892163d..acd2b2afb 100644 --- a/GTG/gtk/browser/main_window.py +++ b/GTG/gtk/browser/main_window.py @@ -401,7 +401,7 @@ def _init_signal_connections(self): self.connect('notify::default-height', self.on_window_resize) for p in PANE_STACK_NAMES_MAP.keys(): - pane = self.stack_switcher.get_stack().get_child_by_name(p).get_first_child() + pane = self.get_pane_by_name(p) pane.task_selection.connect('selection-changed', self.on_selection_changed) self.sidebar.connect('selection_changed', self.on_sidebar_select_changed) @@ -1459,9 +1459,16 @@ def get_selected_pane(self, old_names: bool = True) -> str: return current + def get_pane_by_name(self, name: str) -> TaskPane: + """Get a task pane by name.""" + + return self.stack_switcher.get_stack().get_child_by_name(name).get_first_child() + + def get_pane(self): """Get the selected pane.""" + return self.stack_switcher.get_stack().get_visible_child().get_first_child()