2006-10-15 01:24:45 +02:00
|
|
|
# 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
|
|
|
|
|
2006-10-02 01:50:43 +02:00
|
|
|
import hippo
|
2006-08-28 14:04:51 +02:00
|
|
|
|
2006-10-02 01:50:43 +02:00
|
|
|
from sugar.graphics.canvasicon import CanvasIcon
|
|
|
|
from sugar.graphics.menuicon import MenuIcon
|
2006-10-02 16:37:30 +02:00
|
|
|
from sugar.graphics.menu import Menu
|
2006-10-02 01:50:43 +02:00
|
|
|
from sugar.graphics import style
|
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
|
|
|
|
2006-10-04 00:25:03 +02:00
|
|
|
def __init__(self, activity_host):
|
2006-10-02 16:37:30 +02:00
|
|
|
Menu.__init__(self, activity_host.get_title())
|
2006-09-16 20:35:03 +02:00
|
|
|
|
2006-10-19 15:44:00 +02:00
|
|
|
if not activity_host.get_shared():
|
|
|
|
self._add_mesh_action()
|
|
|
|
|
|
|
|
self._add_close_action()
|
|
|
|
|
|
|
|
def _add_mesh_action(self):
|
2006-10-02 16:37:30 +02:00
|
|
|
icon = CanvasIcon(icon_name='stock-share-mesh')
|
2006-09-16 20:35:03 +02:00
|
|
|
self.add_action(icon, ActivityMenu.ACTION_SHARE)
|
|
|
|
|
2006-10-19 15:44:00 +02:00
|
|
|
def _add_close_action(self):
|
2006-10-02 16:37:30 +02:00
|
|
|
icon = CanvasIcon(icon_name='stock-close')
|
2006-09-18 11:56:53 +02:00
|
|
|
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)
|
|
|
|
|
|
|
|
def create_menu(self):
|
2006-10-04 00:25:03 +02:00
|
|
|
menu = ActivityMenu(self._activity_host)
|
2006-09-16 20:35:03 +02:00
|
|
|
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-10-02 01:50:43 +02:00
|
|
|
class ZoomBox(hippo.CanvasBox):
|
2006-09-19 14:04:11 +02:00
|
|
|
def __init__(self, shell, menu_shell):
|
2006-10-02 01:50:43 +02:00
|
|
|
hippo.CanvasBox.__init__(self, orientation=hippo.ORIENTATION_HORIZONTAL)
|
2006-09-13 13:50:00 +02:00
|
|
|
|
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-10-02 01:50:43 +02:00
|
|
|
icon = CanvasIcon(icon_name='stock-zoom-mesh')
|
2006-10-05 13:26:02 +02:00
|
|
|
style.apply_stylesheet(icon, 'frame.ZoomIcon')
|
2006-10-02 01:50:43 +02:00
|
|
|
icon.connect('activated', self._level_clicked_cb, sugar.ZOOM_MESH)
|
2006-10-02 16:37:30 +02:00
|
|
|
self.append(icon)
|
2006-08-28 14:04:51 +02:00
|
|
|
|
2006-10-02 01:50:43 +02:00
|
|
|
icon = CanvasIcon(icon_name='stock-zoom-friends')
|
2006-10-05 13:26:02 +02:00
|
|
|
style.apply_stylesheet(icon, 'frame.ZoomIcon')
|
2006-10-02 01:50:43 +02:00
|
|
|
icon.connect('activated', self._level_clicked_cb, sugar.ZOOM_FRIENDS)
|
2006-10-02 16:37:30 +02:00
|
|
|
self.append(icon)
|
2006-09-22 10:55:10 +02:00
|
|
|
|
2006-10-02 01:50:43 +02:00
|
|
|
icon = CanvasIcon(icon_name='stock-zoom-home')
|
2006-10-05 13:26:02 +02:00
|
|
|
style.apply_stylesheet(icon, 'frame.ZoomIcon')
|
2006-10-02 01:50:43 +02:00
|
|
|
icon.connect('activated', self._level_clicked_cb, sugar.ZOOM_HOME)
|
2006-10-02 16:37:30 +02:00
|
|
|
self.append(icon)
|
2006-08-28 14:04:51 +02:00
|
|
|
|
2006-10-02 01:50:43 +02:00
|
|
|
icon = CanvasIcon(icon_name='stock-zoom-activity')
|
2006-10-05 13:26:02 +02:00
|
|
|
style.apply_stylesheet(icon, 'frame.ZoomIcon')
|
2006-10-02 01:50:43 +02:00
|
|
|
icon.connect('activated', self._level_clicked_cb, sugar.ZOOM_ACTIVITY)
|
2006-10-02 16:37:30 +02:00
|
|
|
self.append(icon)
|
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:
|
2006-10-02 01:50:43 +02:00
|
|
|
self.remove(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-10-05 13:26:02 +02:00
|
|
|
style.apply_stylesheet(icon, 'frame.ZoomIcon')
|
2006-10-02 01:50:43 +02:00
|
|
|
self.append(icon, 0)
|
2006-09-16 20:35:03 +02:00
|
|
|
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)
|