From 35bbfe1d5015bb4f2792d10739ad90ba94fec410 Mon Sep 17 00:00:00 2001 From: Aleksey Lim Date: Fri, 31 Jul 2009 20:43:35 +0000 Subject: [PATCH] Support palettes for sub-toolbar widgets --- src/sugar/graphics/palette.py | 24 +++++++++++++++----- src/sugar/graphics/toolbarbox.py | 38 +++++++++++++++++++++++++++++++- 2 files changed, 55 insertions(+), 7 deletions(-) diff --git a/src/sugar/graphics/palette.py b/src/sugar/graphics/palette.py index a29a9412..c681af9d 100644 --- a/src/sugar/graphics/palette.py +++ b/src/sugar/graphics/palette.py @@ -340,26 +340,38 @@ class PaletteWindow(gtk.Window): else: self.hide() - def _invoker_mouse_enter_cb(self, invoker): + def on_invoker_enter(self): self._mouse_detector.start() - def _invoker_mouse_leave_cb(self, invoker): + def on_invoker_leave(self): self._mouse_detector.stop() self.popdown() + def on_enter(self, event): + self._popdown_anim.stop() + self._secondary_anim.start() + + def on_leave(self, event): + self.popdown() + + def _invoker_mouse_enter_cb(self, invoker): + self.on_invoker_enter() + + def _invoker_mouse_leave_cb(self, invoker): + self.on_invoker_leave() + def _invoker_right_click_cb(self, invoker): self.popup(immediate=True) def __enter_notify_event_cb(self, widget, event): if event.detail != gtk.gdk.NOTIFY_INFERIOR and \ event.mode == gtk.gdk.CROSSING_NORMAL: - self._popdown_anim.stop() - self._secondary_anim.start() + self.on_enter(event) def __leave_notify_event_cb(self, widget, event): if event.detail != gtk.gdk.NOTIFY_INFERIOR and \ event.mode == gtk.gdk.CROSSING_NORMAL: - self.popdown() + self.on_leave(event) def __show_cb(self, widget): self._invoker.notify_popup() @@ -385,7 +397,7 @@ class PaletteWindow(gtk.Window): y = win_y + rectangle.y width = rectangle.width height = rectangle.height - + return gtk.gdk.Rectangle(x, y, width, height) class Palette(PaletteWindow): diff --git a/src/sugar/graphics/toolbarbox.py b/src/sugar/graphics/toolbarbox.py index 2344b534..91c5c2d8 100644 --- a/src/sugar/graphics/toolbarbox.py +++ b/src/sugar/graphics/toolbarbox.py @@ -24,6 +24,7 @@ import gtk from sugar.graphics import style from sugar.graphics.palette import PaletteWindow, ToolInvoker from sugar.graphics.toolbutton import ToolButton +from sugar.graphics import palettegroup class ToolbarButton(ToolButton): def __init__(self, page=None, **kwargs): @@ -68,7 +69,7 @@ class ToolbarButton(ToolButton): self.page_widget in self.toolbar_box.get_children(): self.toolbar_box.remove(self.page_widget) - if self.props.palette is not None: + if isinstance(self.props.palette, _ToolbarPalette): self.props.palette.add(self.page_widget) def is_expanded(self): @@ -176,6 +177,37 @@ class _ToolbarPalette(PaletteWindow): PaletteWindow.__init__(self, **kwargs) self.toolbar_box = None self.set_border_width(0) + self._focus = 0 + + group = palettegroup.get_group('default') + group.connect('popdown', self.__group_popdown_cb) + self.set_group_id('toolbar_box') + + def on_invoker_enter(self): + PaletteWindow.on_invoker_enter(self) + self._handle_focus(+1) + + def on_invoker_leave(self): + PaletteWindow.on_invoker_leave(self) + self._handle_focus(-1) + + def on_enter(self, event): + PaletteWindow.on_enter(self, event) + self._handle_focus(+1) + + def on_leave(self, event): + PaletteWindow.on_enter(self, event) + self._handle_focus(-1) + + def _handle_focus(self, delta): + self._focus += delta + if self._focus not in (0, 1): + logging.error('_Palette._focus=%s not in (0, 1)' % self._focus) + + if self._focus == 0: + group = palettegroup.get_group('default') + if not group.is_up(): + self.popdown() def do_size_request(self, requisition): gtk.Window.do_size_request(self, requisition) @@ -191,6 +223,10 @@ class _ToolbarPalette(PaletteWindow): box.props.padding) PaletteWindow.popup(self, immediate) + def __group_popdown_cb(self, group): + if self._focus == 0: + self.popdown(immediate=True) + class _Box(gtk.EventBox): def __init__(self): gtk.EventBox.__init__(self)