Expose palette.menu rather than wrapping methods.
This commit is contained in:
parent
ff5edef2bc
commit
6dd6b0275b
@ -85,7 +85,8 @@ class BuddyMenu(Palette):
|
|||||||
else:
|
else:
|
||||||
menu_item = MenuItem(_('Make friend'), 'stock-add')
|
menu_item = MenuItem(_('Make friend'), 'stock-add')
|
||||||
menu_item.connect('activate', self._make_friend_cb)
|
menu_item.connect('activate', self._make_friend_cb)
|
||||||
self.append_menu_item(menu_item)
|
|
||||||
|
self.menu.append(menu_item)
|
||||||
menu_item.show()
|
menu_item.show()
|
||||||
|
|
||||||
activity = shell_model.get_home().get_current_activity()
|
activity = shell_model.get_home().get_current_activity()
|
||||||
@ -96,7 +97,7 @@ class BuddyMenu(Palette):
|
|||||||
|
|
||||||
menu_item = MenuItem(_('Invite'), 'stock-invite')
|
menu_item = MenuItem(_('Invite'), 'stock-invite')
|
||||||
menu_item.connect('activate', self._invite_friend_cb)
|
menu_item.connect('activate', self._invite_friend_cb)
|
||||||
self.append_menu_item(menu_item)
|
self.menu.append(menu_item)
|
||||||
menu_item.show()
|
menu_item.show()
|
||||||
|
|
||||||
def _buddy_icon_changed_cb(self, buddy):
|
def _buddy_icon_changed_cb(self, buddy):
|
||||||
|
@ -130,7 +130,7 @@ class HomeMyIcon(MyIcon):
|
|||||||
|
|
||||||
shutdown_menu_item = gtk.MenuItem(_('Shutdown'))
|
shutdown_menu_item = gtk.MenuItem(_('Shutdown'))
|
||||||
shutdown_menu_item.connect('activate', self._shutdown_activate_cb)
|
shutdown_menu_item.connect('activate', self._shutdown_activate_cb)
|
||||||
palette.append_menu_item(shutdown_menu_item)
|
palette.menu.append(shutdown_menu_item)
|
||||||
shutdown_menu_item.show()
|
shutdown_menu_item.show()
|
||||||
|
|
||||||
self.set_palette(palette)
|
self.set_palette(palette)
|
||||||
|
@ -88,14 +88,14 @@ class ActivityIcon(CanvasIcon):
|
|||||||
|
|
||||||
resume_menu_item = gtk.MenuItem(_('Resume'))
|
resume_menu_item = gtk.MenuItem(_('Resume'))
|
||||||
resume_menu_item.connect('activate', self._resume_activate_cb)
|
resume_menu_item.connect('activate', self._resume_activate_cb)
|
||||||
palette.append_menu_item(resume_menu_item)
|
palette.menu.append(resume_menu_item)
|
||||||
resume_menu_item.show()
|
resume_menu_item.show()
|
||||||
|
|
||||||
# FIXME: kludge
|
# FIXME: kludge
|
||||||
if self._activity.get_type() != "org.laptop.JournalActivity":
|
if self._activity.get_type() != "org.laptop.JournalActivity":
|
||||||
stop_menu_item = gtk.MenuItem(_('Stop'))
|
stop_menu_item = gtk.MenuItem(_('Stop'))
|
||||||
stop_menu_item.connect('activate', self._stop_activate_cb)
|
stop_menu_item.connect('activate', self._stop_activate_cb)
|
||||||
palette.append_menu_item(stop_menu_item)
|
palette.menu.append(stop_menu_item)
|
||||||
stop_menu_item.show()
|
stop_menu_item.show()
|
||||||
|
|
||||||
def _launching_changed_cb(self, activity, pspec):
|
def _launching_changed_cb(self, activity, pspec):
|
||||||
|
@ -96,24 +96,30 @@ class Palette(gtk.Window):
|
|||||||
self._label = gtk.Label()
|
self._label = gtk.Label()
|
||||||
vbox.pack_start(self._label, False)
|
vbox.pack_start(self._label, False)
|
||||||
|
|
||||||
|
self._secondary_box = gtk.VBox()
|
||||||
|
vbox.pack_start(self._secondary_box)
|
||||||
|
|
||||||
self._separator = gtk.HSeparator()
|
self._separator = gtk.HSeparator()
|
||||||
vbox.pack_start(self._separator)
|
self._secondary_box.pack_start(self._separator)
|
||||||
|
|
||||||
menu_box = gtk.VBox()
|
menu_box = gtk.VBox()
|
||||||
vbox.pack_start(menu_box)
|
self._secondary_box.pack_start(menu_box)
|
||||||
menu_box.show()
|
menu_box.show()
|
||||||
|
|
||||||
self._content = gtk.VBox()
|
self._content = gtk.VBox()
|
||||||
vbox.pack_start(self._content)
|
self._secondary_box.pack_start(self._content)
|
||||||
|
self._content.show()
|
||||||
|
|
||||||
self._button_bar = gtk.HButtonBox()
|
self._button_bar = gtk.HButtonBox()
|
||||||
vbox.pack_start(self._button_bar)
|
self._secondary_box.pack_start(self._button_bar)
|
||||||
|
self._button_bar.show()
|
||||||
|
|
||||||
self.add(vbox)
|
self.add(vbox)
|
||||||
vbox.show()
|
vbox.show()
|
||||||
|
|
||||||
self._menu = _sugaruiext.Menu()
|
self.menu = _Menu(self)
|
||||||
self._menu.embed(menu_box)
|
self.menu.embed(menu_box)
|
||||||
|
self.menu.show()
|
||||||
|
|
||||||
self.connect('enter-notify-event',
|
self.connect('enter-notify-event',
|
||||||
self._enter_notify_event_cb)
|
self._enter_notify_event_cb)
|
||||||
@ -129,18 +135,15 @@ class Palette(gtk.Window):
|
|||||||
self._label.set_text(label)
|
self._label.set_text(label)
|
||||||
self._label.show()
|
self._label.show()
|
||||||
|
|
||||||
def append_menu_item(self, item):
|
|
||||||
self._menu.append(item)
|
|
||||||
|
|
||||||
def insert_menu_item(self, item, index=-1):
|
|
||||||
self._menu.insert(item, index)
|
|
||||||
|
|
||||||
def remove_menu_item(self, index):
|
|
||||||
self._menu.remove(self._menu.get_children()[index])
|
|
||||||
|
|
||||||
def set_content(self, widget):
|
def set_content(self, widget):
|
||||||
|
if len(self._content.get_children()) > 0:
|
||||||
|
self.remove(self._content.get_children()[0])
|
||||||
|
|
||||||
|
if widget is not None:
|
||||||
|
self._content.add(widget)
|
||||||
|
|
||||||
self._update_accept_focus()
|
self._update_accept_focus()
|
||||||
self._content.pack_start(widget)
|
self._update_separator()
|
||||||
|
|
||||||
def append_button(self, button):
|
def append_button(self, button):
|
||||||
self._button_bar.append_button(button)
|
self._button_bar.append_button(button)
|
||||||
@ -172,6 +175,11 @@ class Palette(gtk.Window):
|
|||||||
else:
|
else:
|
||||||
raise AssertionError
|
raise AssertionError
|
||||||
|
|
||||||
|
def _update_separator(self):
|
||||||
|
visible = len(self.menu.get_children()) > 0 or \
|
||||||
|
len(self._content.get_children()) > 0
|
||||||
|
self._separator.props.visible = visible
|
||||||
|
|
||||||
def _update_accept_focus(self):
|
def _update_accept_focus(self):
|
||||||
accept_focus = len(self._content.get_children())
|
accept_focus = len(self._content.get_children())
|
||||||
if self.window:
|
if self.window:
|
||||||
@ -308,7 +316,7 @@ class Palette(gtk.Window):
|
|||||||
'popup', self._palette_observer_popup_cb)
|
'popup', self._palette_observer_popup_cb)
|
||||||
|
|
||||||
self._update_position()
|
self._update_position()
|
||||||
self._menu.set_active(True)
|
self.menu.set_active(True)
|
||||||
self.show()
|
self.show()
|
||||||
|
|
||||||
self._up = True
|
self._up = True
|
||||||
@ -319,7 +327,7 @@ class Palette(gtk.Window):
|
|||||||
if not self._palette_popup_sid is None:
|
if not self._palette_popup_sid is None:
|
||||||
_palette_observer.disconnect(self._palette_popup_sid)
|
_palette_observer.disconnect(self._palette_popup_sid)
|
||||||
self._palette_popup_sid = None
|
self._palette_popup_sid = None
|
||||||
self._menu.set_active(False)
|
self.menu.set_active(False)
|
||||||
self.hide()
|
self.hide()
|
||||||
|
|
||||||
self._up = False
|
self._up = False
|
||||||
@ -344,22 +352,9 @@ class Palette(gtk.Window):
|
|||||||
return
|
return
|
||||||
|
|
||||||
if state == self._PRIMARY:
|
if state == self._PRIMARY:
|
||||||
self._menu.hide()
|
self._secondary_box.hide()
|
||||||
self._content.hide()
|
|
||||||
self._separator.hide()
|
|
||||||
self._button_bar.hide()
|
|
||||||
elif state == self._SECONDARY:
|
elif state == self._SECONDARY:
|
||||||
has_menu_items = len(self._menu.get_children()) > 0
|
self._secondary_box.show()
|
||||||
self._menu.props.visible = has_menu_items
|
|
||||||
|
|
||||||
has_content = len(self._content.get_children()) > 0
|
|
||||||
self._content.props.visible = has_content
|
|
||||||
|
|
||||||
has_buttons = len(self._button_bar.get_children()) > 0
|
|
||||||
self._button_bar.props.visible = has_buttons
|
|
||||||
|
|
||||||
has_separator = has_buttons or has_menu_items or has_content
|
|
||||||
self._separator.props.visible = has_separator
|
|
||||||
|
|
||||||
self._state = state
|
self._state = state
|
||||||
|
|
||||||
@ -382,6 +377,17 @@ class Palette(gtk.Window):
|
|||||||
if self != palette:
|
if self != palette:
|
||||||
self._hide()
|
self._hide()
|
||||||
|
|
||||||
|
class _Menu(_sugaruiext.Menu):
|
||||||
|
__gtype_name__ = 'SugarPaletteMenu'
|
||||||
|
|
||||||
|
def __init__(self, palette):
|
||||||
|
_sugaruiext.Menu.__init__(self)
|
||||||
|
self._palette = palette
|
||||||
|
|
||||||
|
def do_insert(self, item, position):
|
||||||
|
_sugaruiext.Menu.do_insert(self, item, position)
|
||||||
|
self._palette._update_separator()
|
||||||
|
|
||||||
class _PopupAnimation(animator.Animation):
|
class _PopupAnimation(animator.Animation):
|
||||||
def __init__(self, palette):
|
def __init__(self, palette):
|
||||||
animator.Animation.__init__(self, 0.0, 1.0)
|
animator.Animation.__init__(self, 0.0, 1.0)
|
||||||
|
Loading…
Reference in New Issue
Block a user