From 31c3a767f691f3908013262615752763da6133e3 Mon Sep 17 00:00:00 2001 From: Ali Mirjamali Date: Sun, 30 Jun 2024 14:05:04 +0330 Subject: [PATCH 1/2] Fixing CSS for Updater GUI VM Name Labels Fixes QubesOS/qubes-issues#9236 --- qubes_config/widgets/gtk_utils.py | 4 +++- qui/styles/qubes-colors-dark.css | 1 + qui/styles/qubes-colors-light.css | 3 ++- qui/styles/qubes-widgets-base.css | 4 ++++ qui/updater/updater.py | 4 +++- qui/updater/utils.py | 14 +++++++++++++- 6 files changed, 26 insertions(+), 4 deletions(-) diff --git a/qubes_config/widgets/gtk_utils.py b/qubes_config/widgets/gtk_utils.py index ae2a1fd5..0a333eed 100644 --- a/qubes_config/widgets/gtk_utils.py +++ b/qubes_config/widgets/gtk_utils.py @@ -192,7 +192,7 @@ def load_theme(widget: Gtk.Widget, light_theme_path: Optional[str] = None, dark_theme_path: Optional[str] = None, package_name: Optional[str] = None, light_file_name: Optional[str] = None, - dark_file_name: Optional[str] = None): + dark_file_name: Optional[str] = None) -> Gtk.CssProvider: """ Load a dark or light theme to current screen, based on widget's current (system) defaults. @@ -203,6 +203,7 @@ def load_theme(widget: Gtk.Widget, light_theme_path: Optional[str] = None, :param package_name: name of the package :param light_file_name: name of the css file with light theme :param dark_file_name: name of the css file with dark theme + Returns used CSS provider; it can be safely discarded if unused. """ if not light_theme_path and light_file_name: assert package_name @@ -222,6 +223,7 @@ def load_theme(widget: Gtk.Widget, light_theme_path: Optional[str] = None, provider.load_from_path(path) Gtk.StyleContext.add_provider_for_screen( screen, provider, Gtk.STYLE_PROVIDER_PRIORITY_APPLICATION) + return provider def is_theme_light(widget): diff --git a/qui/styles/qubes-colors-dark.css b/qui/styles/qubes-colors-dark.css index 21d2fdea..3150519c 100644 --- a/qui/styles/qubes-colors-dark.css +++ b/qui/styles/qubes-colors-dark.css @@ -41,3 +41,4 @@ @define-color blue-label #4363d8; @define-color purple-label #911eb4; @define-color black-label #ffffff; +@define-color custom-label #ffffff; diff --git a/qui/styles/qubes-colors-light.css b/qui/styles/qubes-colors-light.css index 45fc69eb..25a30372 100644 --- a/qui/styles/qubes-colors-light.css +++ b/qui/styles/qubes-colors-light.css @@ -40,4 +40,5 @@ @define-color gray-label #555555; @define-color blue-label #0E2276; @define-color purple-label #3F0C46; -@define-color black-label #000000; \ No newline at end of file +@define-color black-label #000000; +@define-color custom-label #000000; diff --git a/qui/styles/qubes-widgets-base.css b/qui/styles/qubes-widgets-base.css index 0b888210..dd0d8682 100644 --- a/qui/styles/qubes-widgets-base.css +++ b/qui/styles/qubes-widgets-base.css @@ -45,6 +45,10 @@ label { color: @black-label; } +.qube-box-custom-label { + color: @custom-label; +} + .group_title { font-weight: 400; font-size: 150%; diff --git a/qui/updater/updater.py b/qui/updater/updater.py index 383dfb36..7c094fff 100644 --- a/qui/updater/updater.py +++ b/qui/updater/updater.py @@ -15,6 +15,7 @@ from qui.updater.updater_settings import Settings, OverriddenSettings from qui.updater.summary_page import SummaryPage from qui.updater.intro_page import IntroPage +import qui.updater.utils gi.require_version('Gtk', '3.0') # isort:skip from gi.repository import Gtk, Gdk, Gio # isort:skip @@ -93,10 +94,11 @@ def perform_setup(self, *_args, **_kwargs): "button_cancel") self.cancel_button.connect("clicked", self.cancel_clicked) - load_theme(widget=self.main_window, + self.EffectiveCssProvider = load_theme(widget=self.main_window, package_name='qui', light_file_name='qubes-updater-light.css', dark_file_name='qubes-updater-dark.css') + qui.updater.utils.SetEffectiveCssProvider(self.EffectiveCssProvider) self.header_label: Gtk.Label = self.builder.get_object("header_label") diff --git a/qui/updater/utils.py b/qui/updater/utils.py index fdfc1fe0..2e5355a6 100644 --- a/qui/updater/utils.py +++ b/qui/updater/utils.py @@ -135,10 +135,22 @@ class QubeClass(Enum): AppVM = 3 DispVM = 4 +__effective_css_provider__: Gtk.CssProvider = None + +def SetEffectiveCssProvider(CssProvider: Gtk.CssProvider) -> None: + global __effective_css_provider__ + __effective_css_provider__ = CssProvider def label_color_theme(color: str) -> str: + global __effective_css_provider__ widget = Gtk.Label() - widget.get_style_context().add_class(f'qube-box-{color}') + if __effective_css_provider__ == None: + # Replicating the old behaviour. Both forward and backward compatible + widget.get_style_context().add_class(f'qube-box-{color}') + elif f'.qube-box-{color}' in __effective_css_provider__.to_string(): + widget.get_style_context().add_class(f'qube-box-{color}') + else: + widget.get_style_context().add_class('qube-box-custom-label') gtk_color = widget.get_style_context().get_color(Gtk.StateFlags.NORMAL) color_rgb = ast.literal_eval(gtk_color.to_string()[3:]) color_hex = '#{:02x}{:02x}{:02x}'.format(*color_rgb) From d283842f6beffc296d1b947eacab2d6354aac3d9 Mon Sep 17 00:00:00 2001 From: Ali Mirjamali Date: Mon, 8 Jul 2024 16:43:07 +0330 Subject: [PATCH 2/2] Making the Pylint happy for PR #197 --- qui/updater/utils.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/qui/updater/utils.py b/qui/updater/utils.py index 2e5355a6..2a646521 100644 --- a/qui/updater/utils.py +++ b/qui/updater/utils.py @@ -135,6 +135,8 @@ class QubeClass(Enum): AppVM = 3 DispVM = 4 +# pylint: disable=global-statement +# TODO: Encapsulate the below variable within a class __effective_css_provider__: Gtk.CssProvider = None def SetEffectiveCssProvider(CssProvider: Gtk.CssProvider) -> None: @@ -142,9 +144,8 @@ def SetEffectiveCssProvider(CssProvider: Gtk.CssProvider) -> None: __effective_css_provider__ = CssProvider def label_color_theme(color: str) -> str: - global __effective_css_provider__ widget = Gtk.Label() - if __effective_css_provider__ == None: + if not __effective_css_provider__: # Replicating the old behaviour. Both forward and backward compatible widget.get_style_context().add_class(f'qube-box-{color}') elif f'.qube-box-{color}' in __effective_css_provider__.to_string():