~ubuntu-branches/debian/sid/sugar-toolkit-gtk3/sid

« back to all changes in this revision

Viewing changes to src/sugar3/graphics/colorbutton.py

  • Committer: Package Import Robot
  • Author(s): Jonas Smedegaard
  • Date: 2015-04-17 10:34:39 UTC
  • mfrom: (4.1.4 experimental)
  • Revision ID: package-import@ubuntu.com-20150417103439-xsqh30o8p0v6bflp
Tags: 0.104.1-5
* Move packaging to Debian Sugar Team.
* Update package relations:
  + Fix depend on python-gi-cairo.
    Thanks to Martin Abente and James Cameron.
* Fix typo in libsugarext-dev short description.
  Closes: bug#747026. Thanks to Anders Jonsson.

Show diffs side-by-side

added added

removed removed

Lines of Context:
29
29
from sugar3.graphics.palette import Palette, ToolInvoker, WidgetInvoker
30
30
 
31
31
 
32
 
_ = lambda msg: gettext.dgettext('sugar-toolkit', msg)
 
32
_ = lambda msg: gettext.dgettext('sugar-toolkit-gtk3', msg)
33
33
 
34
34
 
35
35
def get_svg_color_string(color):
48
48
 
49
49
    __gtype_name__ = 'SugarColorButton'
50
50
    __gsignals__ = {'color-set': (GObject.SignalFlags.RUN_FIRST, None,
51
 
        tuple())}
 
51
                                  tuple())}
52
52
 
53
53
    def __init__(self, **kwargs):
54
54
        self._title = _('Choose a color')
66
66
        # FIXME Drag and drop is not working, SL #3796
67
67
        if self._accept_drag:
68
68
            self.drag_dest_set(Gtk.DestDefaults.MOTION |
69
 
                    Gtk.DestDefaults.HIGHLIGHT | Gtk.DestDefaults.DROP,
70
 
                    [Gtk.TargetEntry.new('application/x-color', 0, 0)],
71
 
                    Gdk.DragAction.COPY)
 
69
                               Gtk.DestDefaults.HIGHLIGHT |
 
70
                               Gtk.DestDefaults.DROP,
 
71
                               [Gtk.TargetEntry.new(
 
72
                                'application/x-color', 0, 0)],
 
73
                               Gdk.DragAction.COPY)
72
74
        self.drag_source_set(Gdk.ModifierType.BUTTON1_MASK |
73
 
                    Gdk.ModifierType.BUTTON3_MASK,
74
 
                    [Gtk.TargetEntry.new('application/x-color', 0, 0)],
75
 
                    Gdk.DragAction.COPY)
 
75
                             Gdk.ModifierType.BUTTON3_MASK,
 
76
                             [Gtk.TargetEntry.new(
 
77
                                 'application/x-color', 0, 0)],
 
78
                             Gdk.DragAction.COPY)
76
79
        self.connect('drag_data_received', self.__drag_data_received_cb)
77
80
        self.connect('drag_data_get', self.__drag_data_get_cb)
78
81
 
92
95
                                          primary_text=self._title)
93
96
            self._palette.connect('color-set', self.__palette_color_set_cb)
94
97
            self._palette.connect('notify::color', self.
95
 
                __palette_color_changed)
 
98
                                  __palette_color_changed)
96
99
 
97
100
        return self._palette
98
101
 
110
113
        fg_color = context.get_color(Gtk.StateType.NORMAL)
111
114
        # the color components are stored as float values between 0.0 and 1.0
112
115
        return '#%.2X%.2X%.2X' % (fg_color.red * 255, fg_color.green * 255,
113
 
                              fg_color.blue * 255)
 
116
                                  fg_color.blue * 255)
114
117
 
115
118
    def set_color(self, color):
116
119
        assert isinstance(color, Gdk.Color)
167
170
 
168
171
    has_invoker = GObject.property(type=bool, default=True,
169
172
                                   flags=GObject.PARAM_READWRITE |
170
 
                                         GObject.PARAM_CONSTRUCT_ONLY,
 
173
                                   GObject.PARAM_CONSTRUCT_ONLY,
171
174
                                   getter=_get_has_invoker,
172
175
                                   setter=_set_has_invoker)
173
176
 
179
182
 
180
183
    has_palette = GObject.property(type=bool, default=True,
181
184
                                   flags=GObject.PARAM_READWRITE |
182
 
                                         GObject.PARAM_CONSTRUCT_ONLY,
 
185
                                   GObject.PARAM_CONSTRUCT_ONLY,
183
186
                                   getter=_get_has_palette,
184
187
                                   setter=_set_has_palette)
