Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix sensitivity of start button #1114

Merged
merged 3 commits into from
Jul 18, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
47 changes: 37 additions & 10 deletions GTG/gtk/browser/main_window.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down Expand Up @@ -400,6 +400,12 @@ 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.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)

# # Active tasks TreeView
# tsk_treeview_btn_press = self.on_task_treeview_click_begin
# active_pane_gesture_single = Gtk.GestureSingle(
Expand Down Expand Up @@ -693,16 +699,30 @@ 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_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."""

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()
Expand Down Expand Up @@ -1439,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()


Expand Down
11 changes: 10 additions & 1 deletion GTG/gtk/browser/sidebar.py
Original file line number Diff line number Diff line change
Expand Up @@ -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."""

diegogangl marked this conversation as resolved.
Show resolved Hide resolved

def on_tag_RMB_click(self, gesture, sequence) -> None:
"""Callback when right-clicking on a tag."""

Expand Down Expand Up @@ -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"""
Expand All @@ -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:
Expand All @@ -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"""

Expand Down Expand Up @@ -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)."""
Expand Down