2022-07-18 08:10:00 +00:00
|
|
|
# option.py
|
2022-07-17 11:46:05 +00:00
|
|
|
#
|
2022-07-19 17:41:02 +00:00
|
|
|
# Copyright 2022 Adwaita Manager Team
|
2022-07-17 11:46:05 +00:00
|
|
|
#
|
|
|
|
# Permission is hereby granted, free of charge, to any person obtaining
|
|
|
|
# a copy of this software and associated documentation files (the
|
|
|
|
# "Software"), to deal in the Software without restriction, including
|
|
|
|
# without limitation the rights to use, copy, modify, merge, publish,
|
|
|
|
# distribute, sublicense, and/or sell copies of the Software, and to
|
|
|
|
# permit persons to whom the Software is furnished to do so, subject to
|
|
|
|
# the following conditions:
|
|
|
|
#
|
|
|
|
# The above copyright notice and this permission notice shall be
|
|
|
|
# included in all copies or substantial portions of the Software.
|
|
|
|
#
|
|
|
|
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
|
|
|
# EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
|
|
|
# MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
|
|
|
# NONINFRINGEMENT. IN NO EVENT SHALL THE X CONSORTIUM BE LIABLE FOR ANY
|
|
|
|
# CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
|
|
|
|
# TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
|
|
|
|
# SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
|
|
|
#
|
|
|
|
# Except as contained in this notice, the name(s) of the above copyright
|
|
|
|
# holders shall not be used in advertising or otherwise to promote the sale,
|
|
|
|
# use or other dealings in this Software without prior written
|
|
|
|
# authorization.
|
|
|
|
|
2022-07-24 18:43:32 +00:00
|
|
|
from gi.repository import Gtk, Gdk, Adw
|
2022-07-17 11:46:05 +00:00
|
|
|
|
2022-08-08 21:09:38 +00:00
|
|
|
@Gtk.Template(resource_path='/com/github/AdwCustomizerTeam/AdwCustomizer/ui/option.ui')
|
2022-07-17 11:46:05 +00:00
|
|
|
class AdwcustomizerOption(Adw.ActionRow):
|
|
|
|
__gtype_name__ = 'AdwcustomizerOption'
|
|
|
|
|
|
|
|
color_value = Gtk.Template.Child("color-value")
|
|
|
|
text_value = Gtk.Template.Child("text-value")
|
|
|
|
value_stack = Gtk.Template.Child("value-stack")
|
|
|
|
text_value_toggle = Gtk.Template.Child("text-value-toggle")
|
2022-07-18 14:23:01 +00:00
|
|
|
warning_button = Gtk.Template.Child("warning-button")
|
|
|
|
warning_label = Gtk.Template.Child("warning-label")
|
2022-07-17 11:46:05 +00:00
|
|
|
explanation_button = Gtk.Template.Child("explanation-button")
|
|
|
|
explanation_label = Gtk.Template.Child("explanation-label")
|
|
|
|
|
2022-07-18 14:23:01 +00:00
|
|
|
def __init__(self, name, title, adw_gtk3_support, explanation, **kwargs):
|
2022-07-17 11:46:05 +00:00
|
|
|
super().__init__(**kwargs)
|
|
|
|
|
2022-07-17 15:02:29 +00:00
|
|
|
self.set_name(name)
|
2022-07-17 11:46:05 +00:00
|
|
|
self.set_title(title)
|
2022-07-25 11:08:41 +00:00
|
|
|
self.set_subtitle("@" + name)
|
2022-07-18 14:23:01 +00:00
|
|
|
|
|
|
|
if adw_gtk3_support == "yes":
|
|
|
|
self.warning_button.set_visible(False)
|
|
|
|
elif adw_gtk3_support == "partial":
|
|
|
|
self.warning_button.add_css_class("warning")
|
2022-07-25 14:35:40 +00:00
|
|
|
self.warning_label.set_label(_("This option is only partially supported by the adw-gtk3 theme."))
|
2022-07-18 14:23:01 +00:00
|
|
|
elif adw_gtk3_support == "no":
|
|
|
|
self.warning_button.add_css_class("error")
|
2022-07-25 14:35:40 +00:00
|
|
|
self.warning_label.set_label(_("This option is not supported by the adw-gtk3 theme."))
|
2022-07-18 14:23:01 +00:00
|
|
|
|
2022-07-17 11:46:05 +00:00
|
|
|
self.explanation_label.set_label(explanation or "")
|
2022-07-18 14:23:01 +00:00
|
|
|
if explanation is None:
|
2022-07-17 11:46:05 +00:00
|
|
|
self.explanation_button.set_visible(False)
|
|
|
|
|
2022-07-17 12:25:36 +00:00
|
|
|
@Gtk.Template.Callback()
|
2022-07-25 14:35:40 +00:00
|
|
|
def on_color_value_changed(self, *_args):
|
2022-07-17 12:25:36 +00:00
|
|
|
self.update_value(self.color_value.get_rgba().to_string(), update_from="color_value")
|
|
|
|
|
|
|
|
@Gtk.Template.Callback()
|
2022-07-25 14:35:40 +00:00
|
|
|
def on_text_value_changed(self, *_args):
|
2022-07-17 12:25:36 +00:00
|
|
|
self.update_value(self.text_value.get_text(), update_from="text_value")
|
|
|
|
|
2022-07-17 11:46:05 +00:00
|
|
|
@Gtk.Template.Callback()
|
2022-07-25 14:35:40 +00:00
|
|
|
def on_text_value_toggled(self, *_args):
|
2022-07-24 18:43:32 +00:00
|
|
|
if self.text_value_toggle.get_active():
|
2022-07-17 11:46:05 +00:00
|
|
|
self.value_stack.set_visible_child(self.text_value)
|
|
|
|
else:
|
|
|
|
self.value_stack.set_visible_child(self.color_value)
|
|
|
|
|
2022-07-17 12:25:36 +00:00
|
|
|
def update_value(self, new_value, **kwargs):
|
2022-07-30 05:10:31 +00:00
|
|
|
rgba = Gdk.RGBA()
|
2022-07-17 12:25:36 +00:00
|
|
|
if kwargs.get("update_from") != "text_value":
|
2022-07-30 05:10:31 +00:00
|
|
|
if rgba.parse(new_value):
|
|
|
|
self.text_value.set_text(rgba.to_string())
|
|
|
|
else:
|
|
|
|
self.text_value.set_text(new_value)
|
2022-07-17 12:25:36 +00:00
|
|
|
if kwargs.get("update_from") != "color_value":
|
|
|
|
if rgba.parse(new_value):
|
|
|
|
self.color_value.set_rgba(rgba)
|
2022-07-24 17:46:37 +00:00
|
|
|
self.color_value.set_tooltip_text(new_value)
|
2022-07-17 12:25:36 +00:00
|
|
|
if kwargs.get("update_from") != "text_value":
|
|
|
|
self.text_value_toggle.set_active(False)
|
|
|
|
elif kwargs.get("update_from") != "text_value":
|
|
|
|
self.text_value_toggle.set_active(True)
|
|
|
|
else:
|
2022-07-30 05:10:31 +00:00
|
|
|
rgba.parse("rgba(0,0,0,0)")
|
2022-07-17 12:25:36 +00:00
|
|
|
self.color_value.set_rgba(rgba)
|
2022-07-25 14:35:40 +00:00
|
|
|
self.color_value.set_tooltip_text(_("Not a color, see text value"))
|
2022-07-17 11:46:05 +00:00
|
|
|
|
2022-07-17 15:02:29 +00:00
|
|
|
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
|
2022-08-01 19:42:42 +00:00
|
|
|
Gtk.Application.get_default().mark_as_dirty()
|
2022-07-17 15:02:29 +00:00
|
|
|
Gtk.Application.get_default().reload_variables()
|