mirror of
https://gitlab.gnome.org/jpu/cambalache.git
synced 2025-09-25 00:02:49 -04:00
CmbColorEntry: add new property editor
Add color editor
This commit is contained in:
parent
39814c2316
commit
d50be33972
@ -645,3 +645,68 @@ class CmbIconNameEntry(CmbEntry):
|
||||
popover.get_style_context().add_class("cmb-icon-chooser")
|
||||
popover.add(hbox)
|
||||
popover.popup()
|
||||
|
||||
|
||||
class CmbColorEntry(Gtk.Box):
|
||||
__gtype_name__ = 'CmbColorEntry'
|
||||
|
||||
use_color = GObject.Property(type=bool, default=False, flags = GObject.ParamFlags.READWRITE)
|
||||
|
||||
def __init__(self, **kwargs):
|
||||
self.__ignore_notify = False
|
||||
|
||||
super().__init__(**kwargs)
|
||||
|
||||
self.entry = Gtk.Entry(visible=True,
|
||||
width_chars=14,
|
||||
editable=False)
|
||||
self.button = Gtk.ColorButton(visible=True,
|
||||
use_alpha=True)
|
||||
|
||||
self.__default_color = self.button.props.color
|
||||
self.__default_rgba = self.button.props.rgba
|
||||
|
||||
self.pack_start(self.entry, False, True, 0)
|
||||
self.pack_start(self.button, False, True, 4)
|
||||
|
||||
self.button.connect('color-set', self.__on_color_set)
|
||||
self.entry.connect("icon-press", self.__on_entry_icon_pressed)
|
||||
|
||||
def __on_entry_icon_pressed(self, widget, icon_pos, event):
|
||||
self.cmb_value = None
|
||||
|
||||
def __on_color_set(self, obj):
|
||||
if self.use_color:
|
||||
self.cmb_value = self.button.props.color.to_string() if self.button.props.color else None
|
||||
else:
|
||||
self.cmb_value = self.button.props.rgba.to_string() if self.button.props.rgba else None
|
||||
|
||||
@GObject.Property(type=str)
|
||||
def cmb_value(self):
|
||||
return self.entry.props.text if self.entry.props.text != '' else None
|
||||
|
||||
@cmb_value.setter
|
||||
def _set_cmb_value(self, value):
|
||||
if value:
|
||||
self.entry.props.text = value
|
||||
self.entry.props.secondary_icon_name = 'edit-clear-symbolic'
|
||||
else:
|
||||
self.entry.props.text = ''
|
||||
self.entry.props.secondary_icon_name = None
|
||||
|
||||
valid = False
|
||||
|
||||
if self.use_color:
|
||||
color = None
|
||||
if value:
|
||||
valid, color = Gdk.Color.parse(value)
|
||||
|
||||
self.button.set_color(color if valid else self.__default_color)
|
||||
else:
|
||||
rgba = Gdk.RGBA()
|
||||
|
||||
if value:
|
||||
valid = rgba.parse(value)
|
||||
|
||||
self.button.set_rgba(rgba if valid else self.__default_rgba)
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user