[Sugar-devel] [sugar-toolkit-gtk3] Finish the port of ColorToolButton to gtk3

Manuel Quiñones manuq at laptop.org
Tue Aug 7 19:03:49 EDT 2012


Thanks Gonzalo.

2012/8/7  <godiard at sugarlabs.org>:
> From: Gonzalo Odiard <godiard at gmail.com>
>
> This patch solves the following problems:
>
> * API changed in the drag and drop code in Gtk
> * Changes in the way to get color information from the theme.

I would also add in the message that this is because Gtk.Style was
deprecated by Gtk.StyleContext.  If you mention it the next time, the
review can be faster too :)

> * The internal button was not visible.
>
> Signed-of-by: Gonzalo Odiard <gonzalo at laptop.org>
> ---
>  src/sugar3/graphics/colorbutton.py | 30 ++++++++++++++++++------------
>  1 file changed, 18 insertions(+), 12 deletions(-)
>
> diff --git a/src/sugar3/graphics/colorbutton.py b/src/sugar3/graphics/colorbutton.py
> index c21da47..3b847b3 100644
> --- a/src/sugar3/graphics/colorbutton.py
> +++ b/src/sugar3/graphics/colorbutton.py
> @@ -64,20 +64,19 @@ class _ColorButton(Gtk.Button):
>          GObject.GObject.__init__(self, **kwargs)
>
>          if self._accept_drag:
> -            Gtk.drag_dest_set(self, Gtk.DEST_DEFAULT_MOTION |
> -                               Gtk.DEST_DEFAULT_HIGHLIGHT |
> -                               Gtk.DEST_DEFAULT_DROP,
> -                               [('application/x-color', 0, 0)],
> -                               Gdk.DragAction.COPY)
> -        self.drag_source_set(Gdk.EventMask.BUTTON1_MASK | Gdk.EventMask.BUTTON3_MASK,
> -                             [('application/x-color', 0, 0)],
> -                             Gdk.DragAction.COPY)
> +            self.drag_dest_set(Gtk.DestDefaults.MOTION |
> +                    Gtk.DestDefaults.HIGHLIGHT | Gtk.DestDefaults.DROP,
> +                    [Gtk.TargetEntry.new('application/x-color', 0, 0)],
> +                    Gdk.DragAction.COPY)
> +        self.drag_source_set(Gdk.ModifierType.BUTTON1_MASK | \
> +                    Gdk.ModifierType.BUTTON3_MASK,
> +                    [Gtk.TargetEntry.new('application/x-color', 0, 0)],
> +                    Gdk.DragAction.COPY)

Drag and drop is not working for me.  A way to test it: drag one color
from the same palette to the toolbar button.  Another: add two color
buttons and drag from the palette of one to the other button.

I will try to figure out the problem and report back.

Are the PyGi devs aware that this constants are not being converted in
the pygi-convert script?

>          self.connect('drag_data_received', self.__drag_data_received_cb)
>          self.connect('drag_data_get', self.__drag_data_get_cb)
>
>          self._preview.fill_color = get_svg_color_string(self._color)
> -        self._preview.stroke_color = \
> -            get_svg_color_string(self.style.fg[Gtk.StateType.NORMAL])
> +        self._preview.stroke_color = self._get_fg_style_color_str()

I think would be a more readable name: _get_preview_stroke_color.

>          self.set_image(self._preview)
>
>          if self._has_palette and self._has_invoker:
> @@ -103,8 +102,14 @@ class _ColorButton(Gtk.Button):
>          self.color = self._palette.color
>
>      def do_style_set(self, previous_style):
> -        self._preview.stroke_color = \
> -            get_svg_color_string(self.style.fg[Gtk.StateType.NORMAL])
> +        self._preview.stroke_color = self._get_fg_style_color_str()
> +
> +    def _get_fg_style_color_str(self):
> +        context = self.get_style_context()
> +        fg_color = context.get_color(Gtk.StateType.NORMAL)
> +        # the color components are stored as float values between 0.0 and 1.0
> +        return '#%.2X%.2X%.2X' % (fg_color.red * 255, fg_color.green * 255,
> +                              fg_color.blue * 255)

Great, this is because of the deprecation mentioned above.  The
returned colors are the same as in GTK2.

>      def do_clicked(self):
>          if self._palette:
> @@ -438,6 +443,7 @@ class ColorToolButton(Gtk.ToolItem):
>          # Replace it with a ColorButton
>          color_button = _ColorButton(icon_name=icon_name, has_invoker=False)
>          self.add(color_button)
> +        color_button.show()

Yes, tested and without this addition the button is not shown.

>          # The following is so that the behaviour on the toolbar is correct.
>          color_button.set_relief(Gtk.ReliefStyle.NONE)
> --
> 1.7.11.2
>
> _______________________________________________
> Sugar-devel mailing list
> Sugar-devel at lists.sugarlabs.org
> http://lists.sugarlabs.org/listinfo/sugar-devel

-- 
.. manuq ..


More information about the Sugar-devel mailing list