After an evaluation, GNOME has moved from Bugzilla to GitLab. Learn more about GitLab.
No new issues can be reported in GNOME Bugzilla anymore.
To report an issue in a GNOME project, go to GNOME GitLab.
Do not go to GNOME Gitlab for: Bluefish, Doxygen, GnuCash, GStreamer, java-gnome, LDTP, NetworkManager, Tomboy.
Bug 761005 - GtkColorChooser: make set_rgba work in editor mode
GtkColorChooser: make set_rgba work in editor mode
Status: RESOLVED FIXED
Product: gtk+
Classification: Platform
Component: Widget: GtkColorChooser
unspecified
Other All
: Normal trivial
: ---
Assigned To: gtk-bugs
gtk-bugs
Depends on:
Blocks:
 
 
Reported: 2016-01-22 21:32 UTC by sébastien lafargue
Modified: 2016-01-23 23:18 UTC
See Also:
GNOME target: ---
GNOME version: ---


Attachments
GtkColorChooser: make set_rgba work in editor mode (1.20 KB, patch)
2016-01-22 21:33 UTC, sébastien lafargue
committed Details | Review

Description sébastien lafargue 2016-01-22 21:32:57 UTC
When using the color chooser in editor mode,
gtk_color_chooser_set_rgba need to be propaged
to the editor
Comment 1 sébastien lafargue 2016-01-22 21:33:03 UTC
Created attachment 319573 [details] [review]
GtkColorChooser: make set_rgba work in editor mode
Comment 2 Matthias Clasen 2016-01-22 22:43:53 UTC
That looks a little random to me.
Why not do this unconditionally ?
Whats the context and use case ?
Comment 3 sébastien lafargue 2016-01-23 09:40:48 UTC
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
Comment 4 Matthias Clasen 2016-01-23 15:48:19 UTC
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
Comment 5 sébastien lafargue 2016-01-23 16:05:58 UTC
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)
Comment 6 Matthias Clasen 2016-01-23 23:18:36 UTC
Attachment 319573 [details] pushed as 526fd89 - GtkColorChooser: make set_rgba work in editor mode