Skip to content

Commit

Permalink
list: Split update bottles list and show page
Browse files Browse the repository at this point in the history
This also gets rid of all the weird callbacks with `GLib.idle_add()`
and other methods.
  • Loading branch information
TheEvilSkeleton committed Dec 24, 2024
1 parent 485bf21 commit 2a37108
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 25 deletions.
27 changes: 5 additions & 22 deletions bottles/frontend/views/list.py
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,7 @@ def __init__(self, window, arg_bottle=None, **kwargs):

# backend signals
SignalManager.connect(
Signals.ManagerLocalBottlesLoaded, self.backend_local_bottle_loaded
Signals.ManagerLocalBottlesLoaded, self.update_bottles_list
)

self.bottle_status.set_icon_name(APP_ID)
Expand All @@ -176,7 +176,7 @@ def __filter_bottles(row, terms=None):
text = row.get_title().lower()
return terms.lower() in text

def idle_update_bottles_list(self, show=False):
def update_bottles_list(self, *args) -> None:
self.__bottles = {}
while self.list_bottles.get_first_child():
self.list_bottles.remove(self.list_bottles.get_first_child())
Expand Down Expand Up @@ -206,26 +206,9 @@ def idle_update_bottles_list(self, show=False):
self.group_steam.set_visible(True)
self.group_bottles.set_title(_("Your Bottles"))

if (
self.arg_bottle is not None and self.arg_bottle in local_bottles.keys()
) or (show is not None and show in local_bottles.keys()):
_config = None
if self.arg_bottle:
_config = local_bottles[self.arg_bottle]
if show:
_config = local_bottles[show]
if not _config:
raise NotImplementedError("neither 'arg_bottle' nor 'show' are set")

self.window.page_details.view_preferences.update_combo_components()
self.window.show_details_view(config=_config)
self.arg_bottle = None

def backend_local_bottle_loaded(self, _: Result):
self.update_bottles_list()

def update_bottles_list(self, show=False):
GLib.idle_add(self.idle_update_bottles_list, show)
def show_page(self, page: str) -> None:
if config := self.window.manager.local_bottles.get(page):
self.window.show_details_view(config=config)

def disable_bottle(self, config):
self.__bottles[config.Path].disable()
5 changes: 2 additions & 3 deletions bottles/frontend/views/new.py
Original file line number Diff line number Diff line change
Expand Up @@ -243,9 +243,8 @@ def send_notification(notification: Gio.Notification) -> None:
# Ask the manager to check for new bottles,
# then update the user bottles' list.
self.manager.check_bottles()
self.window.page_list.update_bottles_list(
show=result.data.get("config").get("Path")
)
self.window.page_list.update_bottles_list()
self.window.page_list.show_page(self.new_bottle_config.get("Path"))

def __radio_get_active(self) -> str:
# TODO: Remove this ugly zig zag and find a better way to set the environment
Expand Down

0 comments on commit 2a37108

Please sign in to comment.