1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
|
# Copyright (C) 2006, Red Hat, Inc.
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# This program 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 General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
import logging
import hippo
from sugar.graphics.canvasicon import CanvasIcon
from sugar.graphics.menuicon import MenuIcon
from sugar.graphics.menu import Menu
from sugar.graphics import style
import sugar
class ActivityMenu(Menu):
ACTION_SHARE = 1
ACTION_CLOSE = 2
def __init__(self, activity_model):
Menu.__init__(self, activity_model.get_title())
if not activity_model.get_shared():
self._add_mesh_action()
self._add_close_action()
def _add_mesh_action(self):
icon = CanvasIcon(icon_name='stock-share-mesh')
self.add_action(icon, ActivityMenu.ACTION_SHARE)
def _add_close_action(self):
icon = CanvasIcon(icon_name='stock-close')
self.add_action(icon, ActivityMenu.ACTION_CLOSE)
class ActivityIcon(MenuIcon):
def __init__(self, shell, menu_shell, activity_model):
self._shell = shell
self._activity_model = activity_model
icon_name = self._activity_model.get_icon_name()
icon_color = self._activity_model.get_icon_color()
MenuIcon.__init__(self, menu_shell, icon_name=icon_name,
color=icon_color)
def create_menu(self):
menu = ActivityMenu(self._activity_model)
menu.connect('action', self._action_cb)
return menu
def _action_cb(self, menu, action):
self.popdown()
activity = self._shell.get_current_activity()
if activity == None:
logging.error('No active activity.')
return
if action == ActivityMenu.ACTION_SHARE:
activity.share()
if action == ActivityMenu.ACTION_CLOSE:
activity.close()
class ZoomBox(hippo.CanvasBox):
def __init__(self, shell, menu_shell):
hippo.CanvasBox.__init__(self, orientation=hippo.ORIENTATION_HORIZONTAL)
self._shell = shell
self._menu_shell = menu_shell
self._activity_icon = None
icon = CanvasIcon(icon_name='stock-zoom-mesh')
style.apply_stylesheet(icon, 'frame.ZoomIcon')
icon.connect('activated', self._level_clicked_cb, sugar.ZOOM_MESH)
self.append(icon)
icon = CanvasIcon(icon_name='stock-zoom-friends')
style.apply_stylesheet(icon, 'frame.ZoomIcon')
icon.connect('activated', self._level_clicked_cb, sugar.ZOOM_FRIENDS)
self.append(icon)
icon = CanvasIcon(icon_name='stock-zoom-home')
style.apply_stylesheet(icon, 'frame.ZoomIcon')
icon.connect('activated', self._level_clicked_cb, sugar.ZOOM_HOME)
self.append(icon)
icon = CanvasIcon(icon_name='stock-zoom-activity')
style.apply_stylesheet(icon, 'frame.ZoomIcon')
icon.connect('activated', self._level_clicked_cb, sugar.ZOOM_ACTIVITY)
self.append(icon)
home_model = shell.get_model().get_home()
home_model.connect('active-activity-changed',
self._activity_changed_cb)
self._set_current_activity(home_model.get_current_activity())
def _set_current_activity(self, home_activity):
if self._activity_icon:
self.remove(self._activity_icon)
if home_activity:
icon = ActivityIcon(self._shell, self._menu_shell, home_activity)
style.apply_stylesheet(icon, 'frame.ZoomIcon')
self.append(icon, 0)
self._activity_icon = icon
else:
self._activity_icon = None
def _activity_changed_cb(self, home_model, home_activity):
self._set_current_activity(home_activity)
def _level_clicked_cb(self, item, level):
self._shell.set_zoom_level(level)
|