2006-08-19 11:12:25 +02:00
|
|
|
import random
|
|
|
|
|
2006-08-19 02:00:04 +02:00
|
|
|
import goocanvas
|
|
|
|
|
2006-08-19 11:12:25 +02:00
|
|
|
from sugar.canvas.IconItem import IconItem
|
2006-08-19 14:27:56 +02:00
|
|
|
from sugar.canvas.IconItem import IconColor
|
2006-08-19 11:12:25 +02:00
|
|
|
|
2006-08-23 14:13:15 +02:00
|
|
|
import Theme
|
2006-08-23 14:06:45 +02:00
|
|
|
|
2006-08-19 02:00:04 +02:00
|
|
|
class Model(goocanvas.CanvasModelSimple):
|
2006-08-19 11:12:25 +02:00
|
|
|
def __init__(self, data_model):
|
2006-08-19 02:00:04 +02:00
|
|
|
goocanvas.CanvasModelSimple.__init__(self)
|
2006-08-23 14:13:15 +02:00
|
|
|
self._theme = Theme.get_instance()
|
2006-08-23 14:06:45 +02:00
|
|
|
self._theme.connect("theme-changed", self.__theme_changed_cb)
|
2006-08-19 02:00:04 +02:00
|
|
|
|
|
|
|
root = self.get_root_item()
|
|
|
|
|
2006-08-23 16:41:12 +02:00
|
|
|
color = self._theme.get_home_mesh_color()
|
2006-08-23 14:06:45 +02:00
|
|
|
self._mesh_rect = goocanvas.Rect(width=1200, height=900,
|
|
|
|
fill_color=color)
|
|
|
|
root.add_child(self._mesh_rect)
|
|
|
|
|
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(x=100, y=100, width=1000, height=700,
|
|
|
|
line_width=0, fill_color=color,
|
|
|
|
radius_x=30, radius_y=30)
|
|
|
|
root.add_child(self._friends_rect)
|
|
|
|
|
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=400, y=300, width=400, height=300,
|
|
|
|
line_width=0, fill_color=color,
|
|
|
|
radius_x=30, radius_y=30)
|
|
|
|
root.add_child(self._home_rect)
|
2006-08-19 11:12:25 +02:00
|
|
|
|
|
|
|
for friend in data_model:
|
|
|
|
self.add_friend(friend)
|
|
|
|
|
|
|
|
data_model.connect('friend-added', self.__friend_added_cb)
|
|
|
|
|
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_home_friends_color()
|
2006-08-23 14:06:45 +02:00
|
|
|
self._friends_rect.set_property("fill-color", color)
|
2006-08-23 16:41:12 +02:00
|
|
|
color = self._theme.get_home_mesh_color()
|
2006-08-23 14:06:45 +02:00
|
|
|
self._mesh_rect.set_property("fill-color", color)
|
|
|
|
|
2006-08-19 11:12:25 +02:00
|
|
|
def add_friend(self, friend):
|
|
|
|
root = self.get_root_item()
|
|
|
|
|
2006-08-19 14:27:56 +02:00
|
|
|
icon = IconItem('stock-buddy', IconColor(), 48)
|
2006-08-19 11:12:25 +02:00
|
|
|
icon.set_property('x', random.random() * 1100)
|
|
|
|
icon.set_property('y', random.random() * 800)
|
|
|
|
|
|
|
|
root.add_child(icon)
|
|
|
|
|
|
|
|
def __friend_added_cb(self, data_model, friend):
|
|
|
|
self.add_friend(friend)
|
|
|
|
|
2006-08-19 02:00:04 +02:00
|
|
|
class FriendsView(goocanvas.CanvasView):
|
2006-08-19 11:12:25 +02:00
|
|
|
def __init__(self, shell, data_model):
|
2006-08-19 02:00:04 +02:00
|
|
|
goocanvas.CanvasView.__init__(self)
|
|
|
|
self._shell = shell
|
|
|
|
|
|
|
|
self.connect("item_view_created", self.__item_view_created_cb)
|
|
|
|
|
2006-08-19 11:12:25 +02:00
|
|
|
canvas_model = Model(data_model)
|
2006-08-19 02:00:04 +02:00
|
|
|
self.set_model(canvas_model)
|
|
|
|
|
|
|
|
def __item_view_created_cb(self, view, item_view, item):
|
|
|
|
pass
|