2006-08-23 11:52:18 +02:00
|
|
|
import gtk
|
|
|
|
import goocanvas
|
|
|
|
|
|
|
|
from sugar.canvas.IconItem import IconItem
|
2006-08-23 21:03:17 +02:00
|
|
|
from sugar.canvas.IconColor import IconColor
|
2006-08-23 11:52:18 +02:00
|
|
|
from sugar import conf
|
2006-09-01 15:11:52 +02:00
|
|
|
from frame.Panel import Panel
|
2006-08-25 17:24:39 +02:00
|
|
|
import logging
|
2006-08-23 11:52:18 +02:00
|
|
|
|
|
|
|
class ActivityItem(IconItem):
|
|
|
|
def __init__(self, activity, size):
|
2006-08-25 17:24:39 +02:00
|
|
|
icon_name = activity.get_icon()
|
|
|
|
if not icon_name:
|
|
|
|
act_type = activity.get_default_type()
|
2006-08-28 14:04:51 +02:00
|
|
|
raise RuntimeError("Activity %s did not have an icon!" % act_type)
|
2006-08-28 12:44:46 +02:00
|
|
|
IconItem.__init__(self, icon_name=icon_name,
|
|
|
|
color=IconColor('white'), size=size)
|
2006-08-23 11:52:18 +02:00
|
|
|
self._activity = activity
|
|
|
|
|
|
|
|
def get_activity_id(self):
|
|
|
|
return self._activity.get_id()
|
|
|
|
|
|
|
|
class ActivityBar(goocanvas.Group):
|
|
|
|
def __init__(self, shell, height):
|
|
|
|
goocanvas.Group.__init__(self)
|
|
|
|
|
|
|
|
self._shell = shell
|
|
|
|
self._height = height
|
|
|
|
|
|
|
|
registry = conf.get_activity_registry()
|
|
|
|
for activity in registry.list_activities():
|
|
|
|
if activity.get_show_launcher():
|
|
|
|
self.add_activity(activity)
|
|
|
|
|
|
|
|
def add_activity(self, activity):
|
2006-08-25 17:24:39 +02:00
|
|
|
# Need an icon to show up on the bar
|
|
|
|
if not activity.get_icon():
|
|
|
|
name = activity.get_name()
|
|
|
|
logging.info("Activity %s did not have an icon. Won't show it." % name)
|
|
|
|
return
|
|
|
|
|
2006-08-23 11:52:18 +02:00
|
|
|
item = ActivityItem(activity, self._height)
|
|
|
|
|
|
|
|
icon_size = self._height
|
|
|
|
x = (icon_size + 6) * self.get_n_children()
|
|
|
|
item.set_property('x', x)
|
|
|
|
|
|
|
|
self.add_child(item)
|
|
|
|
|
2006-09-01 15:11:52 +02:00
|
|
|
class BottomPanel(Panel):
|
2006-08-23 11:52:18 +02:00
|
|
|
def __init__(self, shell):
|
|
|
|
Panel.__init__(self)
|
|
|
|
|
|
|
|
self._shell = shell
|
|
|
|
|
|
|
|
view = self.get_view()
|
|
|
|
view.connect("item_view_created", self.__item_view_created_cb)
|
|
|
|
|
|
|
|
def construct(self):
|
|
|
|
Panel.construct(self)
|
|
|
|
|
2006-08-28 16:53:29 +02:00
|
|
|
root = self.get_root()
|
2006-08-23 11:52:18 +02:00
|
|
|
|
|
|
|
activity_bar = ActivityBar(self._shell, self.get_height())
|
|
|
|
root.add_child(activity_bar)
|
|
|
|
|
|
|
|
def __item_view_created_cb(self, view, item_view, item):
|
|
|
|
if isinstance(item, ActivityItem):
|
|
|
|
item_view.connect("button_press_event",
|
|
|
|
self.__activity_button_press_cb,
|
|
|
|
item.get_activity_id())
|
|
|
|
|
|
|
|
def __activity_button_press_cb(self, view, target, event, activity_id):
|
|
|
|
self._shell.start_activity(activity_id)
|