Skip to content
This repository has been archived by the owner on Jul 23, 2024. It is now read-only.

Commit

Permalink
Merge branch 'main' into shell-theming
Browse files Browse the repository at this point in the history
Signed-off-by: tfuxu <73042332+tfuxu@users.noreply.github.com>
  • Loading branch information
tfuxu committed Jan 6, 2023
2 parents fb9e1a5 + 787bb49 commit d3f9d28
Show file tree
Hide file tree
Showing 34 changed files with 1,404 additions and 1,446 deletions.
8 changes: 6 additions & 2 deletions data/ui/option_row.blp
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,10 @@ Popover warning-popover {
autohide: true;
Label warning-label {
margin-top: 10;
margin-start: 10;
margin-end: 10;
margin-bottom: 10;
max-width-chars: 60;
max-width-chars: 50;
wrap: true;
justify: center;
}
Expand All @@ -61,8 +63,10 @@ Popover explanation-popover {
autohide: true;
Label explanation-label {
margin-top: 10;
margin-start: 10;
margin-end: 10;
margin-bottom: 10;
max-width-chars: 60;
max-width-chars: 50;
wrap: true;
justify: center;
}
Expand Down
26 changes: 4 additions & 22 deletions data/ui/window.blp
Original file line number Diff line number Diff line change
Expand Up @@ -30,11 +30,12 @@ template GradienceMainWindow : Adw.ApplicationWindow {
tooltip-text: _("Apply Preset");
action-name: "app.apply_color_scheme";
}

[start]
Gtk.MenuButton {
Button {
icon-name: "applications-science-symbolic";
menu-model: preview-menu;
tooltip-text: _("Preview Theme in…");
tooltip-text: _("Show Preview Window");
visible: false;
}

[title]
Expand Down Expand Up @@ -143,25 +144,6 @@ menu main-menu {
}
}

menu preview-menu {
section {
item {
label: _("Adwaita Demo");
action: "app.show_adwaita_demo";
}

item {
label: _("GTK 4 Demo");
action: "app.show_gtk4_demo";
}

item {
label: _("GTK 4 Widget Factory");
action: "app.show_gtk4_widget_factory";
}
}
}

menu presets-menu {
section {
label: _("Built-In Presets");
Expand Down
9 changes: 4 additions & 5 deletions gradience/backend/css_parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,11 +51,10 @@ def parse_css(path):
if cdefine_match != None: # If @define-color variable declarations were found
palette_part = cdefine_match.__getitem__(1) # Get the second item of the re.Match object
name, color = palette_part.split(" ", 1)[1].split(" ", 1)
for color_name in adw_colors:
if name.startswith(color_name): # Palette colors
palette[name[:-1]][name[-1:]] = color[:-1]
else: # Other color variables
variables[name] = color[:-1]
if name.startswith(tuple(adw_colors)): # Palette colors
palette[name[:-1]][name[-1:]] = color[:-1]
else: # Other color variables
variables[name] = color[:-1]
elif not_cdefine_match != None: # If CSS rules were found
css_part = not_cdefine_match.__getitem__(1)
css += f"{css_part}\n"
Expand Down
129 changes: 65 additions & 64 deletions gradience/backend/theming/preset_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
from gi.repository import GLib, Gio

from gradience.backend.models.preset import Preset

from gradience.backend.models.shell import ShellTheme
from gradience.backend.utils.colors import rgba_from_argb, argb_to_color_code

Expand Down Expand Up @@ -69,98 +70,98 @@ def new_preset_from_monet(self, name=None, monet_palette=None, props=None, obj_o
if theme == "dark":
dark_theme = monet_palette["schemes"]["dark"]
variable = {
"accent_color": rgba_from_argb(dark_theme.primary),
"accent_bg_color": rgba_from_argb(dark_theme.primaryContainer),
"accent_fg_color": rgba_from_argb(dark_theme.onPrimaryContainer),
"destructive_color": rgba_from_argb(dark_theme.error),
"destructive_bg_color": rgba_from_argb(dark_theme.errorContainer),
"destructive_fg_color": rgba_from_argb(
"accent_color": argb_to_color_code(dark_theme.primary),
"accent_bg_color": argb_to_color_code(dark_theme.primaryContainer),
"accent_fg_color": argb_to_color_code(dark_theme.onPrimaryContainer),
"destructive_color": argb_to_color_code(dark_theme.error),
"destructive_bg_color": argb_to_color_code(dark_theme.errorContainer),
"destructive_fg_color": argb_to_color_code(
dark_theme.onErrorContainer
),
"success_color": rgba_from_argb(dark_theme.tertiary),
"success_bg_color": rgba_from_argb(dark_theme.onTertiary),
"success_fg_color": rgba_from_argb(dark_theme.onTertiaryContainer),
"warning_color": rgba_from_argb(dark_theme.secondary),
"warning_bg_color": rgba_from_argb(dark_theme.onSecondary),
"warning_fg_color": rgba_from_argb(dark_theme.primary, "0.8"),
"error_color": rgba_from_argb(dark_theme.error),
"error_bg_color": rgba_from_argb(dark_theme.errorContainer),
"error_fg_color": rgba_from_argb(dark_theme.onError),
"window_bg_color": rgba_from_argb(dark_theme.surface),
"window_fg_color": rgba_from_argb(dark_theme.onSurface),
"view_bg_color": rgba_from_argb(dark_theme.surface),
"view_fg_color": rgba_from_argb(dark_theme.onSurface),
"headerbar_bg_color": rgba_from_argb(dark_theme.surface),
"headerbar_fg_color": rgba_from_argb(dark_theme.onSurface),
"headerbar_border_color": rgba_from_argb(
"success_color": argb_to_color_code(dark_theme.tertiary),
"success_bg_color": argb_to_color_code(dark_theme.onTertiary),
"success_fg_color": argb_to_color_code(dark_theme.onTertiaryContainer),
"warning_color": argb_to_color_code(dark_theme.secondary),
"warning_bg_color": argb_to_color_code(dark_theme.onSecondary),
"warning_fg_color": argb_to_color_code(dark_theme.primary, "0.8"),
"error_color": argb_to_color_code(dark_theme.error),
"error_bg_color": argb_to_color_code(dark_theme.errorContainer),
"error_fg_color": argb_to_color_code(dark_theme.onError),
"window_bg_color": argb_to_color_code(dark_theme.surface),
"window_fg_color": argb_to_color_code(dark_theme.onSurface),
"view_bg_color": argb_to_color_code(dark_theme.surface),
"view_fg_color": argb_to_color_code(dark_theme.onSurface),
"headerbar_bg_color": argb_to_color_code(dark_theme.surface),
"headerbar_fg_color": argb_to_color_code(dark_theme.onSurface),
"headerbar_border_color": argb_to_color_code(
dark_theme.primary, "0.8"
),
"headerbar_backdrop_color": "@headerbar_bg_color",
"headerbar_shade_color": rgba_from_argb(dark_theme.shadow),
"card_bg_color": rgba_from_argb(dark_theme.primary, "0.05"),
"card_fg_color": rgba_from_argb(dark_theme.onSecondaryContainer),
"card_shade_color": rgba_from_argb(dark_theme.shadow),
"dialog_bg_color": rgba_from_argb(dark_theme.secondaryContainer),
"dialog_fg_color": rgba_from_argb(dark_theme.onSecondaryContainer),
"popover_bg_color": rgba_from_argb(dark_theme.secondaryContainer),
"popover_fg_color": rgba_from_argb(
"headerbar_shade_color": argb_to_color_code(dark_theme.shadow),
"card_bg_color": argb_to_color_code(dark_theme.primary, "0.05"),
"card_fg_color": argb_to_color_code(dark_theme.onSecondaryContainer),
"card_shade_color": argb_to_color_code(dark_theme.shadow),
"dialog_bg_color": argb_to_color_code(dark_theme.secondaryContainer),
"dialog_fg_color": argb_to_color_code(dark_theme.onSecondaryContainer),
"popover_bg_color": argb_to_color_code(dark_theme.secondaryContainer),
"popover_fg_color": argb_to_color_code(
dark_theme.onSecondaryContainer
),
"shade_color": rgba_from_argb(dark_theme.shadow),
"scrollbar_outline_color": rgba_from_argb(dark_theme.outline),
"shade_color": argb_to_color_code(dark_theme.shadow),
"scrollbar_outline_color": argb_to_color_code(dark_theme.outline),
}
elif theme == "light":
light_theme = monet_palette["schemes"]["light"]
variable = {
"accent_color": rgba_from_argb(light_theme.primary),
"accent_bg_color": rgba_from_argb(light_theme.primary),
"accent_fg_color": rgba_from_argb(light_theme.onPrimary),
"destructive_color": rgba_from_argb(light_theme.error),
"destructive_bg_color": rgba_from_argb(light_theme.errorContainer),
"destructive_fg_color": rgba_from_argb(
"accent_color": argb_to_color_code(light_theme.primary),
"accent_bg_color": argb_to_color_code(light_theme.primary),
"accent_fg_color": argb_to_color_code(light_theme.onPrimary),
"destructive_color": argb_to_color_code(light_theme.error),
"destructive_bg_color": argb_to_color_code(light_theme.errorContainer),
"destructive_fg_color": argb_to_color_code(
light_theme.onErrorContainer
),
"success_color": rgba_from_argb(light_theme.tertiary),
"success_bg_color": rgba_from_argb(light_theme.tertiaryContainer),
"success_fg_color": rgba_from_argb(
"success_color": argb_to_color_code(light_theme.tertiary),
"success_bg_color": argb_to_color_code(light_theme.tertiaryContainer),
"success_fg_color": argb_to_color_code(
light_theme.onTertiaryContainer
),
"warning_color": rgba_from_argb(light_theme.secondary),
"warning_bg_color": rgba_from_argb(light_theme.secondaryContainer),
"warning_fg_color": rgba_from_argb(
"warning_color": argb_to_color_code(light_theme.secondary),
"warning_bg_color": argb_to_color_code(light_theme.secondaryContainer),
"warning_fg_color": argb_to_color_code(
light_theme.onSecondaryContainer
),
"error_color": rgba_from_argb(light_theme.error),
"error_bg_color": rgba_from_argb(light_theme.errorContainer),
"error_fg_color": rgba_from_argb(light_theme.onError),
"window_bg_color": rgba_from_argb(light_theme.secondaryContainer),
"window_fg_color": rgba_from_argb(light_theme.onSurface),
"view_bg_color": rgba_from_argb(light_theme.secondaryContainer),
"view_fg_color": rgba_from_argb(light_theme.onSurface),
"headerbar_bg_color": rgba_from_argb(
"error_color": argb_to_color_code(light_theme.error),
"error_bg_color": argb_to_color_code(light_theme.errorContainer),
"error_fg_color": argb_to_color_code(light_theme.onError),
"window_bg_color": argb_to_color_code(light_theme.secondaryContainer),
"window_fg_color": argb_to_color_code(light_theme.onSurface),
"view_bg_color": argb_to_color_code(light_theme.secondaryContainer),
"view_fg_color": argb_to_color_code(light_theme.onSurface),
"headerbar_bg_color": argb_to_color_code(
light_theme.secondaryContainer
),
"headerbar_fg_color": rgba_from_argb(light_theme.onSurface),
"headerbar_border_color": rgba_from_argb(
"headerbar_fg_color": argb_to_color_code(light_theme.onSurface),
"headerbar_border_color": argb_to_color_code(
light_theme.primary, "0.8"
),
"headerbar_backdrop_color": "@headerbar_bg_color",
"headerbar_shade_color": rgba_from_argb(
"headerbar_shade_color": argb_to_color_code(
light_theme.secondaryContainer
),
"card_bg_color": rgba_from_argb(light_theme.primary, "0.05"),
"card_fg_color": rgba_from_argb(light_theme.onSecondaryContainer),
"card_shade_color": rgba_from_argb(light_theme.shadow),
"dialog_bg_color": rgba_from_argb(light_theme.secondaryContainer),
"dialog_fg_color": rgba_from_argb(
"card_bg_color": argb_to_color_code(light_theme.primary, "0.05"),
"card_fg_color": argb_to_color_code(light_theme.onSecondaryContainer),
"card_shade_color": argb_to_color_code(light_theme.shadow),
"dialog_bg_color": argb_to_color_code(light_theme.secondaryContainer),
"dialog_fg_color": argb_to_color_code(
light_theme.onSecondaryContainer
),
"popover_bg_color": rgba_from_argb(light_theme.secondaryContainer),
"popover_fg_color": rgba_from_argb(
"popover_bg_color": argb_to_color_code(light_theme.secondaryContainer),
"popover_fg_color": argb_to_color_code(
light_theme.onSecondaryContainer
),
"shade_color": rgba_from_argb(light_theme.shadow),
"scrollbar_outline_color": rgba_from_argb(light_theme.outline),
"shade_color": argb_to_color_code(light_theme.shadow),
"scrollbar_outline_color": argb_to_color_code(light_theme.outline),
}

if obj_only == False and not name:
Expand Down
49 changes: 39 additions & 10 deletions gradience/backend/utils/colors.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,38 @@ def rgba_from_argb(argb, alpha=None) -> str:

return base.format(red, green, blue, alpha)

def rgb_to_hash(rgb) -> [str, float]:
"""
This function converts rgb or rgba-formatted color code to an hexadecimal code.
Alpha channel from RGBA color codes is passed without any convertion
as a second return variable and is completely ignored in hexadecimal codes
to remain compliant with web stantards.
"""
if rgb.startswith("rgb"):
rgb_values = rgb.strip("rgb()")

if rgb.startswith("rgba"):
rgb_values = rgb.strip("rgba()")

rgb_list = rgb_values.split(",")

red = int(rgb_list[0])
green = int(rgb_list[1])
blue = int(rgb_list[2])
alpha = None

if len(rgb_list) == 4:
alpha = float(rgb_list[3])

hex_out = [f"{red:x}", f"{green:x}", f"{blue:x}"]

for i, hex_part in enumerate(hex_out):
if len(hex_part) == 1:
hex_out[i] = "0" + hex_part

return "#" + "".join(hex_out), alpha

def argb_to_color_code(argb, alpha=None) -> str:
"""
This function can return either an hexadecimal or rgba-formatted color code.
Expand All @@ -38,18 +70,15 @@ def argb_to_color_code(argb, alpha=None) -> str:
If alpha parameter is specified, then the function will return
an rgba-formatted color code.
"""
hex_base = "#{0:x}{1:x}{2:x}"
rgba_base = "rgba({0}, {1}, {2}, {3})"

red_chnl = monet.redFromArgb(argb)
green_chnl = monet.greenFromArgb(argb)
blue_chnl = monet.blueFromArgb(argb)
alpha_chnl = alpha

red = monet.redFromArgb(argb)
green = monet.greenFromArgb(argb)
blue = monet.blueFromArgb(argb)
if not alpha:
alpha_chnl = monet.alphaFromArgb(argb)
alpha = monet.alphaFromArgb(argb)

if alpha_chnl in (255, 0.0):
return hex_base.format(red_chnl, green_chnl, blue_chnl)
if alpha in (255, 0.0):
return monet.hexFromArgb(argb)

return rgba_base.format(red_chnl, green_chnl, blue_chnl, alpha_chnl)
return rgba_base.format(red, green, blue, alpha)
11 changes: 10 additions & 1 deletion gradience/frontend/dialogs/save_dialog.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,15 @@
from gradience.backend.constants import rootdir


# TODO: Make this dialog async when Libadwaita 1.3 becomes available \
# https://gnome.pages.gitlab.gnome.org/libadwaita/doc/main/method.MessageDialog.choose.html
@Gtk.Template(resource_path=f"{rootdir}/ui/save_dialog.ui")
class GradienceSaveDialog(Adw.MessageDialog):
__gtype_name__ = "GradienceSaveDialog"

preset_entry = Gtk.Template.Child("preset-entry")

def __init__(self, parent, heading=None, body=None, path=None, **kwargs):
def __init__(self, parent, heading=None, body=None, path=None, discard=False, **kwargs):
super().__init__(**kwargs)

self.parent = parent
Expand All @@ -53,6 +55,13 @@ def __init__(self, parent, heading=None, body=None, path=None, **kwargs):
raise AttributeError("DEV FAULT: You need to either specify 'body' or 'path' parameter")

self.add_response("cancel", _("_Cancel"))

if discard:
self.add_response("discard", _("Discard"))
self.set_response_appearance(
"discard", Adw.ResponseAppearance.DESTRUCTIVE
)

self.add_response("save", _("_Save"))
self.set_default_response("cancel")
self.set_close_response("cancel")
Expand Down
Loading

0 comments on commit d3f9d28

Please sign in to comment.