2006-10-02 16:37:30 +02:00
|
|
|
import gtk
|
|
|
|
import hippo
|
|
|
|
import gobject
|
|
|
|
|
|
|
|
from sugar.graphics.canvasicon import CanvasIcon
|
2006-10-05 14:52:33 +02:00
|
|
|
from sugar.graphics import style
|
2006-10-02 16:37:30 +02:00
|
|
|
|
|
|
|
class Menu(gtk.Window):
|
|
|
|
__gsignals__ = {
|
|
|
|
'action': (gobject.SIGNAL_RUN_FIRST,
|
|
|
|
gobject.TYPE_NONE, ([int])),
|
|
|
|
}
|
|
|
|
|
|
|
|
def __init__(self, title, content_box=None):
|
|
|
|
gtk.Window.__init__(self, gtk.WINDOW_POPUP)
|
|
|
|
|
|
|
|
canvas = hippo.Canvas()
|
|
|
|
self.add(canvas)
|
|
|
|
canvas.show()
|
|
|
|
|
2006-10-05 16:29:55 +02:00
|
|
|
self._root = hippo.CanvasBox()
|
|
|
|
style.apply_stylesheet(self._root, 'menu')
|
2006-10-02 16:37:30 +02:00
|
|
|
canvas.set_root(self._root)
|
|
|
|
|
2006-10-05 16:29:55 +02:00
|
|
|
text = hippo.CanvasText(text=title)
|
|
|
|
style.apply_stylesheet(text, 'menu.Title')
|
2006-10-02 16:37:30 +02:00
|
|
|
self._root.append(text)
|
|
|
|
|
|
|
|
if content_box:
|
|
|
|
separator = self._create_separator()
|
|
|
|
self._root.append(separator)
|
|
|
|
self._root.append(content_box)
|
|
|
|
|
2006-10-05 16:29:55 +02:00
|
|
|
self._action_box = None
|
|
|
|
|
|
|
|
def _create_separator(self):
|
|
|
|
separator = hippo.CanvasBox()
|
|
|
|
style.apply_stylesheet(separator, 'menu.Separator')
|
|
|
|
return separator
|
|
|
|
|
|
|
|
def _create_action_box(self):
|
2006-10-02 16:37:30 +02:00
|
|
|
separator = self._create_separator()
|
|
|
|
self._root.append(separator)
|
|
|
|
|
|
|
|
self._action_box = hippo.CanvasBox(
|
|
|
|
orientation=hippo.ORIENTATION_HORIZONTAL)
|
|
|
|
self._root.append(self._action_box)
|
|
|
|
|
|
|
|
def add_action(self, icon, action_id):
|
2006-10-05 16:29:55 +02:00
|
|
|
if not self._action_box:
|
|
|
|
self._create_action_box()
|
|
|
|
|
2006-10-05 14:52:33 +02:00
|
|
|
style.apply_stylesheet(icon, 'menu.ActionIcon')
|
2006-10-02 16:37:30 +02:00
|
|
|
icon.connect('activated', self._action_clicked_cb, action_id)
|
|
|
|
self._action_box.append(icon)
|
|
|
|
|
|
|
|
def _action_clicked_cb(self, icon, action):
|
|
|
|
self.emit('action', action)
|