185
188
 
191
194
 
192
195
    accept_drag = GObject.property(type=bool, default=True,
193
196
                                   flags=GObject.PARAM_READWRITE |
194
 
                                         GObject.PARAM_CONSTRUCT_ONLY,
 
197
                                   GObject.PARAM_CONSTRUCT_ONLY,
195
198
                                   getter=_get_accept_drag,
196
199
                                   setter=_set_accept_drag)
197
200
 
198
201
    def __drag_begin_cb(self, widget, context):
199
202
        # Drag and Drop
200
203
        pixbuf = GdkPixbuf.Pixbuf(GdkPixbuf.Colorspace.RGB, True, 8,
201
 
                                style.SMALL_ICON_SIZE,
202
 
                                style.SMALL_ICON_SIZE)
 
204
                                  style.SMALL_ICON_SIZE,
 
205
                                  style.SMALL_ICON_SIZE)
203
206
 
204
207
        red = self._color.red / 257
205
208
        green = self._color.green / 257
211
214
 
212
215
    def __drag_data_get_cb(self, widget, context, selection_data, info, time):
213
216
        data = struct.pack('=HHHH', self._color.red, self._color.green,
214
 
                                    self._color.blue, 65535)
 
217
                           self._color.blue, 65535)
215
218
        selection_data.set(selection_data.target, 16, data)
216
219
 
217
 
    def __drag_data_received_cb(self, widget, context, x, y, selection_data, \
218
 
                               info, time):
 
220
    def __drag_data_received_cb(self, widget, context, x, y, selection_data,
 
221
                                info, time):
219
222
        if len(selection_data.data) != 8:
220
223
            return
221
224
 
242
245
    # The color-set signal is emitted when the user is finished selecting
243
246
    # a color.
244
247
    __gsignals__ = {'color-set': (GObject.SignalFlags.RUN_FIRST, None,
245
 
        tuple())}
 
248
                                  tuple())}
246
249
 
247
250
    def __init__(self, **kwargs):
248
251
        self._color = Gdk.Color(0, 0, 0)
255
258
        self.connect('popdown', self.__popdown_cb)
256
259
 
257
260
        self._picker_hbox = Gtk.HBox()
258
 
        self.set_content(self._picker_hbox)
 
261
        alignment = Gtk.Alignment()
 
262
        alignment.set_padding(0, 0, style.DEFAULT_SPACING,
 
263
                              style.DEFAULT_SPACING)
 
264
        alignment.add(self._picker_hbox)
 
265
        self.set_content(alignment)
 
266
        alignment.show()
259
267
 
260
268
        self._swatch_tray = Gtk.Table()
261
269
 
401
409
    keyval, mask = Gtk.accelerator_parse(tool_button.props.accelerator)
402
410
    # the accelerator needs to be set at the child, so the Gtk.AccelLabel
403
411
    # in the palette can pick it up.
404
 
    tool_button.get_child().add_accelerator('clicked', accel_group, keyval, mask,
405
 
                                      Gtk.AccelFlags.LOCKED | Gtk.AccelFlags.VISIBLE)
 
412
    tool_button.get_child(
 
413
    ).add_accelerator('clicked', accel_group, keyval, mask,
 
414
                      Gtk.AccelFlags.LOCKED | Gtk.AccelFlags.VISIBLE)
406
415
 
407
416
 
408
417
def _hierarchy_changed_cb(tool_button, previous_toplevel):
421
430
 
422
431
    __gtype_name__ = 'SugarColorToolButton'
423
432
    __gsignals__ = {'color-set': (GObject.SignalFlags.RUN_FIRST, None,
424
 
        tuple())}
 
433
                                  tuple())}
425
434
 
426
435
    def __init__(self, icon_name='color-preview', **kwargs):
427
436
        self._accelerator = None
466
475
        return self._accelerator
467
476
 
468
477
    accelerator = GObject.property(type=str, setter=set_accelerator,
469
 
            getter=get_accelerator)
 
478
                                   getter=get_accelerator)
470
479
 
471
480
    def create_palette(self):
472
481
        self._palette = self.get_child().create_palette()
540
549
    title = GObject.property(type=str, getter=get_title, setter=set_title)
541
550
 
542
551
    def do_draw(self, cr):
543
 
        child = self.get_child()
544
552
        if self._palette and self._palette.is_up():
545
553
            allocation = self.get_allocation()
546
554
            # draw a black background, has been done by the engine before