Initial implementation of the activity menu

This commit is contained in:
Marco Pesenti Gritti 2006-09-16 20:35:03 +02:00
parent d9fc47ca01
commit 465253d95e
4 changed files with 63 additions and 35 deletions

View File

@ -31,6 +31,9 @@ class ActivityHost:
def get_id(self):
return self._id
def get_title(self):
return self._window.get_name()
def get_xid(self):
return self._xid

View File

@ -3,8 +3,7 @@ from view.BuddyMenu import BuddyMenu
class BuddyIcon(MenuIcon):
def __init__(self, shell, friend):
MenuIcon.__init__(self, shell.get_grid(),
icon_name='stock-buddy',
MenuIcon.__init__(self, shell.get_grid(), icon_name='stock-buddy',
color=friend.get_color(), size=96)
self._shell = shell

View File

@ -53,7 +53,7 @@ class Shell(gobject.GObject):
elif key == 'F5':
self._frame.toggle_visibility()
elif key == 'F6':
self._model.start_activity('org.sugar.Terminal')
self.start_activity('org.sugar.Terminal')
def __window_opened_cb(self, screen, window):
if window.get_window_type() == wnck.WINDOW_NORMAL:

View File

@ -2,13 +2,49 @@ import goocanvas
from sugar.canvas.CanvasBox import CanvasBox
from sugar.canvas.IconItem import IconItem
from sugar.canvas.MenuIcon import MenuIcon
from sugar.canvas.Menu import Menu
import sugar
class ActivityMenu(Menu):
ACTION_SHARE = 1
def __init__(self, grid, activity_host):
title = activity_host.get_title()
Menu.__init__(self, grid, title, 'black', 'black')
icon = IconItem(icon_name='stock-share')
self.add_action(icon, ActivityMenu.ACTION_SHARE)
class ActivityIcon(MenuIcon):
def __init__(self, shell, activity_host):
self._shell = shell
self._activity_host = activity_host
icon_name = activity_host.get_icon_name()
icon_color = activity_host.get_icon_color()
MenuIcon.__init__(self, shell.get_grid(), icon_name=icon_name,
color=icon_color)
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):
if action == ActivityMenu.ACTION_SHARE:
shell_model = self._shell.get_model()
activity = shell_model.get_current_activity()
if activity != None:
activity.share()
class TopPanel(goocanvas.Group):
def __init__(self, shell):
goocanvas.Group.__init__(self)
self._shell = shell
self._activity_icon = None
grid = shell.get_grid()
@ -17,55 +53,45 @@ class TopPanel(goocanvas.Group):
self.add_child(box)
icon = IconItem(icon_name='stock-zoom-activity')
icon.connect('clicked', self.__level_clicked_cb, sugar.ZOOM_ACTIVITY)
icon.connect('clicked', self._level_clicked_cb, sugar.ZOOM_ACTIVITY)
box.set_constraints(icon, 3, 3)
box.add_child(icon)
icon = IconItem(icon_name='stock-zoom-home')
icon.connect('clicked', self.__level_clicked_cb, sugar.ZOOM_HOME)
icon.connect('clicked', self._level_clicked_cb, sugar.ZOOM_HOME)
box.set_constraints(icon, 3, 3)
box.add_child(icon)
icon = IconItem(icon_name='stock-zoom-friends')
icon.connect('clicked', self.__level_clicked_cb, sugar.ZOOM_FRIENDS)
icon.connect('clicked', self._level_clicked_cb, sugar.ZOOM_FRIENDS)
box.set_constraints(icon, 3, 3)
box.add_child(icon)
icon = IconItem(icon_name='stock-zoom-mesh')
icon.connect('clicked', self.__level_clicked_cb, sugar.ZOOM_MESH)
icon.connect('clicked', self._level_clicked_cb, sugar.ZOOM_MESH)
box.set_constraints(icon, 3, 3)
box.add_child(icon)
box = CanvasBox(grid, CanvasBox.HORIZONTAL, 1)
grid.set_constraints(box, 60, 0)
self.add_child(box)
self._box = box
icon = IconItem(icon_name='stock-share')
icon.connect('clicked', self.__share_clicked_cb)
box.set_constraints(icon, 3, 3)
box.add_child(icon)
shell_model = shell.get_model()
shell_model.connect('activity-changed', self._activity_changed_cb)
self._set_current_activity(shell_model.get_current_activity())
icon = IconItem(icon_name='stock-invite')
icon.connect('clicked', self.__invite_clicked_cb)
box.set_constraints(icon, 3, 3)
box.add_child(icon)
def _set_current_activity(self, activity):
if self._activity_icon:
self._box.remove_child(self._activity_icon)
icon = IconItem(icon_name='stock-chat')
icon.connect('clicked', self.__chat_clicked_cb)
box.set_constraints(icon, 3, 3)
box.add_child(icon)
if activity:
icon = ActivityIcon(self._shell, activity)
self._box.set_constraints(icon, 3, 3)
self._box.add_child(icon)
self._activity_icon = icon
else:
self._activity_icon = None
def __level_clicked_cb(self, item, level):
def _activity_changed_cb(self, shell_model, activity):
self._set_current_activity(activity)
def _level_clicked_cb(self, item, level):
self._shell.set_zoom_level(level)
def __share_clicked_cb(self, item):
shell_model = self._shell.get_model()
activity = shell_model.get_current_activity()
if activity != None:
activity.share()
def __invite_clicked_cb(self, item):
pass
def __chat_clicked_cb(self, item):
pass