From 4c5b368fbbd55213330f176b31ca116016e18f4f Mon Sep 17 00:00:00 2001 From: Ben Grande Date: Thu, 12 Feb 2026 16:36:03 +0100 Subject: [PATCH] Hide internal qubes from list modeler by default The early load of icon for any qube is to prevent a qube that is not supposed to be listed, to be able to load an icon if it is the default value. Example: set a property to a qube that has the internal feature set, it should be listed in the GUI and should load the icon. --- qubes_config/global_config/basics_handler.py | 2 ++ qubes_config/tests/test_gtk_widgets.py | 22 +++++++++++++++++++- qubes_config/widgets/gtk_widgets.py | 22 ++++++++++++++++++-- 3 files changed, 43 insertions(+), 3 deletions(-) diff --git a/qubes_config/global_config/basics_handler.py b/qubes_config/global_config/basics_handler.py index 2e6536ce..a8f906ea 100644 --- a/qubes_config/global_config/basics_handler.py +++ b/qubes_config/global_config/basics_handler.py @@ -135,6 +135,7 @@ def __init__( vm_filter: Optional[Callable] = None, readable_name: Optional[str] = None, additional_options: Dict[Any | str | None, str] | None = None, + show_internal: bool = False, ): self.qapp = qapp self.trait_holder = trait_holder @@ -149,6 +150,7 @@ def __init__( current_value=self.get_current_value(), style_changes=True, additional_options=additional_options, + show_internal=show_internal, ) def get_readable_description(self) -> str: diff --git a/qubes_config/tests/test_gtk_widgets.py b/qubes_config/tests/test_gtk_widgets.py index beaa8bce..e7f5b356 100644 --- a/qubes_config/tests/test_gtk_widgets.py +++ b/qubes_config/tests/test_gtk_widgets.py @@ -351,13 +351,33 @@ def test_vmmodeler_default_current(test_qapp): def test_vmmodeler_filter(test_qapp): combobox: Gtk.ComboBox = Gtk.ComboBox.new_with_entry() - vms = ["test-vm", "test-blue", "test-red"] + internal_vm = ["disp-mgmt"] + normal_vms = ["test-vm", "test-blue", "test-red"] + vms = internal_vm + normal_vms _ = gtk_widgets.VMListModeler( combobox=combobox, qapp=test_qapp, filter_function=lambda vm: str(vm) in vms, ) + selected_vms = [] + model = combobox.get_model() + for item in model: + selected_vms.append(item[1]) + + assert sorted(selected_vms) == sorted(normal_vms) + + +def test_vmmodeler_filter_include_internal(test_qapp): + combobox: Gtk.ComboBox = Gtk.ComboBox.new_with_entry() + vms = ["disp-mgmt", "test-vm", "test-blue", "test-red"] + _ = gtk_widgets.VMListModeler( + combobox=combobox, + qapp=test_qapp, + filter_function=lambda vm: str(vm) in vms, + show_internal=True, + ) + selected_vms = [] model = combobox.get_model() for item in model: diff --git a/qubes_config/widgets/gtk_widgets.py b/qubes_config/widgets/gtk_widgets.py index 415b7144..68689487 100644 --- a/qubes_config/widgets/gtk_widgets.py +++ b/qubes_config/widgets/gtk_widgets.py @@ -35,6 +35,8 @@ import gettext +from ..widgets.utils import get_boolean_feature + t = gettext.translation("desktop-linux-manager", fallback=True) _ = t.gettext @@ -234,6 +236,7 @@ def __init__( current_value: qubesadmin.vm.QubesVM | str | None = None, style_changes: bool = False, additional_options: dict[qubesadmin.vm.QubesVM | str | None, str] | None = None, + show_internal: bool = False, ): """ :param combobox: target ComboBox object @@ -254,12 +257,14 @@ def __init__( applied when combobox value changes :param additional_options: Dictionary of token: readable name of additonal options to be added to the combobox + :param show_internal: if True, show qubes with internal feature enabled """ self.qapp = qapp self.combo = combobox self.entry_box = self.combo.get_child() self.change_function = event_callback self.style_changes = style_changes + self.show_internal = show_internal self._entries: dict[str, dict[str, Any]] = {} @@ -337,9 +342,23 @@ def _create_entries( "vm": None, } + found_current = False + if current_value and current_value in self.qapp.domains: + found_current = True + domain = self.qapp.domains[current_value] + icon = self._get_icon(domain.icon) + vm_name = domain.name + self._entries[vm_name] = { + "api_name": vm_name, + "icon": icon, + "vm": domain, + } + for domain in self.qapp.domains: if filter_function and not filter_function(domain): continue + if not self.show_internal and get_boolean_feature(domain, "internal"): + continue vm_name = domain.name icon = self._get_icon(domain.icon) display_name = vm_name @@ -353,8 +372,7 @@ def _create_entries( "vm": domain, } - if current_value: - found_current = False + if current_value and not found_current: for value in self._entries.values(): if value["api_name"] == current_value: found_current = True