2007-07-06 14:36:59 +02:00
|
|
|
# Copyright (C) 2007, Eduardo Silva <edsiper@gmail.com>
|
2008-04-01 11:52:11 +02:00
|
|
|
# Copyright (C) 2008, One Laptop Per Child
|
2009-08-01 16:15:01 +02:00
|
|
|
# Copyright (C) 2009, Tomeu Vizoso
|
2007-05-24 19:37:48 +02:00
|
|
|
#
|
2007-06-14 22:04:25 +02:00
|
|
|
# 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.
|
2007-05-24 19:37:48 +02:00
|
|
|
#
|
2007-06-14 22:04:25 +02:00
|
|
|
# This library is distributed in the hope that it will be useful,
|
2007-05-24 19:37:48 +02:00
|
|
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
2007-06-14 22:04:25 +02:00
|
|
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
# Lesser General Public License for more details.
|
2007-05-24 19:37:48 +02:00
|
|
|
#
|
2007-06-14 22:04:25 +02:00
|
|
|
# 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.
|
2007-05-24 19:37:48 +02:00
|
|
|
|
2008-10-28 14:19:01 +01:00
|
|
|
"""
|
|
|
|
STABLE.
|
|
|
|
"""
|
|
|
|
|
2007-07-01 11:05:14 +02:00
|
|
|
import logging
|
|
|
|
|
2007-05-24 19:37:48 +02:00
|
|
|
import gtk
|
|
|
|
import gobject
|
2007-06-19 22:02:25 +02:00
|
|
|
import hippo
|
2008-01-10 19:21:29 +01:00
|
|
|
import pango
|
2007-05-24 19:37:48 +02:00
|
|
|
|
2007-07-06 14:36:59 +02:00
|
|
|
from sugar.graphics import palettegroup
|
2007-06-25 14:31:43 +02:00
|
|
|
from sugar.graphics import animator
|
2007-07-18 20:15:54 +02:00
|
|
|
from sugar.graphics import style
|
2008-04-19 10:45:52 +02:00
|
|
|
from sugar.graphics.icon import Icon
|
2009-08-01 16:15:01 +02:00
|
|
|
from sugar.graphics.palettewindow import PaletteWindow
|
2007-10-16 11:04:59 +02:00
|
|
|
from sugar import _sugarext
|
2007-06-25 14:31:43 +02:00
|
|
|
|
2009-08-01 16:15:01 +02:00
|
|
|
# DEPRECATED
|
|
|
|
# Import these for backwards compatibility
|
|
|
|
from sugar.graphics.palettewindow import MouseSpeedDetector, Invoker, \
|
|
|
|
WidgetInvoker, CanvasInvoker, ToolInvoker, CellRendererInvoker
|
2007-11-22 18:07:52 +01:00
|
|
|
|
2009-08-01 16:15:01 +02:00
|
|
|
class Palette(PaletteWindow):
|
2009-08-01 00:04:28 +02:00
|
|
|
PRIMARY = 0
|
|
|
|
SECONDARY = 1
|
|
|
|
|
2009-08-01 13:23:06 +02:00
|
|
|
__gtype_name__ = 'SugarPalette'
|
|
|
|
|
2008-04-01 03:27:46 +02:00
|
|
|
# DEPRECATED: label is passed with the primary-text property, accel_path
|
|
|
|
# is set via the invoker property, and menu_after_content is not used
|
2008-04-03 07:23:00 +02:00
|
|
|
def __init__(self, label=None, accel_path=None, menu_after_content=False,
|
2009-04-06 19:03:42 +02:00
|
|
|
text_maxlen=60, **kwargs):
|
2007-05-24 19:37:48 +02:00
|
|
|
|
2008-04-01 03:27:46 +02:00
|
|
|
self._primary_text = None
|
|
|
|
self._secondary_text = None
|
|
|
|
self._icon = None
|
|
|
|
self._icon_visible = True
|
2009-08-01 16:15:01 +02:00
|
|
|
self._palette_state = self.PRIMARY
|
2007-06-01 06:08:24 +02:00
|
|
|
|
2008-04-01 03:27:46 +02:00
|
|
|
palette_box = gtk.VBox()
|
2007-06-25 14:31:43 +02:00
|
|
|
|
2008-04-01 03:27:46 +02:00
|
|
|
primary_box = gtk.HBox()
|
|
|
|
palette_box.pack_start(primary_box, expand=False)
|
|
|
|
primary_box.show()
|
2007-07-02 12:05:42 +02:00
|
|
|
|
2008-04-01 03:27:46 +02:00
|
|
|
self._icon_box = gtk.HBox()
|
2009-03-13 15:44:57 +01:00
|
|
|
self._icon_box.set_size_request(style.GRID_CELL_SIZE, -1)
|
2008-04-01 03:27:46 +02:00
|
|
|
primary_box.pack_start(self._icon_box, expand=False)
|
2007-06-25 14:31:43 +02:00
|
|
|
|
2008-04-01 03:27:46 +02:00
|
|
|
labels_box = gtk.VBox()
|
|
|
|
self._label_alignment = gtk.Alignment(xalign=0, yalign=0.5,
|
2008-04-02 16:20:12 +02:00
|
|
|
xscale=1, yscale=0.33)
|
2008-04-01 03:27:46 +02:00
|
|
|
self._label_alignment.set_padding(0, 0, style.DEFAULT_SPACING,
|
|
|
|
style.DEFAULT_SPACING)
|
|
|
|
self._label_alignment.add(labels_box)
|
|
|
|
self._label_alignment.show()
|
|
|
|
primary_box.pack_start(self._label_alignment, expand=True)
|
|
|
|
labels_box.show()
|
2007-08-08 03:07:00 +02:00
|
|
|
|
2008-04-01 11:52:11 +02:00
|
|
|
self._label = gtk.AccelLabel('')
|
2007-09-22 00:21:45 +02:00
|
|
|
self._label.set_alignment(0, 0.5)
|
2008-01-10 19:21:29 +01:00
|
|
|
|
|
|
|
if text_maxlen > 0:
|
|
|
|
self._label.set_max_width_chars(text_maxlen)
|
|
|
|
self._label.set_ellipsize(pango.ELLIPSIZE_MIDDLE)
|
2008-04-01 03:27:46 +02:00
|
|
|
labels_box.pack_start(self._label, expand=True)
|
2008-01-10 19:21:29 +01:00
|
|
|
|
2008-04-01 03:27:46 +02:00
|
|
|
self._secondary_label = gtk.Label()
|
|
|
|
self._secondary_label.set_alignment(0, 0.5)
|
|
|
|
|
|
|
|
if text_maxlen > 0:
|
|
|
|
self._secondary_label.set_max_width_chars(text_maxlen)
|
2009-02-24 10:37:30 +01:00
|
|
|
self._secondary_label.set_ellipsize(pango.ELLIPSIZE_END)
|
2008-04-01 03:27:46 +02:00
|
|
|
|
|
|
|
labels_box.pack_start(self._secondary_label, expand=True)
|
2007-08-08 03:07:00 +02:00
|
|
|
|
2007-08-08 12:56:19 +02:00
|
|
|
self._secondary_box = gtk.VBox()
|
2008-04-01 03:27:46 +02:00
|
|
|
palette_box.pack_start(self._secondary_box)
|
2007-08-08 12:56:19 +02:00
|
|
|
|
2007-08-08 03:07:00 +02:00
|
|
|
self._separator = gtk.HSeparator()
|
2007-08-08 12:56:19 +02:00
|
|
|
self._secondary_box.pack_start(self._separator)
|
2007-08-08 03:07:00 +02:00
|
|
|
|
2007-09-22 00:43:14 +02:00
|
|
|
self._menu_content_separator = gtk.HSeparator()
|
|
|
|
|
2008-05-24 19:34:03 +02:00
|
|
|
self._secondary_anim = animator.Animator(2.0, 10)
|
2008-04-01 03:27:46 +02:00
|
|
|
self._secondary_anim.add(_SecondaryAnimation(self))
|
|
|
|
|
|
|
|
# we init after initializing all of our containers
|
2009-08-01 13:23:06 +02:00
|
|
|
PaletteWindow.__init__(self, **kwargs)
|
2008-12-05 11:51:40 +01:00
|
|
|
|
2009-03-13 15:44:57 +01:00
|
|
|
primary_box.set_size_request(-1, style.GRID_CELL_SIZE
|
2008-04-01 03:27:46 +02:00
|
|
|
- 2 * self.get_border_width())
|
2009-08-01 13:23:06 +02:00
|
|
|
|
|
|
|
self._full_request = [0, 0]
|
2008-04-19 10:45:52 +02:00
|
|
|
self._menu_box = None
|
|
|
|
self._content = None
|
2008-04-01 03:27:46 +02:00
|
|
|
|
|
|
|
# we set these for backward compatibility
|
|
|
|
if label is not None:
|
|
|
|
self.props.primary_text = label
|
|
|
|
|
|
|
|
self._add_menu()
|
|
|
|
self._secondary_box.pack_start(self._menu_content_separator)
|
|
|
|
self._add_content()
|
2007-06-02 06:33:41 +02:00
|
|
|
|
2007-08-08 13:03:09 +02:00
|
|
|
self.action_bar = PaletteActionBar()
|
|
|
|
self._secondary_box.pack_start(self.action_bar)
|
|
|
|
self.action_bar.show()
|
2007-06-06 06:51:01 +02:00
|
|
|
|
2008-04-01 03:27:46 +02:00
|
|
|
self.add(palette_box)
|
|
|
|
palette_box.show()
|
2007-06-25 11:39:51 +02:00
|
|
|
|
2007-09-22 00:43:14 +02:00
|
|
|
# The menu is not shown here until an item is added
|
2007-08-08 12:56:19 +02:00
|
|
|
self.menu = _Menu(self)
|
2008-09-07 21:51:10 +02:00
|
|
|
self.menu.connect('item-inserted', self.__menu_item_inserted_cb)
|
2007-08-08 11:53:41 +02:00
|
|
|
|
2009-08-01 13:23:06 +02:00
|
|
|
self.connect('realize', self.__realize_cb)
|
|
|
|
self.connect('show', self.__show_cb)
|
|
|
|
self.connect('hide', self.__hide_cb)
|
|
|
|
self.connect('notify::invoker', self.__notify_invoker_cb)
|
|
|
|
self.connect('destroy', self.__destroy_cb)
|
2007-06-06 04:43:42 +02:00
|
|
|
|
2009-08-01 13:23:06 +02:00
|
|
|
def _invoker_right_click_cb(self, invoker):
|
|
|
|
self.popup(immediate=True, state=self.SECONDARY)
|
|
|
|
|
|
|
|
def do_style_set(self, previous_style):
|
|
|
|
# Prevent a warning from pygtk
|
|
|
|
if previous_style is not None:
|
|
|
|
gtk.Window.do_style_set(self, previous_style)
|
|
|
|
self.set_border_width(self.get_style().xthickness)
|
2007-11-22 18:07:52 +01:00
|
|
|
|
2008-09-07 21:51:10 +02:00
|
|
|
def __menu_item_inserted_cb(self, menu):
|
|
|
|
self._update_separators()
|
|
|
|
|
2008-09-10 12:31:10 +02:00
|
|
|
def __destroy_cb(self, palette):
|
2008-09-13 13:23:49 +02:00
|
|
|
# Break the reference cycle. It looks like the gc is not able to free
|
|
|
|
# it, possibly because gtk.Menu memory handling is very special.
|
|
|
|
self.menu = None
|
2009-08-01 13:23:06 +02:00
|
|
|
|
|
|
|
def __show_cb(self, widget):
|
|
|
|
self.menu.set_active(True)
|
|
|
|
|
|
|
|
def __hide_cb(self, widget):
|
|
|
|
logging.debug('__hide_cb')
|
|
|
|
self.menu.set_active(False)
|
2009-08-01 16:15:01 +02:00
|
|
|
self._secondary_anim.stop()
|
2009-08-01 13:23:06 +02:00
|
|
|
|
|
|
|
def __notify_invoker_cb(self, palette, pspec):
|
|
|
|
invoker = self.props.invoker
|
|
|
|
if invoker is not None and hasattr(invoker.props, 'widget'):
|
|
|
|
self._update_accel_widget()
|
|
|
|
self._invoker.connect('notify::widget',
|
|
|
|
self.__invoker_widget_changed_cb)
|
|
|
|
|
|
|
|
def __invoker_widget_changed_cb(self, invoker, spec):
|
|
|
|
self._update_accel_widget()
|
|
|
|
|
|
|
|
def get_full_size_request(self):
|
|
|
|
return self._full_request
|
|
|
|
|
|
|
|
def popup(self, immediate=False, state=None):
|
|
|
|
logging.debug('Palette.popup immediate %r' % immediate)
|
|
|
|
|
|
|
|
if self._invoker is not None:
|
|
|
|
self._update_full_request()
|
|
|
|
|
|
|
|
PaletteWindow.popup(self, immediate)
|
|
|
|
|
|
|
|
if state is None:
|
|
|
|
state = self.PRIMARY
|
2009-08-01 00:04:28 +02:00
|
|
|
self.set_palette_state(state)
|
2009-08-01 13:23:06 +02:00
|
|
|
|
|
|
|
self._secondary_anim.start()
|
2009-08-01 16:15:01 +02:00
|
|
|
|
|
|
|
def on_enter(self, event):
|
|
|
|
PaletteWindow.on_enter(self, event)
|
|
|
|
self._secondary_anim.start()
|
2008-01-09 21:21:06 +01:00
|
|
|
|
2007-09-09 04:48:21 +02:00
|
|
|
def _add_menu(self):
|
|
|
|
self._menu_box = gtk.VBox()
|
|
|
|
self._secondary_box.pack_start(self._menu_box)
|
|
|
|
self._menu_box.show()
|
|
|
|
|
|
|
|
def _add_content(self):
|
2007-09-22 00:43:14 +02:00
|
|
|
# The content is not shown until a widget is added
|
2007-09-09 04:48:21 +02:00
|
|
|
self._content = gtk.VBox()
|
2007-10-16 18:17:01 +02:00
|
|
|
self._content.set_border_width(style.DEFAULT_SPACING)
|
2007-09-09 04:48:21 +02:00
|
|
|
self._secondary_box.pack_start(self._content)
|
|
|
|
|
2008-08-14 15:12:57 +02:00
|
|
|
def _update_accel_widget(self):
|
|
|
|
assert self.props.invoker is not None
|
|
|
|
self._label.props.accel_widget = self.props.invoker.props.widget
|
2008-04-01 03:27:46 +02:00
|
|
|
|
|
|
|
def set_primary_text(self, label, accel_path=None):
|
|
|
|
self._primary_text = label
|
|
|
|
|
2007-08-16 17:32:29 +02:00
|
|
|
if label is not None:
|
2008-04-01 11:52:11 +02:00
|
|
|
self._label.set_markup('<b>%s</b>' % label)
|
2007-08-16 17:32:29 +02:00
|
|
|
self._label.show()
|
2007-07-01 11:05:14 +02:00
|
|
|
|
2009-01-12 15:38:08 +01:00
|
|
|
def get_primary_text(self):
|
|
|
|
return self._primary_text
|
|
|
|
|
|
|
|
primary_text = gobject.property(type=str,
|
|
|
|
getter=get_primary_text,
|
|
|
|
setter=set_primary_text)
|
|
|
|
|
|
|
|
def set_secondary_text(self, label):
|
2009-02-24 10:56:09 +01:00
|
|
|
if label is not None:
|
|
|
|
label = label.split('\n', 1)[0]
|
2008-04-01 03:27:46 +02:00
|
|
|
self._secondary_text = label
|
|
|
|
|
|
|
|
if label is None:
|
|
|
|
self._secondary_label.hide()
|
|
|
|
else:
|
|
|
|
self._secondary_label.set_text(label)
|
|
|
|
self._secondary_label.show()
|
|
|
|
|
2009-01-12 15:38:08 +01:00
|
|
|
def get_secondary_text(self):
|
|
|
|
return self._secondary_text
|
|
|
|
|
|
|
|
|
|
|
|
secondary_text = gobject.property(type=str,
|
|
|
|
getter=get_secondary_text,
|
|
|
|
setter=set_secondary_text)
|
2008-04-01 03:27:46 +02:00
|
|
|
def _show_icon(self):
|
|
|
|
self._label_alignment.set_padding(0, 0, 0, style.DEFAULT_SPACING)
|
|
|
|
self._icon_box.show()
|
|
|
|
|
|
|
|
def _hide_icon(self):
|
|
|
|
self._icon_box.hide()
|
|
|
|
self._label_alignment.set_padding(0, 0, style.DEFAULT_SPACING,
|
|
|
|
style.DEFAULT_SPACING)
|
|
|
|
|
2009-02-10 18:57:02 +01:00
|
|
|
def set_icon(self, icon):
|
2008-04-01 03:27:46 +02:00
|
|
|
if icon is None:
|
|
|
|
self._icon = None
|
|
|
|
self._hide_icon()
|
|
|
|
else:
|
|
|
|
if self._icon:
|
2009-02-10 18:57:02 +01:00
|
|
|
self._icon_box.remove(self._icon_box.get_children()[0])
|
|
|
|
|
|
|
|
event_box = gtk.EventBox()
|
|
|
|
event_box.connect('button-release-event',
|
|
|
|
self.__icon_button_release_event_cb)
|
|
|
|
self._icon_box.pack_start(event_box)
|
|
|
|
event_box.show()
|
2008-04-01 03:27:46 +02:00
|
|
|
|
|
|
|
self._icon = icon
|
|
|
|
self._icon.props.icon_size = gtk.ICON_SIZE_LARGE_TOOLBAR
|
2009-02-10 18:57:02 +01:00
|
|
|
event_box.add(self._icon)
|
2008-04-01 03:27:46 +02:00
|
|
|
self._icon.show()
|
|
|
|
self._show_icon()
|
|
|
|
|
2009-01-12 15:38:08 +01:00
|
|
|
def get_icon(self):
|
|
|
|
return self._icon
|
|
|
|
|
|
|
|
icon = gobject.property(type=object, getter=get_icon, setter=set_icon)
|
|
|
|
|
2009-02-10 18:57:02 +01:00
|
|
|
def __icon_button_release_event_cb(self, icon, event):
|
|
|
|
self.emit('activate')
|
|
|
|
|
2009-01-12 15:38:08 +01:00
|
|
|
def set_icon_visible(self, visible):
|
2008-04-01 03:27:46 +02:00
|
|
|
self._icon_visible = visible
|
|
|
|
|
|
|
|
if visible and self._icon is not None:
|
|
|
|
self._show_icon()
|
|
|
|
else:
|
|
|
|
self._hide_icon()
|
|
|
|
|
2009-01-12 15:38:08 +01:00
|
|
|
def get_icon_visible(self):
|
|
|
|
return self._icon_visilbe
|
|
|
|
|
|
|
|
icon_visible = gobject.property(type=bool,
|
|
|
|
default=True,
|
|
|
|
getter=get_icon_visible,
|
|
|
|
setter=set_icon_visible)
|
|
|
|
|
2007-08-08 12:56:19 +02:00
|
|
|
def set_content(self, widget):
|
|
|
|
if len(self._content.get_children()) > 0:
|
2007-09-30 00:20:27 +02:00
|
|
|
self._content.remove(self._content.get_children()[0])
|
2007-06-26 18:19:26 +02:00
|
|
|
|
2007-08-08 12:56:19 +02:00
|
|
|
if widget is not None:
|
|
|
|
self._content.add(widget)
|
2007-09-22 00:43:14 +02:00
|
|
|
self._content.show()
|
|
|
|
else:
|
|
|
|
self._content.hide()
|
2007-06-26 18:19:26 +02:00
|
|
|
|
2007-08-08 11:53:41 +02:00
|
|
|
self._update_accept_focus()
|
2007-09-22 00:43:14 +02:00
|
|
|
self._update_separators()
|
2007-05-24 19:37:48 +02:00
|
|
|
|
2007-09-22 00:13:33 +02:00
|
|
|
def do_size_request(self, requisition):
|
2009-08-01 13:23:06 +02:00
|
|
|
PaletteWindow.do_size_request(self, requisition)
|
2007-09-22 00:13:33 +02:00
|
|
|
|
2008-04-01 11:52:11 +02:00
|
|
|
# gtk.AccelLabel request doesn't include the accelerator.
|
2008-04-02 16:20:12 +02:00
|
|
|
label_width = self._label_alignment.size_request()[0] + \
|
2008-04-01 11:52:11 +02:00
|
|
|
self._label.get_accel_width() + \
|
|
|
|
2 * self.get_border_width()
|
2007-09-22 00:13:33 +02:00
|
|
|
|
|
|
|
requisition.width = max(requisition.width,
|
2008-04-01 11:52:11 +02:00
|
|
|
label_width,
|
|
|
|
self._full_request[0])
|
2007-09-22 00:13:33 +02:00
|
|
|
|
2007-09-22 00:43:14 +02:00
|
|
|
def _update_separators(self):
|
2007-08-08 12:56:19 +02:00
|
|
|
visible = len(self.menu.get_children()) > 0 or \
|
|
|
|
len(self._content.get_children()) > 0
|
|
|
|
self._separator.props.visible = visible
|
|
|
|
|
2007-09-22 00:43:14 +02:00
|
|
|
visible = len(self.menu.get_children()) > 0 and \
|
|
|
|
len(self._content.get_children()) > 0
|
|
|
|
self._menu_content_separator.props.visible = visible
|
|
|
|
|
2007-08-08 11:53:41 +02:00
|
|
|
def _update_accept_focus(self):
|
|
|
|
accept_focus = len(self._content.get_children())
|
|
|
|
if self.window:
|
|
|
|
self.window.set_accept_focus(accept_focus)
|
|
|
|
|
2008-09-07 21:18:27 +02:00
|
|
|
def __realize_cb(self, widget):
|
2007-08-08 11:53:41 +02:00
|
|
|
self._update_accept_focus()
|
2007-08-08 03:07:00 +02:00
|
|
|
|
2007-07-24 16:15:13 +02:00
|
|
|
def _update_full_request(self):
|
2009-08-01 00:04:28 +02:00
|
|
|
if self._palette_state == self.PRIMARY:
|
2008-09-07 21:51:10 +02:00
|
|
|
self.menu.embed(self._menu_box)
|
|
|
|
self._secondary_box.show()
|
2007-07-24 16:15:13 +02:00
|
|
|
|
2007-08-08 03:07:00 +02:00
|
|
|
self._full_request = self.size_request()
|
2007-07-24 16:15:13 +02:00
|
|
|
|
2009-08-01 00:04:28 +02:00
|
|
|
if self._palette_state == self.PRIMARY:
|
2008-09-07 21:51:10 +02:00
|
|
|
self.menu.unembed()
|
|
|
|
self._secondary_box.hide()
|
2007-07-24 16:15:13 +02:00
|
|
|
|
2009-08-01 00:04:28 +02:00
|
|
|
def _set_palette_state(self, state):
|
|
|
|
if self._palette_state == state:
|
2007-07-24 15:53:35 +02:00
|
|
|
return
|
|
|
|
|
2007-08-24 14:21:07 +02:00
|
|
|
if state == self.PRIMARY:
|
2007-08-11 12:16:49 +02:00
|
|
|
self.menu.unembed()
|
2007-08-08 12:56:19 +02:00
|
|
|
self._secondary_box.hide()
|
2007-08-24 14:21:07 +02:00
|
|
|
elif state == self.SECONDARY:
|
2007-08-11 12:16:49 +02:00
|
|
|
self.menu.embed(self._menu_box)
|
2007-08-08 12:56:19 +02:00
|
|
|
self._secondary_box.show()
|
2009-08-01 13:23:06 +02:00
|
|
|
self.update_position()
|
2007-07-24 15:53:35 +02:00
|
|
|
|
2009-08-01 00:04:28 +02:00
|
|
|
self._palette_state = state
|
2007-07-24 15:53:35 +02:00
|
|
|
|
2007-08-08 13:03:09 +02:00
|
|
|
class PaletteActionBar(gtk.HButtonBox):
|
2008-04-19 10:45:52 +02:00
|
|
|
def add_action(self, label, icon_name=None):
|
|
|
|
button = gtk.Button(label)
|
2007-08-08 13:03:09 +02:00
|
|
|
|
|
|
|
if icon_name:
|
|
|
|
icon = Icon(icon_name)
|
|
|
|
button.set_image(icon)
|
|
|
|
icon.show()
|
|
|
|
|
|
|
|
self.pack_start(button)
|
|
|
|
button.show()
|
|
|
|
|
2007-10-16 11:04:59 +02:00
|
|
|
class _Menu(_sugarext.Menu):
|
2007-08-08 12:56:19 +02:00
|
|
|
__gtype_name__ = 'SugarPaletteMenu'
|
|
|
|
|
2008-09-07 21:51:10 +02:00
|
|
|
__gsignals__ = {
|
|
|
|
'item-inserted': (gobject.SIGNAL_RUN_FIRST, gobject.TYPE_NONE, ([]))
|
|
|
|
}
|
|
|
|
|
2007-08-08 12:56:19 +02:00
|
|
|
def __init__(self, palette):
|
2007-10-16 11:04:59 +02:00
|
|
|
_sugarext.Menu.__init__(self)
|
2007-08-08 12:56:19 +02:00
|
|
|
self._palette = palette
|
|
|
|
|
|
|
|
def do_insert(self, item, position):
|
2007-10-16 11:04:59 +02:00
|
|
|
_sugarext.Menu.do_insert(self, item, position)
|
2008-09-07 21:51:10 +02:00
|
|
|
self.emit('item-inserted')
|
2007-09-22 00:43:14 +02:00
|
|
|
self.show()
|
2007-08-08 12:56:19 +02:00
|
|
|
|
2008-09-19 17:17:05 +02:00
|
|
|
def attach(self, child, left_attach, right_attach,
|
|
|
|
top_attach, bottom_attach):
|
|
|
|
_sugarext.Menu.attach(self, child, left_attach, right_attach,
|
|
|
|
top_attach, bottom_attach)
|
|
|
|
self.emit('item-inserted')
|
|
|
|
self.show()
|
|
|
|
|
2007-08-10 18:29:28 +02:00
|
|
|
def do_expose_event(self, event):
|
|
|
|
# Ignore the Menu expose, just do the MenuShell expose to prevent any
|
|
|
|
# border from being drawn here. A border is drawn by the palette object
|
|
|
|
# around everything.
|
|
|
|
gtk.MenuShell.do_expose_event(self, event)
|
|
|
|
|
2007-08-10 23:21:36 +02:00
|
|
|
def do_grab_notify(self, was_grabbed):
|
|
|
|
# Ignore grab_notify as the menu would close otherwise
|
|
|
|
pass
|
|
|
|
|
2007-08-08 14:41:30 +02:00
|
|
|
def do_deactivate(self):
|
2008-09-07 21:18:27 +02:00
|
|
|
self._palette.hide()
|
2007-08-08 14:41:30 +02:00
|
|
|
|
2007-07-02 12:05:42 +02:00
|
|
|
class _SecondaryAnimation(animator.Animation):
|
|
|
|
def __init__(self, palette):
|
|
|
|
animator.Animation.__init__(self, 0.0, 1.0)
|
|
|
|
self._palette = palette
|
|
|
|
|
|
|
|
def next_frame(self, current):
|
|
|
|
if current == 1.0:
|
2009-08-01 00:04:28 +02:00
|
|
|
self._palette.set_palette_state(Palette.SECONDARY)
|
2007-07-02 12:39:16 +02:00
|
|
|
|