mirror of
https://github.com/GradienceTeam/Gradience.git
synced 2024-09-29 23:17:53 +00:00
Changing values now actually does things
This commit is contained in:
parent
bfcc7f3a54
commit
71d32d7bb5
2 changed files with 19 additions and 9 deletions
22
src/main.py
22
src/main.py
|
@ -51,6 +51,9 @@ class AdwcustomizerApplication(Adw.Application):
|
|||
We raise the application's main window, creating it if
|
||||
necessary.
|
||||
"""
|
||||
self.variables = {}
|
||||
self.is_ready = False
|
||||
|
||||
win = self.props.active_window
|
||||
if not win:
|
||||
win = AdwcustomizerMainWindow(application=self)
|
||||
|
@ -66,7 +69,7 @@ class AdwcustomizerApplication(Adw.Application):
|
|||
pref_group.set_description(group["description"])
|
||||
|
||||
for variable in group["variables"]:
|
||||
pref_variable = AdwcustomizerOption(variable["title"], variable.get("explanation"), "#00000000")
|
||||
pref_variable = AdwcustomizerOption(variable["name"], variable["title"], variable.get("explanation"), "#00000000")
|
||||
pref_group.add(pref_variable)
|
||||
self.pref_variables[variable["name"]] = pref_variable
|
||||
|
||||
|
@ -80,26 +83,29 @@ class AdwcustomizerApplication(Adw.Application):
|
|||
|
||||
win.present()
|
||||
|
||||
self.is_ready = True
|
||||
|
||||
def load_preset(self, preset_path):
|
||||
preset_text = Gio.resources_lookup_data(preset_path, 0).get_data().decode()
|
||||
preset = json.loads(preset_text)
|
||||
variables = preset["variables"]
|
||||
self.variables = preset["variables"]
|
||||
|
||||
for key in variables.keys():
|
||||
for key in self.variables.keys():
|
||||
if key in self.pref_variables:
|
||||
self.pref_variables[key].update_value(variables[key])
|
||||
self.pref_variables[key].update_value(self.variables[key])
|
||||
|
||||
self.apply_variables_to_app(variables)
|
||||
self.reload_variables()
|
||||
|
||||
def generate_css(self, variables):
|
||||
final_css = ""
|
||||
for key in variables.keys():
|
||||
final_css += "@define-color {0} {1};\n".format(key, variables[key])
|
||||
print(final_css)
|
||||
return final_css
|
||||
|
||||
def apply_variables_to_app(self, variables):
|
||||
def reload_variables(self):
|
||||
css_provider = Gtk.CssProvider()
|
||||
css_provider.load_from_data(self.generate_css(variables).encode())
|
||||
css_provider.load_from_data(self.generate_css(self.variables).encode())
|
||||
# loading with the priority above user to override the applied config
|
||||
Gtk.StyleContext.add_provider_for_display(Gdk.Display.get_default(), css_provider, Gtk.STYLE_PROVIDER_PRIORITY_USER + 1)
|
||||
|
||||
|
@ -122,7 +128,7 @@ class AdwcustomizerApplication(Adw.Application):
|
|||
modal=True,
|
||||
program_name='AdwCustomizer',
|
||||
logo_icon_name='com.github.ArtyIF.AdwCustomizer',
|
||||
version='0.0.3',
|
||||
version='0.0.4',
|
||||
authors=['ArtyIF'],
|
||||
copyright='© 2022 ArtyIF')
|
||||
|
||||
|
|
|
@ -40,9 +40,10 @@ class AdwcustomizerOption(Adw.ActionRow):
|
|||
explanation_button = Gtk.Template.Child("explanation-button")
|
||||
explanation_label = Gtk.Template.Child("explanation-label")
|
||||
|
||||
def __init__(self, title, explanation, value, **kwargs):
|
||||
def __init__(self, name, title, explanation, value, **kwargs):
|
||||
super().__init__(**kwargs)
|
||||
|
||||
self.set_name(name)
|
||||
self.set_title(title)
|
||||
self.explanation_label.set_label(explanation or "")
|
||||
if (explanation is None):
|
||||
|
@ -80,4 +81,7 @@ class AdwcustomizerOption(Adw.ActionRow):
|
|||
rgba.parse("#00000000")
|
||||
self.color_value.set_rgba(rgba)
|
||||
|
||||
if Gtk.Application.get_default().is_ready and kwargs.get("update_from") == "text_value" and new_value != "":
|
||||
Gtk.Application.get_default().variables[self.get_name()] = new_value
|
||||
Gtk.Application.get_default().reload_variables()
|
||||
|
||||
|
|
Loading…
Reference in a new issue