From 641f83bf3357c9cc3afc154f97af79cb93571c1a Mon Sep 17 00:00:00 2001 From: Johannes Laurin Hoermann Date: Mon, 4 Nov 2024 15:11:33 +0100 Subject: [PATCH] MAINT: actionized dependency graph build --- dtool_lookup_gui/views/main_window.py | 42 +++++++++++++++++++++++++-- 1 file changed, 40 insertions(+), 2 deletions(-) diff --git a/dtool_lookup_gui/views/main_window.py b/dtool_lookup_gui/views/main_window.py index 7e0d0a4..7a798e5 100644 --- a/dtool_lookup_gui/views/main_window.py +++ b/dtool_lookup_gui/views/main_window.py @@ -246,12 +246,24 @@ def __init__(self, *args, **kwargs): show_dataset_action.connect("activate", self.do_show_dataset_details_by_row_index) self.add_action(show_dataset_action) + # build dependency graph by row index in dataset list box action + row_index_variant = GLib.Variant.new_uint32(0) + build_dependency_graph_action = Gio.SimpleAction.new("build-dependency-graph", row_index_variant.get_type()) + build_dependency_graph_action.connect("activate", self.do_build_dependency_graph_by_row_index) + self.add_action(build_dependency_graph_action) + # show details of dataset by uri in dataset list box action uri_variant = GLib.Variant.new_string("dummy") show_dataset_by_uri_action = Gio.SimpleAction.new("show-dataset-by-uri", uri_variant.get_type()) show_dataset_by_uri_action.connect("activate", self.do_show_dataset_details_by_uri) self.add_action(show_dataset_by_uri_action) + # build dependency graph by uri in dataset list box action + uri_variant = GLib.Variant.new_string("dummy") + build_dependency_graph_by_uri_action = Gio.SimpleAction.new("build-dependency-graph-by-uri", uri_variant.get_type()) + build_dependency_graph_by_uri_action.connect("activate", self.do_build_dependency_graph_by_uri) + self.add_action(build_dependency_graph_by_uri_action) + # search, select and show first search result subsequently row_index_variant = GLib.Variant.new_string("dummy") search_select_show_action = Gio.SimpleAction.new("search-select-show", row_index_variant.get_type()) @@ -500,6 +512,9 @@ def _show_dataset_details(self, dataset): asyncio.create_task(self._update_dataset_view(dataset)) self.dataset_stack.set_visible_child(self.dataset_box) + def _build_dependency_graph(self, dataset): + asyncio.create_task(self._compute_dependencies(dataset)) + def _show_dataset_details_by_row_index(self, index): row = self.dataset_list_box.get_row_at_index(index) if row is not None: @@ -508,11 +523,25 @@ def _show_dataset_details_by_row_index(self, index): else: _logger.info(f"No dataset row with index {index} available for selection.") + def _build_dependency_graph_by_row_index(self, index): + """Build dependency graph by row index.""" + row = self.dataset_list_box.get_row_at_index(index) + if row is not None: + _logger.debug(f"{row.dataset.name} shown.") + self._build_dependency_graph(row.dataset) + else: + _logger.info(f"No dataset row with index {index} available for selection.") + def _show_dataset_details_by_uri(self, uri): """Select dataset row in dataset list box by uri.""" index = self.dataset_list_box.get_row_index_from_uri(uri) self._show_dataset_details_by_row_index(index) + def _build_dependency_graph_by_uri(self, uri): + """Build dependency graph by uri.""" + index = self.dataset_list_box.get_row_index_from_uri(uri) + self._build_dependency_graph_by_row_index(index) + def _select_and_show_by_row_index(self, index=0): self._select_dataset_row_by_row_index(index) self._show_dataset_details_by_row_index(index) @@ -582,11 +611,21 @@ def do_show_dataset_details_by_row_index(self, action, value): row_index = value.get_uint32() self._show_dataset_details_by_row_index(row_index) + def do_build_dependency_graph_by_row_index(self, action, value): + """Build the dependency graph by row index.""" + row_index = value.get_uint32() + self._build_dependency_graph_by_row_index(row_index) + def do_show_dataset_details_by_uri(self, action, value): """Show dataset details by uri.""" uri = value.get_string() self._show_dataset_details_by_uri(uri) + def do_build_dependency_graph_by_uri(self, action, value): + """Build the dependency graph by uri.""" + uri = value.get_string() + self._build_dependency_graph_by_uri(uri) + # search actions def do_search(self, action, value): """Evoke search tas for specific search text.""" @@ -646,7 +685,6 @@ def do_refresh_view(self, action, value): """Refresh view by reloading base uri list, """ self.refresh() - # signal handlers @Gtk.Template.Callback() def on_settings_clicked(self, widget): @@ -1168,7 +1206,7 @@ async def _get_manifest(): if dataset.type == 'lookup': self.dependency_stack.show() _logger.debug("Selected dataset is lookup result.") - asyncio.create_task(self._compute_dependencies(dataset)) + self.get_action_group("win").activate_action('build-dependency-graph-by-uri', GLib.Variant.new_string(dataset.uri)) else: _logger.debug("Selected dataset is accessed directly.") self.dependency_stack.hide()