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-23 21:03:17 +02:00
|
|
|
from sugar.canvas.IconColor import IconColor
|
2006-08-26 11:47:02 +02:00
|
|
|
from home.DonutItem import DonutItem
|
|
|
|
from home.DonutItem import PieceItem
|
|
|
|
from home.DonutItem import PieceIcon
|
2006-08-25 00:49:39 +02:00
|
|
|
import sugar.conf
|
2006-08-17 11:47:41 +02:00
|
|
|
|
2006-08-23 14:13:15 +02:00
|
|
|
import Theme
|
2006-08-23 13:09:10 +02:00
|
|
|
|
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()
|
2006-08-26 14:17:55 +02:00
|
|
|
icon_color = activity.get_icon_color()
|
|
|
|
item = self.add_piece(100 / 8, icon_name, icon_color)
|
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-16 22:01:43 +02:00
|
|
|
class Background(goocanvas.Group):
|
|
|
|
def __init__(self):
|
|
|
|
goocanvas.Group.__init__(self)
|
2006-08-23 14:13:15 +02:00
|
|
|
self._theme = Theme.get_instance()
|
2006-08-23 13:09:10 +02:00
|
|
|
self._theme.connect("theme-changed", self.__theme_changed_cb)
|
2006-08-16 22:01:43 +02:00
|
|
|
|
2006-08-23 16:41:12 +02:00
|
|
|
color = self._theme.get_home_friends_color()
|
2006-08-23 14:06:45 +02:00
|
|
|
self._friends_rect = goocanvas.Rect(width=1200, height=900,
|
2006-08-23 13:09:10 +02:00
|
|
|
fill_color=color)
|
2006-08-23 14:06:45 +02:00
|
|
|
self.add_child(self._friends_rect)
|
2006-08-23 13:09:10 +02:00
|
|
|
|
2006-08-23 16:41:12 +02:00
|
|
|
color = self._theme.get_home_activities_color()
|
2006-08-23 14:06:45 +02:00
|
|
|
self._home_rect = goocanvas.Rect(x=100, y=100, width=1000, height=700,
|
2006-08-23 13:09:10 +02:00
|
|
|
line_width=0, fill_color=color,
|
|
|
|
radius_x=30, radius_y=30)
|
2006-08-23 14:06:45 +02:00
|
|
|
self.add_child(self._home_rect)
|
2006-08-16 22:01:43 +02:00
|
|
|
|
|
|
|
item = goocanvas.Text(text="My Activities",
|
2006-08-23 11:52:18 +02:00
|
|
|
x=12, y=12, fill_color="black",
|
2006-08-16 22:01:43 +02:00
|
|
|
font="Sans 21")
|
|
|
|
self.add_child(item)
|
|
|
|
|
2006-08-23 16:41:12 +02:00
|
|
|
def __theme_changed_cb(self, theme):
|
|
|
|
color = self._theme.get_home_activities_color()
|
2006-08-23 14:06:45 +02:00
|
|
|
self._home_rect.set_property("fill-color", color)
|
2006-08-23 16:41:12 +02:00
|
|
|
color = self._theme.get_friends_colors()
|
2006-08-23 14:06:45 +02:00
|
|
|
self._friends_rect.set_property("fill-color", color)
|
2006-08-23 13:09:10 +02:00
|
|
|
|
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 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-25 00:49:39 +02:00
|
|
|
profile = sugar.conf.get_profile()
|
2006-08-28 12:44:46 +02:00
|
|
|
me = IconItem(icon_name = 'stock-buddy',
|
|
|
|
color = profile.get_color(), size = 150)
|
2006-08-19 13:39:13 +02:00
|
|
|
me.translate(600 - (me.get_property('width') / 2),
|
|
|
|
450 - (me.get_property('height') / 2))
|
|
|
|
root.add_child(me)
|
|
|
|
|
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):
|
2006-08-23 11:52:18 +02:00
|
|
|
if 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()
|