From 5e14781ad795894ac5aa52102021255668561a17 Mon Sep 17 00:00:00 2001 From: Tomeu Vizoso Date: Thu, 5 Jul 2007 14:16:36 +0200 Subject: [PATCH 1/3] Hide the active palette if another pops up. --- sugar/graphics/palette.py | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/sugar/graphics/palette.py b/sugar/graphics/palette.py index ef1a61c4..3a816d58 100644 --- a/sugar/graphics/palette.py +++ b/sugar/graphics/palette.py @@ -55,6 +55,7 @@ class Palette(gobject.GObject): gobject.GObject.__init__(self) self._position = self.AUTOMATIC + self._palette_popup_sid = None self._popup_anim = animator.Animator(0.3, 10) self._popup_anim.add(_PopupAnimation(self)) @@ -202,9 +203,15 @@ class Palette(gobject.GObject): if not self._in_screen(x, y): x, y = self._get_position(_TOP_RIGHT) + self._palette_popup_sid = _palette_observer.connect('popup', + self._palette_observer_popup_cb) self._menu.popup(x, y) + _palette_observer.emit('popup', self) def _hide(self): + if not self._palette_popup_sid is None: + _palette_observer.disconnect(self._palette_popup_sid) + self._palette_popup_sid = None self._menu.popdown() def popup(self): @@ -234,6 +241,10 @@ class Palette(gobject.GObject): def _button_press_event_cb(self, widget, event): pass + def _palette_observer_popup_cb(self, observer, palette): + if self != palette: + self._hide() + class _PrimaryMenuItem(gtk.MenuItem): def __init__(self, label, accel_path): gtk.MenuItem.__init__(self) @@ -390,3 +401,15 @@ class CanvasInvoker(Invoker): self.notify_mouse_leave() return False + +class _PaletteObserver(gobject.GObject): + __gtype_name__ = 'SugarPaletteObserver' + + __gsignals__ = { + 'popup': (gobject.SIGNAL_RUN_FIRST, gobject.TYPE_NONE, ([object])) + } + + def __init__(self): + gobject.GObject.__init__(self) + +_palette_observer = _PaletteObserver() From f614131ad7a9ebb3658a51ba7d58b37de9505880 Mon Sep 17 00:00:00 2001 From: Eduardo Silva Date: Thu, 5 Jul 2007 10:28:52 -0400 Subject: [PATCH 2/3] New graphics.menuitem.py file/class --- sugar/graphics/menuitem.py | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) create mode 100644 sugar/graphics/menuitem.py diff --git a/sugar/graphics/menuitem.py b/sugar/graphics/menuitem.py new file mode 100644 index 00000000..c16c1666 --- /dev/null +++ b/sugar/graphics/menuitem.py @@ -0,0 +1,28 @@ +# Copyright (C) 2007, Eduardo Silva (edsiper@gmail.com) +# +# This library is free software; you can redistribute it and/or +# modify it under the terms of the GNU Lesser General Public +# License as published by the Free Software Foundation; either +# version 2 of the License, or (at your option) any later version. +# +# This library is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +# Lesser General Public License for more details. +# +# You should have received a copy of the GNU Lesser General Public +# License along with this library; if not, write to the +# Free Software Foundation, Inc., 59 Temple Place - Suite 330, +# Boston, MA 02111-1307, USA. + +import gtk +from sugar.graphics.icon import Icon + +class MenuItem(gtk.ImageMenuItem): + def __init__(self, text_label, icon_name=None): + gtk.ImageMenuItem.__init__(self, text_label) + if icon_name: + icon = Icon(icon_name, gtk.ICON_SIZE_SMALL_TOOLBAR) + self.set_image(icon) + icon.show() + From 90b469e6db771f6d630239c84d68cbd48eb06e86 Mon Sep 17 00:00:00 2001 From: Eduardo Silva Date: Thu, 5 Jul 2007 10:56:17 -0400 Subject: [PATCH 3/3] Add icon to buddy menu items --- shell/view/BuddyMenu.py | 7 ++++--- sugar/graphics/Makefile.am | 1 + sugar/graphics/menuitem.py | 4 ++-- 3 files changed, 7 insertions(+), 5 deletions(-) diff --git a/shell/view/BuddyMenu.py b/shell/view/BuddyMenu.py index aa3de6a7..aae4e1ea 100644 --- a/shell/view/BuddyMenu.py +++ b/shell/view/BuddyMenu.py @@ -21,6 +21,7 @@ import gobject import hippo from sugar.graphics.palette import Palette +from sugar.graphics.menuitem import MenuItem from sugar.graphics import units from sugar.presence import presenceservice @@ -74,10 +75,10 @@ class BuddyMenu(Palette): friends = shell_model.get_friends() if friends.has_buddy(self._buddy): - menu_item = gtk.MenuItem(_('Remove friend')) #, 'theme:stock-remove') + menu_item = MenuItem(_('Remove friend'), 'stock-remove') menu_item.connect('activate', self._remove_friend_cb) else: - menu_item = gtk.MenuItem(_('Make friend')) #, 'theme:stock-add') + menu_item = MenuItem(_('Make friend'), 'stock-add') menu_item.connect('activate', self._make_friend_cb) self.append_menu_item(menu_item) menu_item.show() @@ -88,7 +89,7 @@ class BuddyMenu(Palette): # FIXME check that the buddy is not in the activity already - menu_item = gtk.MenuItem(_('Invite')) #, 'theme:stock-invite') + menu_item = MenuItem(_('Invite'), 'stock-invite') menu_item.connect('activate', self._invite_friend_cb) self.append_menu_item(menu_item) menu_item.show() diff --git a/sugar/graphics/Makefile.am b/sugar/graphics/Makefile.am index c15c5027..f88bd1b4 100644 --- a/sugar/graphics/Makefile.am +++ b/sugar/graphics/Makefile.am @@ -11,6 +11,7 @@ sugar_PYTHON = \ font.py \ frame.py \ notebook.py \ + menuitem.py \ objectchooser.py \ radiotoolbutton.py \ roundbox.py \ diff --git a/sugar/graphics/menuitem.py b/sugar/graphics/menuitem.py index c16c1666..492f5f13 100644 --- a/sugar/graphics/menuitem.py +++ b/sugar/graphics/menuitem.py @@ -1,4 +1,4 @@ -# Copyright (C) 2007, Eduardo Silva (edsiper@gmail.com) +# Copyright (C) 2007, Eduardo Silva # # This library is free software; you can redistribute it and/or # modify it under the terms of the GNU Lesser General Public @@ -22,7 +22,7 @@ class MenuItem(gtk.ImageMenuItem): def __init__(self, text_label, icon_name=None): gtk.ImageMenuItem.__init__(self, text_label) if icon_name: - icon = Icon(icon_name, gtk.ICON_SIZE_SMALL_TOOLBAR) + icon = Icon(icon_name, gtk.ICON_SIZE_MENU) self.set_image(icon) icon.show()