Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixing CSS for Updater VM name Labels #197

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

alimirjamali
Copy link

Setting the default VM Name Label colors for custom labels

Reference to issue: Fixes QubesOS/qubes-issues#9236

@marmarta
Copy link
Member

I don't like enforcing black/white text for all labels in all widgets - I'm afraid this will cause problems with users' custom themes or some other things we have not foreseen (as in, this looks like it works right now, but I'm somewhat worried about weird interactions in the future...)

In the color definitions (qubes-colors-light/dark files) we have a text-color color defined that is the color you need (black for light themes, dark for light themes) - I think it would be a bit safer to add a 'qube-box-all-colors' or something css class to the qube-widgets-base file, set the label color there, and then add this class to qube labels in updaters:

in qui/updater/utils.py:

def label_color_theme(color: str) -> str:
    widget = Gtk.Label()
    widget.get_style_context().add_class(f'qube-box-{color}')
    widget.get_style_context().add_class('qube-box-all-colors')  # add this
    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)
    return color_hex

@alimirjamali
Copy link
Author

In the color definitions (qubes-colors-light/dark files) we have a text-color color defined that is the color you need (black for light themes, dark for light themes) - I think it would be a bit safer to add a 'qube-box-all-colors' or something css class to the qube-widgets-base file, set the label color there, and then add this class to qube labels in updaters:

That is an excellent suggestion. I will try this in next few days and see if nothing breaks.

@alimirjamali
Copy link
Author

widget.get_style_context().add_class('qube-box-all-colors') # add this

I just realized that this is effectively overwriting the previous 'qube-box-{color} CSS class. It does not properly cascade. All labels will be in qube-box-all-colors this way. It would be possible to do something like:

def label_color_theme(color: str) -> str:
    widget = Gtk.Label()
    if color in ['red', 'orange', 'yellow', 'green', 'gray', 'blue', 'purple', 'black']:
        widget.get_style_context().add_class(f'qube-box-{color}')
    else:
        widget.get_style_context().add_class('qube-box-all-colors')  # add this
    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)
    return color_hex

We do not have the color label index here. But we could do something like:

    if qubesadmin.Qubes().get_label(color).index <= qubes.config.max_default_label:
        widget.get_style_context().add_class(f'qube-box-{color}')
    else:
        widget.get_style_context().add_class('qube-box-all-colors')  # add this        

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
2 participants