sugar-toolkit-gtk3/shell/home/MeshView.py

87 lines
2.4 KiB
Python
Raw Normal View History

2006-08-19 11:33:58 +02:00
import random
2006-08-19 01:29:42 +02:00
import goocanvas
2006-08-19 11:33:58 +02:00
from sugar.canvas.IconItem import IconItem
from sugar.canvas.IconItem import IconColor
from sugar import conf
2006-08-19 11:33:58 +02:00
import Theme
2006-08-19 11:33:58 +02:00
class ActivityItem(IconItem):
def __init__(self, activity):
registry = conf.get_activity_registry()
2006-08-19 11:33:58 +02:00
info = registry.get_activity(activity.get_type())
icon_name = info.get_icon()
IconItem.__init__(self, icon_name=icon_name,
color=activity.get_color(), size=48)
2006-08-19 11:33:58 +02:00
self._activity = activity
def get_service(self):
return self._activity.get_service()
2006-08-19 01:29:42 +02:00
class Model(goocanvas.CanvasModelSimple):
def __init__(self, data_model):
2006-08-19 01:29:42 +02:00
goocanvas.CanvasModelSimple.__init__(self)
self._theme = Theme.get_instance()
self._theme.connect("theme-changed", self.__theme_changed_cb)
2006-08-19 01:29:42 +02:00
root = self.get_root_item()
color = self._theme.get_home_mesh_color()
self._mesh_rect = goocanvas.Rect(width=1200, height=900,
fill_color=color)
root.add_child(self._mesh_rect)
color = self._theme.get_home_friends_color()
self._friends_rect = goocanvas.Rect(x=350, y=280, width=500, height=340,
line_width=0, fill_color=color,
radius_x=30, radius_y=30)
root.add_child(self._friends_rect)
color = self._theme.get_home_activities_color()
self._home_rect = goocanvas.Rect(x=480, y=360, width=240, height=180,
line_width=0, fill_color=color,
radius_x=30, radius_y=30)
root.add_child(self._home_rect)
2006-08-19 11:33:58 +02:00
for activity in data_model:
self.add_activity(activity)
data_model.connect('activity-added', self.__activity_added_cb)
def __theme_changed_cb(self, theme):
pass
2006-08-19 11:33:58 +02:00
def add_activity(self, activity):
root = self.get_root_item()
2006-08-26 14:17:55 +02:00
item = ActivityItem(activity)
2006-08-19 11:33:58 +02:00
item.set_property('x', random.random() * 1100)
item.set_property('y', random.random() * 800)
2006-08-19 11:12:25 +02:00
root.add_child(item)
2006-08-19 11:33:58 +02:00
def __activity_added_cb(self, data_model, activity):
self.add_activity(activity)
2006-08-19 01:29:42 +02:00
class MeshView(goocanvas.CanvasView):
2006-08-19 11:12:25 +02:00
def __init__(self, shell, data_model):
2006-08-19 01:29:42 +02:00
goocanvas.CanvasView.__init__(self)
self._shell = shell
self.connect("item_view_created", self.__item_view_created_cb)
canvas_model = Model(data_model)
2006-08-19 01:29:42 +02:00
self.set_model(canvas_model)
2006-08-19 11:33:58 +02:00
def __activity_button_press_cb(self, view, target, event, service):
self._shell.join_activity(service)
2006-08-19 01:29:42 +02:00
def __item_view_created_cb(self, view, item_view, item):
2006-08-19 11:33:58 +02:00
if isinstance(item, ActivityItem):
item_view.connect("button_press_event",
self.__activity_button_press_cb,
item.get_service())