Ticket #4008: 0001-Add-support-for-locking-Palettes.patch

File 0001-Add-support-for-locking-Palettes.patch, 8.5 KB (added by erikos, 11 years ago)

Add support for locking Palettes

  • src/sugar3/activity/widgets.py

    From b887e504eb789550cd07290c524637b3f6a4e1c1 Mon Sep 17 00:00:00 2001
    From: Simon Schampijer <simon@laptop.org>
    Date: Thu, 15 Nov 2012 18:09:00 +0100
    Subject: [PATCH toolkit-gtk3] Add support for locking Palettes
    
    This adds a property that indicates that a Palette should
    behave in a locking manner. The behaviour is the same
    as with the secondary Toolbars: when you hover over the invoking
    widget the Palette will popdown and react to mouse movements,
    leaving the invoker area or the Palette itself will popdown
    the Palette again. When you click the invoking widget
    the Palette will be locked. You have to unlock it again
    to pop it down.
    
    The DescriptionPalette can be seen as a good example, also
    the Colorbutton will work that way.
    
    When a secondary toolbar is unlocked we do force that the
    open Palettes are closed.
    ---
     src/sugar3/activity/widgets.py       |  1 +
     src/sugar3/graphics/colorbutton.py   | 11 ++------
     src/sugar3/graphics/palettewindow.py | 55 +++++++++++++++++++++++++++++++++---
     src/sugar3/graphics/toolbarbox.py    |  1 +
     4 files changed, 55 insertions(+), 13 deletions(-)
    
    diff --git a/src/sugar3/activity/widgets.py b/src/sugar3/activity/widgets.py
    index 03b2415..54b64a4 100644
    a b class DescriptionItem(Gtk.ToolItem): 
    228228        description_button.show()
    229229        description_button.set_tooltip(_('Description'))
    230230        description_button.palette_invoker.props.toggle_palette = True
     231        description_button.palette_invoker.props.lock_palette = True
    231232        description_button.props.hide_tooltip_on_click = False
    232233        self._palette = description_button.get_palette()
    233234
  • src/sugar3/graphics/colorbutton.py

    diff --git a/src/sugar3/graphics/colorbutton.py b/src/sugar3/graphics/colorbutton.py
    index 823fd61..e85157c 100644
    a b class _ColorButton(Gtk.Button): 
    112112        return '#%.2X%.2X%.2X' % (fg_color.red * 255, fg_color.green * 255,
    113113                              fg_color.blue * 255)
    114114
    115     def do_clicked(self):
    116         if self._palette:
    117             if not self._palette.is_up():
    118                 self._palette.popup(immediate=True,
    119                                     state=self._palette.SECONDARY)
    120             else:
    121                 self._palette.popdown(immediate=True)
    122             return True
    123 
    124115    def set_color(self, color):
    125116        assert isinstance(color, Gdk.Color)
    126117
    class ColorToolButton(Gtk.ToolItem): 
    451442        color_button.icon_size = Gtk.IconSize.LARGE_TOOLBAR
    452443
    453444        self._palette_invoker.attach_tool(self)
     445        self._palette_invoker.props.toggle_palette = True
     446        self._palette_invoker.props.lock_palette = True
    454447
    455448        # This widget just proxies the following properties to the colorbutton
    456449        color_button.connect('notify::color', self.__notify_change)
  • src/sugar3/graphics/palettewindow.py

    diff --git a/src/sugar3/graphics/palettewindow.py b/src/sugar3/graphics/palettewindow.py
    index 0283551..05873b9 100644
    a b STABLE. 
    2424"""
    2525
    2626import logging
     27import math
    2728
    2829from gi.repository import Gdk
    2930from gi.repository import Gtk
    class PaletteWindow(GObject.GObject): 
    655656        self.popdown()
    656657
    657658    def _invoker_mouse_enter_cb(self, invoker):
    658         self.on_invoker_enter()
     659        if not self._invoker.locked:
     660            self.on_invoker_enter()
    659661
    660662    def _invoker_mouse_leave_cb(self, invoker):
    661         self.on_invoker_leave()
     663        if not self._invoker.locked:
     664            self.on_invoker_leave()
    662665
    663666    def _invoker_right_click_cb(self, invoker):
    664667        self.popup(immediate=True, state=self.SECONDARY)
    class PaletteWindow(GObject.GObject): 
    670673            self.popup(immediate=True, state=self.SECONDARY)
    671674
    672675    def __enter_notify_cb(self, widget):
    673         self.on_enter()
     676        if not self._invoker.locked:
     677            self.on_enter()
    674678
    675679    def __leave_notify_cb(self, widget):
    676         self.on_leave()
     680        if not self._invoker.locked:
     681            self.on_leave()
    677682
    678683    def __show_cb(self, widget):
    679684        if self._invoker is not None:
    class Invoker(GObject.GObject): 
    774779        self._palette = None
    775780        self._cache_palette = True
    776781        self._toggle_palette = False
     782        self._lock_palette = False
     783        self.locked = False
    777784
    778785    def attach(self, parent):
    779786        self.parent = parent
    class Invoker(GObject.GObject): 
    10121019    button left click/touch tap. Defaults to False.
    10131020    """
    10141021
     1022    def get_lock_palette(self):
     1023        return self._lock_palette
     1024
     1025    def set_lock_palette(self, lock_palette):
     1026        self._lock_palette = lock_palette
     1027
     1028    lock_palette = GObject.property(type=object, setter=set_lock_palette,
     1029                                      getter=get_lock_palette)
     1030    """Whether the invoker will lock the Palette and
     1031    ignore mouse events. Defaults to False.
     1032    """
     1033
    10151034    def __palette_popdown_cb(self, palette):
    10161035        if not self.props.cache_palette:
    10171036            self.set_palette(None)
    class WidgetInvoker(Invoker): 
    10231042        Invoker.__init__(self)
    10241043
    10251044        self._widget = None
     1045        self._expanded = False
    10261046        self._enter_hid = None
    10271047        self._leave_hid = None
    10281048        self._release_hid = None
    10291049        self._click_hid = None
    10301050        self._touch_hid = None
     1051        self._draw_hid = None
    10311052        self._long_pressed_recognized = False
    10321053        self._long_pressed_hid = None
    10331054        self._long_pressed_controller = SugarGestures.LongPressController()
    class WidgetInvoker(Invoker): 
    10541075            self.__touch_event_cb)
    10551076        self._release_hid = self._widget.connect('button-release-event',
    10561077            self.__button_release_event_cb)
     1078        self._draw_hid = self._widget.connect_after('draw', self.__drawing_cb)
    10571079
    10581080        self._long_pressed_hid = self._long_pressed_controller.connect(
    10591081            'pressed', self.__long_pressed_event_cb, self._widget)
    class WidgetInvoker(Invoker): 
    10661088        self._widget.disconnect(self._enter_hid)
    10671089        self._widget.disconnect(self._leave_hid)
    10681090        self._widget.disconnect(self._release_hid)
     1091        self._widget.disconnect(self._draw_hid)
    10691092        if self._click_hid:
    10701093            self._widget.disconnect(self._click_hid)
    10711094        self._widget.disconnect(self._touch_hid)
    class WidgetInvoker(Invoker): 
    11271150
    11281151    def __click_event_cb(self, button):
    11291152        if self.props.toggle_palette:
     1153            if self.locked == False:
     1154                self.locked = True
     1155            else:
     1156                self.locked = False
    11301157            self.notify_toggle_state()
    11311158
    11321159    def __button_release_event_cb(self, widget, event):
    11331160        if event.button == 1 and not self._click_hid:
    11341161            if self.props.toggle_palette:
     1162                if self.locked == False:
     1163                    self.locked = True
     1164                else:
     1165                    self.locked = False
    11351166                self.notify_toggle_state()
    11361167        elif event.button == 3:
    11371168            self.notify_right_click()
    class WidgetInvoker(Invoker): 
    11481179
    11491180    def notify_popup(self):
    11501181        Invoker.notify_popup(self)
     1182        self._expanded = True
    11511183        self._widget.queue_draw()
    11521184
    11531185    def notify_popdown(self):
    11541186        Invoker.notify_popdown(self)
     1187        self._expanded = False
    11551188        self._widget.queue_draw()
    11561189
    11571190    def _get_widget(self):
    11581191        return self._widget
    11591192    widget = GObject.property(type=object, getter=_get_widget, setter=None)
    11601193
     1194    def __drawing_cb(self, widget, cr):
     1195        if not self.props.lock_palette:
     1196            return False
     1197        alloc = widget.get_allocation()
     1198        arrow_size = style.TOOLBAR_ARROW_SIZE / 2
     1199        y = alloc.height - arrow_size
     1200        x = (alloc.width - arrow_size) / 2
     1201        context = widget.get_style_context()
     1202        context.add_class('toolitem')
     1203        if self._expanded:
     1204            Gtk.render_arrow(context, cr, 0, x, y, arrow_size)
     1205        else:
     1206            Gtk.render_arrow(context, cr, math.pi, x, y, arrow_size)
     1207
    11611208
    11621209class CursorInvoker(Invoker):
    11631210
  • src/sugar3/graphics/toolbarbox.py

    diff --git a/src/sugar3/graphics/toolbarbox.py b/src/sugar3/graphics/toolbarbox.py
    index 1683403..8c4e644 100644
    a b class ToolbarButton(ToolButton): 
    8989
    9090    def set_expanded(self, expanded):
    9191        self.popdown()
     92        palettegroup.popdown_all()
    9293
    9394        if self.page is None or self.is_expanded() == expanded:
    9495            return