2006-08-28 14:04:51 +02:00
|
|
|
import goocanvas
|
|
|
|
|
2006-09-13 13:50:00 +02:00
|
|
|
from sugar.canvas.CanvasBox import CanvasBox
|
2006-08-28 14:04:51 +02:00
|
|
|
from sugar.canvas.IconItem import IconItem
|
2006-09-16 20:35:03 +02:00
|
|
|
from sugar.canvas.MenuIcon import MenuIcon
|
|
|
|
from sugar.canvas.Menu import Menu
|
2006-09-17 01:05:59 +02:00
|
|
|
from view.frame.MenuStrategy import MenuStrategy
|
2006-08-28 14:36:48 +02:00
|
|
|
import sugar
|
2006-08-28 14:04:51 +02:00
|
|
|
|
2006-09-16 20:35:03 +02:00
|
|
|
class ActivityMenu(Menu):
|
|
|
|
ACTION_SHARE = 1
|
2006-09-18 11:56:53 +02:00
|
|
|
ACTION_CLOSE = 2
|
2006-09-16 20:35:03 +02:00
|
|
|
|
|
|
|
def __init__(self, grid, activity_host):
|
|
|
|
title = activity_host.get_title()
|
2006-09-16 20:48:27 +02:00
|
|
|
Menu.__init__(self, grid, title)
|
2006-09-16 20:35:03 +02:00
|
|
|
|
|
|
|
icon = IconItem(icon_name='stock-share')
|
|
|
|
self.add_action(icon, ActivityMenu.ACTION_SHARE)
|
|
|
|
|
2006-09-18 11:56:53 +02:00
|
|
|
icon = IconItem(icon_name='stock-close-activity')
|
|
|
|
self.add_action(icon, ActivityMenu.ACTION_CLOSE)
|
|
|
|
|
2006-09-16 20:35:03 +02:00
|
|
|
class ActivityIcon(MenuIcon):
|
2006-09-19 14:04:11 +02:00
|
|
|
def __init__(self, shell, menu_shell, activity_host):
|
2006-09-16 20:35:03 +02:00
|
|
|
self._shell = shell
|
|
|
|
self._activity_host = activity_host
|
|
|
|
|
|
|
|
icon_name = activity_host.get_icon_name()
|
|
|
|
icon_color = activity_host.get_icon_color()
|
|
|
|
|
2006-09-19 14:04:11 +02:00
|
|
|
MenuIcon.__init__(self, menu_shell, icon_name=icon_name,
|
2006-09-16 20:35:03 +02:00
|
|
|
color=icon_color)
|
|
|
|
|
2006-09-17 01:05:59 +02:00
|
|
|
self.set_menu_strategy(MenuStrategy())
|
|
|
|
|
2006-09-16 20:35:03 +02:00
|
|
|
def create_menu(self):
|
|
|
|
menu = ActivityMenu(self._shell.get_grid(), self._activity_host)
|
|
|
|
menu.connect('action', self._action_cb)
|
|
|
|
return menu
|
|
|
|
|
|
|
|
def _action_cb(self, menu, action):
|
2006-09-18 11:56:53 +02:00
|
|
|
self.popdown()
|
|
|
|
|
|
|
|
activity = self._shell.get_current_activity()
|
|
|
|
if activity == None:
|
|
|
|
return
|
|
|
|
|
2006-09-16 20:35:03 +02:00
|
|
|
if action == ActivityMenu.ACTION_SHARE:
|
2006-09-18 11:56:53 +02:00
|
|
|
activity.share()
|
|
|
|
if action == ActivityMenu.ACTION_CLOSE:
|
|
|
|
activity.close()
|
2006-09-16 20:35:03 +02:00
|
|
|
|
2006-09-13 13:50:00 +02:00
|
|
|
class TopPanel(goocanvas.Group):
|
2006-09-19 14:04:11 +02:00
|
|
|
def __init__(self, shell, menu_shell):
|
2006-09-13 13:50:00 +02:00
|
|
|
goocanvas.Group.__init__(self)
|
|
|
|
|
2006-08-28 14:36:48 +02:00
|
|
|
self._shell = shell
|
2006-09-19 14:04:11 +02:00
|
|
|
self._menu_shell = menu_shell
|
2006-09-16 20:35:03 +02:00
|
|
|
self._activity_icon = None
|
2006-08-28 14:04:51 +02:00
|
|
|
|
2006-09-15 14:24:26 +02:00
|
|
|
grid = shell.get_grid()
|
|
|
|
|
2006-09-22 10:55:10 +02:00
|
|
|
box = CanvasBox(grid, CanvasBox.HORIZONTAL)
|
2006-09-15 14:24:26 +02:00
|
|
|
grid.set_constraints(box, 5, 0)
|
2006-09-13 13:50:00 +02:00
|
|
|
self.add_child(box)
|
2006-09-08 00:51:45 +02:00
|
|
|
|
2006-09-22 10:55:10 +02:00
|
|
|
icon = IconItem(icon_name='stock-zoom-mesh')
|
|
|
|
icon.connect('clicked', self._level_clicked_cb, sugar.ZOOM_MESH)
|
|
|
|
box.set_constraints(icon, 5, 5)
|
2006-09-13 13:50:00 +02:00
|
|
|
box.add_child(icon)
|
2006-09-08 00:51:45 +02:00
|
|
|
|
2006-09-13 13:50:00 +02:00
|
|
|
icon = IconItem(icon_name='stock-zoom-friends')
|
2006-09-16 20:35:03 +02:00
|
|
|
icon.connect('clicked', self._level_clicked_cb, sugar.ZOOM_FRIENDS)
|
2006-09-22 10:55:10 +02:00
|
|
|
box.set_constraints(icon, 5, 5)
|
2006-09-13 13:50:00 +02:00
|
|
|
box.add_child(icon)
|
2006-08-28 14:04:51 +02:00
|
|
|
|
2006-09-22 10:55:10 +02:00
|
|
|
icon = IconItem(icon_name='stock-zoom-home')
|
|
|
|
icon.connect('clicked', self._level_clicked_cb, sugar.ZOOM_HOME)
|
|
|
|
box.set_constraints(icon, 5, 5)
|
|
|
|
box.add_child(icon)
|
|
|
|
|
|
|
|
icon = IconItem(icon_name='stock-zoom-activity')
|
|
|
|
icon.connect('clicked', self._level_clicked_cb, sugar.ZOOM_ACTIVITY)
|
|
|
|
box.set_constraints(icon, 5, 5)
|
2006-09-13 13:50:00 +02:00
|
|
|
box.add_child(icon)
|
2006-08-28 14:04:51 +02:00
|
|
|
|
2006-09-16 20:35:03 +02:00
|
|
|
self._box = box
|
2006-08-28 14:04:51 +02:00
|
|
|
|
2006-09-18 11:48:33 +02:00
|
|
|
shell.connect('activity-changed', self._activity_changed_cb)
|
|
|
|
self._set_current_activity(shell.get_current_activity())
|
2006-09-13 13:50:00 +02:00
|
|
|
|
2006-09-16 20:35:03 +02:00
|
|
|
def _set_current_activity(self, activity):
|
|
|
|
if self._activity_icon:
|
|
|
|
self._box.remove_child(self._activity_icon)
|
2006-09-13 13:50:00 +02:00
|
|
|
|
2006-09-16 20:35:03 +02:00
|
|
|
if activity:
|
2006-09-19 14:04:11 +02:00
|
|
|
icon = ActivityIcon(self._shell, self._menu_shell, activity)
|
2006-09-22 14:32:07 +02:00
|
|
|
self._box.set_constraints(icon, 5, 5)
|
2006-09-16 20:35:03 +02:00
|
|
|
self._box.add_child(icon)
|
|
|
|
self._activity_icon = icon
|
|
|
|
else:
|
|
|
|
self._activity_icon = None
|
2006-08-28 14:36:48 +02:00
|
|
|
|
2006-09-16 20:35:03 +02:00
|
|
|
def _activity_changed_cb(self, shell_model, activity):
|
|
|
|
self._set_current_activity(activity)
|
2006-08-28 14:04:51 +02:00
|
|
|
|
2006-09-16 20:35:03 +02:00
|
|
|
def _level_clicked_cb(self, item, level):
|
|
|
|
self._shell.set_zoom_level(level)
|