Support palettes for sub-toolbar widgets

This commit is contained in:
Aleksey Lim 2009-07-31 20:43:35 +00:00
parent 6e724c3d8d
commit 35bbfe1d50
2 changed files with 55 additions and 7 deletions

View File

@ -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()

View File

@ -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)