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-12-24 15:39:00 +01:00
|
|
|
import logging
|
2007-02-20 16:38:25 +01:00
|
|
|
from gettext import gettext as _
|
2006-12-24 15:39:00 +01:00
|
|
|
|
2006-10-02 01:50:43 +02:00
|
|
|
import hippo
|
2006-08-28 14:04:51 +02:00
|
|
|
|
2007-02-21 17:05:41 +01:00
|
|
|
from sugar.graphics.menu import Menu, MenuItem
|
2007-02-27 22:35:28 +01:00
|
|
|
from sugar.graphics import color
|
2007-02-21 13:01:20 +01:00
|
|
|
from sugar.graphics.iconbutton import IconButton
|
2006-08-28 14:36:48 +02:00
|
|
|
import sugar
|
2006-08-28 14:04:51 +02:00
|
|
|
|
2007-02-21 17:05:41 +01:00
|
|
|
class ActivityMenu(Menu):
|
2006-12-04 20:12:24 +01:00
|
|
|
ACTION_SHARE = 1
|
|
|
|
ACTION_CLOSE = 2
|
2006-09-16 20:35:03 +02:00
|
|
|
|
2006-12-24 14:35:02 +01:00
|
|
|
def __init__(self, activity_model):
|
2007-02-21 17:05:41 +01:00
|
|
|
Menu.__init__(self, activity_model.get_title())
|
2006-09-16 20:35:03 +02:00
|
|
|
|
2007-03-16 15:00:16 +01:00
|
|
|
# FIXME: re-enable after trial1
|
|
|
|
# if not activity_model.get_shared():
|
|
|
|
# self.add_item(MenuItem(ActivityMenu.ACTION_SHARE,
|
|
|
|
# _('Share'),
|
|
|
|
# 'theme:stock-share-mesh'))
|
2006-10-19 15:44:00 +02:00
|
|
|
|
2007-02-21 17:05:41 +01:00
|
|
|
self.add_item(MenuItem(ActivityMenu.ACTION_CLOSE,
|
|
|
|
_('Close'),
|
|
|
|
'theme:stock-close'))
|
2006-10-19 15:44:00 +02:00
|
|
|
|
2007-02-21 13:01:20 +01:00
|
|
|
class ActivityButton(IconButton):
|
2007-02-21 21:12:27 +01:00
|
|
|
def __init__(self, shell, activity_model, popup_context):
|
2006-12-04 20:12:24 +01:00
|
|
|
self._shell = shell
|
2006-12-24 15:39:00 +01:00
|
|
|
self._activity_model = activity_model
|
2007-02-21 21:12:27 +01:00
|
|
|
self._popup_context = popup_context
|
2006-09-16 20:35:03 +02:00
|
|
|
|
2006-12-24 14:35:02 +01:00
|
|
|
icon_name = self._activity_model.get_icon_name()
|
|
|
|
icon_color = self._activity_model.get_icon_color()
|
2006-09-16 20:35:03 +02:00
|
|
|
|
2007-02-23 17:08:37 +01:00
|
|
|
IconButton.__init__(self, icon_name=icon_name, xo_color=icon_color)
|
2007-02-20 16:38:25 +01:00
|
|
|
|
2007-02-21 10:16:03 +01:00
|
|
|
def get_popup(self):
|
2007-02-21 17:05:41 +01:00
|
|
|
menu = ActivityMenu(self._activity_model)
|
|
|
|
menu.connect('action', self._action_cb)
|
|
|
|
return menu
|
2007-02-20 16:38:25 +01:00
|
|
|
|
2007-02-21 10:16:03 +01:00
|
|
|
def get_popup_context(self):
|
2007-02-21 21:12:27 +01:00
|
|
|
return self._popup_context
|
2007-02-20 16:38:25 +01:00
|
|
|
|
2007-02-21 17:05:41 +01:00
|
|
|
def _action_cb(self, menu, menu_item):
|
2007-02-20 16:38:25 +01:00
|
|
|
# TODO: Wouldn't be better to share/close the activity associated with
|
|
|
|
# this button instead of asking for the current activity?
|
2006-12-24 15:39:00 +01:00
|
|
|
activity = self._shell.get_current_activity()
|
|
|
|
if activity == None:
|
|
|
|
logging.error('No active activity.')
|
|
|
|
return
|
|
|
|
|
2007-02-21 17:05:41 +01:00
|
|
|
if menu_item.props.action_id == ActivityMenu.ACTION_SHARE:
|
2006-12-24 15:39:00 +01:00
|
|
|
activity.share()
|
2007-02-21 17:05:41 +01:00
|
|
|
elif menu_item.props.action_id == ActivityMenu.ACTION_CLOSE:
|
2006-12-24 15:39:00 +01:00
|
|
|
activity.close()
|
2006-09-16 20:35:03 +02:00
|
|
|
|
2006-10-02 01:50:43 +02:00
|
|
|
class ZoomBox(hippo.CanvasBox):
|
2007-02-21 21:12:27 +01:00
|
|
|
def __init__(self, shell, popup_context):
|
2006-12-04 20:12:24 +01:00
|
|
|
hippo.CanvasBox.__init__(self, orientation=hippo.ORIENTATION_HORIZONTAL)
|
|
|
|
|
|
|
|
self._shell = shell
|
2007-02-21 21:12:27 +01:00
|
|
|
self._popup_context = popup_context
|
2006-12-04 20:12:24 +01:00
|
|
|
self._activity_icon = None
|
|
|
|
|
2007-02-27 22:35:28 +01:00
|
|
|
icon = IconButton(icon_name='theme:stock-zoom-mesh',
|
|
|
|
stroke_color=color.BLACK,
|
|
|
|
fill_color=color.WHITE)
|
2006-12-04 20:12:24 +01:00
|
|
|
icon.connect('activated', self._level_clicked_cb, sugar.ZOOM_MESH)
|
|
|
|
self.append(icon)
|
|
|
|
|
2007-02-27 22:35:28 +01:00
|
|
|
icon = IconButton(icon_name='theme:stock-zoom-friends',
|
|
|
|
stroke_color=color.BLACK,
|
|
|
|
fill_color=color.WHITE)
|
2006-12-04 20:12:24 +01:00
|
|
|
icon.connect('activated', self._level_clicked_cb, sugar.ZOOM_FRIENDS)
|
|
|
|
self.append(icon)
|
|
|
|
|
2007-02-27 22:35:28 +01:00
|
|
|
icon = IconButton(icon_name='theme:stock-zoom-home',
|
|
|
|
stroke_color=color.BLACK,
|
|
|
|
fill_color=color.WHITE)
|
2006-12-04 20:12:24 +01:00
|
|
|
icon.connect('activated', self._level_clicked_cb, sugar.ZOOM_HOME)
|
|
|
|
self.append(icon)
|
|
|
|
|
2007-02-27 22:35:28 +01:00
|
|
|
icon = IconButton(icon_name='theme:stock-zoom-activity',
|
|
|
|
stroke_color=color.BLACK,
|
|
|
|
fill_color=color.WHITE)
|
2006-12-04 20:12:24 +01:00
|
|
|
icon.connect('activated', self._level_clicked_cb, sugar.ZOOM_ACTIVITY)
|
|
|
|
self.append(icon)
|
|
|
|
|
2006-12-24 15:39:00 +01:00
|
|
|
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())
|
2006-12-04 20:12:24 +01:00
|
|
|
|
2006-12-24 15:39:00 +01:00
|
|
|
def _set_current_activity(self, home_activity):
|
2006-12-04 20:12:24 +01:00
|
|
|
if self._activity_icon:
|
|
|
|
self.remove(self._activity_icon)
|
|
|
|
|
2006-12-24 15:39:00 +01:00
|
|
|
if home_activity:
|
2007-02-21 21:12:27 +01:00
|
|
|
icon = ActivityButton(self._shell, home_activity, self._popup_context)
|
2007-01-25 17:37:27 +01:00
|
|
|
self.append(icon)
|
2006-12-04 20:12:24 +01:00
|
|
|
self._activity_icon = icon
|
|
|
|
else:
|
|
|
|
self._activity_icon = None
|
|
|
|
|
2006-12-24 15:39:00 +01:00
|
|
|
def _activity_changed_cb(self, home_model, home_activity):
|
|
|
|
self._set_current_activity(home_activity)
|
2006-12-04 20:12:24 +01:00
|
|
|
|
|
|
|
def _level_clicked_cb(self, item, level):
|
|
|
|
self._shell.set_zoom_level(level)
|