Skip to content

Commit

Permalink
details: Port to AdwNavigationPage
Browse files Browse the repository at this point in the history
  • Loading branch information
TheEvilSkeleton committed Jan 9, 2025
1 parent a084df9 commit 4cf0fa7
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 150 deletions.
71 changes: 5 additions & 66 deletions bottles/frontend/ui/details.blp
Original file line number Diff line number Diff line change
Expand Up @@ -5,72 +5,11 @@ template $DetailsView: Adw.NavigationPage {
title: _("Details");
tag: "details";

child: Adw.Bin {
Adw.Leaflet leaflet {
can-navigate-back: true;
can-unfold: false;
hexpand: true;

Box {
orientation: vertical;

Adw.HeaderBar sidebar_headerbar {
show-end-title-buttons: false;

title-widget: Adw.WindowTitle sidebar_title {
title: _("Details");
};

[end]
Box default_actions {}
}

Box default_view {}
}

Adw.LeafletPage {
navigatable: false;

child: Separator panel_separator {
orientation: vertical;

styles [
"sidebar",
]
};
}

Box content {
orientation: vertical;

Adw.HeaderBar content_headerbar {
show-start-title-buttons: false;

title-widget: Adw.WindowTitle content_title {};

[end]
Box box_actions {}

[end]
MenuButton btn_operations {
visible: false;
tooltip-text: _("Operations");
popover: pop_tasks;

Spinner spinner_tasks {}

styles [
"flat",
]
}
}

Stack stack_bottle {
transition-type: crossfade;
hexpand: true;
vexpand: true;
}
}
child: Adw.ToolbarView {
[top]
Adw.HeaderBar {
[end]
Box default_actions {}
}
};
}
Expand Down
2 changes: 0 additions & 2 deletions bottles/frontend/views/bottle_details_page.py
Original file line number Diff line number Diff line change
Expand Up @@ -107,8 +107,6 @@ def __init__(self, details, config, **kwargs):
# common variables and references
self.window = details.window
self.manager = details.window.manager
self.stack_bottle = details.stack_bottle
self.leaflet = details.leaflet
self.details = details
self.config = config
self.show_hidden = False
Expand Down
84 changes: 2 additions & 82 deletions bottles/frontend/views/details.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,18 +45,9 @@ class DetailsView(Adw.NavigationPage):
__pages = {}

# region Widgets
leaflet = Gtk.Template.Child()
default_view = Gtk.Template.Child()
stack_bottle = Gtk.Template.Child()
sidebar_headerbar = Gtk.Template.Child()
content_headerbar = Gtk.Template.Child()
default_actions = Gtk.Template.Child()
box_actions = Gtk.Template.Child()
content_title = Gtk.Template.Child()
btn_operations = Gtk.Template.Child()
list_tasks = Gtk.Template.Child()
pop_tasks = Gtk.Template.Child()
spinner_tasks = Gtk.Template.Child()

# endregion

Expand All @@ -83,46 +74,10 @@ def __init__(self, window, config: Optional[BottleConfig] = None, **kwargs):
self.default_actions.append(self.view_bottle.actions)

# region signals
self.stack_bottle.connect("notify::visible-child", self.__on_page_change)
self.btn_operations.connect("activate", self.__on_operations_toggled)
self.btn_operations.connect("notify::visible", self.__spin_tasks_toggle)
self.leaflet.connect("notify::folded", self.__on_leaflet_folded)
# endregion

RunAsync(self.build_pages)

def set_title(self, title, subtitle: str = ""):
"""
This function is used to set the title of the DetailsView
headerbar.
"""
self.content_title.set_title(title)
self.content_title.set_subtitle(subtitle)

def __on_leaflet_folded(self, widget, *_args):
folded = widget.get_folded()
self.sidebar_headerbar.set_show_end_title_buttons(folded)
self.content_headerbar.set_show_start_title_buttons(folded)

def __on_page_change(self, *_args):
"""
Update headerbar title according to the current page.
"""
page = self.stack_bottle.get_visible_child_name()

self.set_title(self.__pages[page]["title"], self.__pages[page]["description"])
if page == "dependencies":
self.set_actions(self.view_dependencies.actions)
self.view_dependencies.update(config=self.config)
elif page == "versioning":
self.set_actions(self.view_versioning.actions)
elif page == "installers":
self.set_actions(self.view_installers.actions)
elif page == "taskmanager":
self.set_actions(self.view_taskmanager.actions)
else:
self.set_actions(None)

def build_pages(self):
"""
This function build the pages list according to the
Expand Down Expand Up @@ -156,30 +111,11 @@ def build_pages(self):
del self.__pages["versioning"]

def ui_update():
if self.view_bottle.get_parent() is None:
self.default_view.append(self.view_bottle)

self.stack_bottle.add_named(self.view_preferences, "preferences")
self.stack_bottle.add_named(self.view_dependencies, "dependencies")
self.stack_bottle.add_named(self.view_versioning, "versioning")
self.stack_bottle.add_named(self.view_installers, "installers")
self.stack_bottle.add_named(self.view_taskmanager, "taskmanager")

if self.view_bottle.actions.get_parent() is None:
self.set_actions(self.view_bottle.actions)
toolbar_view = self.get_child()
toolbar_view.set_content(self.view_bottle)

GLib.idle_add(ui_update)

def set_actions(self, widget: Gtk.Widget = None):
"""
This function is used to set the actions buttons in the headerbar.
"""
while self.box_actions.get_first_child():
self.box_actions.remove(self.box_actions.get_first_child())

if widget:
self.box_actions.append(widget)

def set_config(self, config: BottleConfig):
"""
This function update widgets according to the bottle
Expand All @@ -196,22 +132,6 @@ def set_config(self, config: BottleConfig):
self.view_installers.update(config=config)
self.view_versioning.update(config=config)

def __on_operations_toggled(self, widget):
if not self.list_tasks.get_first_child():
widget.set_visible(False)

def __spin_tasks_toggle(self, widget, *_args):
if widget.get_visible():
self.spinner_tasks.start()
self.spinner_tasks.set_visible(True)
else:
self.spinner_tasks.stop()
self.spinner_tasks.set_visible(False)

def unload_view(self, *_args):
while self.stack_bottle.get_first_child():
self.stack_bottle.remove(self.stack_bottle.get_first_child())

@GtkUtils.run_in_main_loop
def lock_back(self):
...
Expand Down

0 comments on commit 4cf0fa7

Please sign in to comment.