2006-07-08 11:56:13 +02:00
|
|
|
import gtk
|
2006-08-15 12:20:09 +02:00
|
|
|
import goocanvas
|
2006-08-17 12:09:45 +02:00
|
|
|
import wnck
|
2006-07-14 15:47:42 +02:00
|
|
|
|
2006-08-16 19:55:13 +02:00
|
|
|
from sugar.canvas.IconItem import IconItem
|
2006-08-17 11:47:41 +02:00
|
|
|
from sugar.canvas.DonutItem import DonutItem
|
2006-08-17 13:16:48 +02:00
|
|
|
from sugar.canvas.DonutItem import PieceItem
|
2006-08-17 14:42:29 +02:00
|
|
|
from sugar.canvas.DonutItem import PieceIcon
|
2006-08-17 11:47:41 +02:00
|
|
|
|
|
|
|
class TasksItem(DonutItem):
|
2006-08-17 14:23:52 +02:00
|
|
|
def __init__(self, shell):
|
2006-08-17 13:16:48 +02:00
|
|
|
DonutItem.__init__(self, 250)
|
2006-08-17 12:09:45 +02:00
|
|
|
|
|
|
|
self._items = {}
|
|
|
|
|
2006-08-17 14:23:52 +02:00
|
|
|
shell.connect('activity_opened', self.__activity_opened_cb)
|
|
|
|
shell.connect('activity_closed', self.__activity_closed_cb)
|
2006-08-17 12:09:45 +02:00
|
|
|
|
2006-08-17 14:23:52 +02:00
|
|
|
def __activity_opened_cb(self, shell, activity):
|
|
|
|
self._add(activity)
|
2006-08-17 12:09:45 +02:00
|
|
|
|
2006-08-17 14:23:52 +02:00
|
|
|
def __activity_closed_cb(self, shell, activity):
|
|
|
|
self._remove(activity)
|
2006-08-17 12:09:45 +02:00
|
|
|
|
2006-08-17 14:23:52 +02:00
|
|
|
def _remove(self, activity):
|
|
|
|
item = self._items[activity.get_id()]
|
2006-08-17 14:42:29 +02:00
|
|
|
self.remove_piece(item)
|
2006-08-17 14:23:52 +02:00
|
|
|
del self._items[activity.get_id()]
|
2006-08-17 12:09:45 +02:00
|
|
|
|
2006-08-17 14:23:52 +02:00
|
|
|
def _add(self, activity):
|
|
|
|
icon_name = activity.get_icon_name()
|
|
|
|
item = self.add_piece(100 / 8, icon_name, 'blue')
|
2006-08-17 14:42:29 +02:00
|
|
|
|
|
|
|
# FIXME This really sucks. Fix goocanvas event handling.
|
2006-08-17 14:23:52 +02:00
|
|
|
item.set_data('activity', activity)
|
2006-08-17 14:42:29 +02:00
|
|
|
item.get_icon().set_data('activity', activity)
|
|
|
|
|
2006-08-17 14:23:52 +02:00
|
|
|
self._items[activity.get_id()] = item
|
2006-08-16 19:55:13 +02:00
|
|
|
|
2006-08-17 10:32:59 +02:00
|
|
|
class ActivityItem(IconItem):
|
|
|
|
def __init__(self, activity):
|
|
|
|
IconItem.__init__(self, activity.get_icon(), 'white', 30)
|
|
|
|
self._activity = activity
|
|
|
|
|
|
|
|
def get_activity_id(self):
|
|
|
|
return self._activity.get_id()
|
|
|
|
|
2006-08-16 23:20:22 +02:00
|
|
|
class ActivityBar(goocanvas.Group):
|
2006-08-17 10:32:59 +02:00
|
|
|
def __init__(self, shell):
|
2006-08-16 23:20:22 +02:00
|
|
|
goocanvas.Group.__init__(self)
|
|
|
|
|
2006-08-17 10:32:59 +02:00
|
|
|
self._shell = shell
|
|
|
|
|
|
|
|
registry = shell.get_registry()
|
2006-08-16 23:20:22 +02:00
|
|
|
for activity in registry.list_activities():
|
|
|
|
if activity.get_show_launcher():
|
|
|
|
self.add_activity(activity)
|
|
|
|
|
|
|
|
def add_activity(self, activity):
|
2006-08-17 10:32:59 +02:00
|
|
|
item = ActivityItem(activity)
|
2006-08-16 23:20:22 +02:00
|
|
|
self.add_child(item)
|
|
|
|
|
2006-08-16 22:01:43 +02:00
|
|
|
class Background(goocanvas.Group):
|
|
|
|
def __init__(self):
|
|
|
|
goocanvas.Group.__init__(self)
|
|
|
|
|
|
|
|
item = goocanvas.Rect(width=1200, height=900,
|
|
|
|
fill_color="#4f4f4f")
|
|
|
|
self.add_child(item)
|
|
|
|
|
|
|
|
item = goocanvas.Rect(x=50, y=50, width=1100, height=800,
|
|
|
|
line_width=0, fill_color="#d8d8d8",
|
|
|
|
radius_x=30, radius_y=30)
|
|
|
|
self.add_child(item)
|
|
|
|
|
|
|
|
item = goocanvas.Text(text="My Activities",
|
|
|
|
x=60, y=10, fill_color="white",
|
|
|
|
font="Sans 21")
|
|
|
|
self.add_child(item)
|
|
|
|
|
2006-08-15 12:20:09 +02:00
|
|
|
class Model(goocanvas.CanvasModelSimple):
|
2006-08-16 23:20:22 +02:00
|
|
|
def __init__(self, shell):
|
2006-08-15 12:20:09 +02:00
|
|
|
goocanvas.CanvasModelSimple.__init__(self)
|
2006-07-14 15:47:42 +02:00
|
|
|
|
2006-08-15 12:20:09 +02:00
|
|
|
root = self.get_root_item()
|
2006-07-10 13:42:34 +02:00
|
|
|
|
2006-08-16 22:01:43 +02:00
|
|
|
background = Background()
|
|
|
|
root.add_child(background)
|
2006-07-10 13:42:34 +02:00
|
|
|
|
2006-08-17 10:32:59 +02:00
|
|
|
activity_bar = ActivityBar(shell)
|
|
|
|
activity_bar.translate(50, 860)
|
2006-08-16 23:20:22 +02:00
|
|
|
root.add_child(activity_bar)
|
|
|
|
|
2006-08-17 14:23:52 +02:00
|
|
|
tasks = TasksItem(shell)
|
2006-08-17 11:47:41 +02:00
|
|
|
tasks.translate(600, 450)
|
|
|
|
root.add_child(tasks)
|
|
|
|
|
2006-08-19 01:29:42 +02:00
|
|
|
class HomeView(goocanvas.CanvasView):
|
2006-07-08 15:47:51 +02:00
|
|
|
def __init__(self, shell):
|
2006-08-19 01:29:42 +02:00
|
|
|
goocanvas.CanvasView.__init__(self)
|
2006-07-10 13:42:34 +02:00
|
|
|
self._shell = shell
|
2006-07-13 11:10:27 +02:00
|
|
|
|
2006-08-19 01:29:42 +02:00
|
|
|
self.connect("item_view_created", self.__item_view_created_cb)
|
2006-08-17 10:32:59 +02:00
|
|
|
|
2006-08-16 23:20:22 +02:00
|
|
|
canvas_model = Model(shell)
|
2006-08-19 01:29:42 +02:00
|
|
|
self.set_model(canvas_model)
|
2006-07-10 13:42:34 +02:00
|
|
|
|
2006-08-17 10:32:59 +02:00
|
|
|
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())
|
2006-08-17 14:42:29 +02:00
|
|
|
elif isinstance(item, PieceItem) or \
|
|
|
|
isinstance(item, PieceIcon):
|
2006-08-17 13:16:48 +02:00
|
|
|
item_view.connect("button_press_event",
|
|
|
|
self.__task_button_press_cb)
|
2006-08-17 10:32:59 +02:00
|
|
|
|
|
|
|
def __activity_button_press_cb(self, view, target, event, activity_id):
|
|
|
|
self._shell.start_activity(activity_id)
|
|
|
|
|
2006-08-17 13:16:48 +02:00
|
|
|
def __task_button_press_cb(self, view, target, event):
|
2006-08-17 14:23:52 +02:00
|
|
|
activity = view.get_item().get_data('activity')
|
|
|
|
activity.present()
|