GNOME Bugzilla – Bug 761005
GtkColorChooser: make set_rgba work in editor mode
Last modified: 2016-01-23 23:18:39 UTC
When using the color chooser in editor mode, gtk_color_chooser_set_rgba need to be propaged to the editor
Created attachment 319573 [details] [review] GtkColorChooser: make set_rgba work in editor mode
That looks a little random to me. Why not do this unconditionally ? Whats the context and use case ?
user case: a Gnome-Builder color picker plugin It always starts with a permanent colorchooser in editor mode and tracks the text color codes under the cursor to update the color chooser editor you can try with this example: #!/usr/bin/env python3 import gi gi.require_version('Gtk', '3.0') from gi.repository import Gtk, Gdk import sys from random import random class Picker(Gtk.Window): def __init__(self): Gtk.Window.__init__(self, title="Picker") box = Gtk.Box() button = Gtk.Button(label="set editor color") button.connect("clicked", self.on_click) self.cc = Gtk.ColorChooserWidget(show_editor=True) box.add(button) box.add(self.cc) self.add(box) def on_click(self, button): rgba = Gdk.RGBA(random(), random(), random(), random()) self.cc.set_rgba(rgba) win = Picker() win.connect("delete-event", Gtk.main_quit) win.show_all() Gtk.main() I do this conditionally because there no need to update the editor when it's not visible The regular way to have an updated editor is from a color swatch in palette mode In the ColorChooser code, When you set_rgba, a matching existing color swatch is selected or a custom one is created but the editor is only updated with this value when showed. Being in editor mode and using set_rgba don't work without this patch
Review of attachment 319573 [details] [review]: The property change notification needs to happen unconditionally. And I am not concerned about the performance here - I would just update the editor unconditionally as well. So just take out the if-else
the notify always happen in any case, i have just take care it don't happen twice: We connect to rgba changes on the editor so that when you set_rgba on the editor, update_from_editor change it on the chooser. Doing both unconditionally set_rgba on the editor and notify in the chooser make the property notified twice. (once in select_swatch, once in update_from_editor)
Attachment 319573 [details] pushed as 526fd89 - GtkColorChooser: make set_rgba work in editor mode