Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/pr/197'
Browse files Browse the repository at this point in the history
* origin/pr/197:
  Making the Pylint happy for PR #197
  Fixing CSS for Updater GUI VM Name Labels
  • Loading branch information
marmarek committed Jul 18, 2024
2 parents 5377b51 + d283842 commit 18ca655
Show file tree
Hide file tree
Showing 6 changed files with 27 additions and 4 deletions.
4 changes: 3 additions & 1 deletion qubes_config/widgets/gtk_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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
Expand All @@ -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):
Expand Down
1 change: 1 addition & 0 deletions qui/styles/qubes-colors-dark.css
Original file line number Diff line number Diff line change
Expand Up @@ -41,3 +41,4 @@
@define-color blue-label #4363d8;
@define-color purple-label #911eb4;
@define-color black-label #ffffff;
@define-color custom-label #ffffff;
3 changes: 2 additions & 1 deletion qui/styles/qubes-colors-light.css
Original file line number Diff line number Diff line change
Expand Up @@ -40,4 +40,5 @@
@define-color gray-label #555555;
@define-color blue-label #0E2276;
@define-color purple-label #3F0C46;
@define-color black-label #000000;
@define-color black-label #000000;
@define-color custom-label #000000;
4 changes: 4 additions & 0 deletions qui/styles/qubes-widgets-base.css
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,10 @@ label {
color: @black-label;
}

.qube-box-custom-label {
color: @custom-label;
}

.group_title {
font-weight: 400;
font-size: 150%;
Expand Down
4 changes: 3 additions & 1 deletion qui/updater/updater.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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")

Expand Down
15 changes: 14 additions & 1 deletion qui/updater/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -135,10 +135,23 @@ 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:
global __effective_css_provider__
__effective_css_provider__ = CssProvider

def label_color_theme(color: str) -> str:
widget = Gtk.Label()
widget.get_style_context().add_class(f'qube-box-{color}')
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():
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)
Expand Down

0 comments on commit 18ca655

Please sign in to comment.