Use CanvasView, rework to the new design, cleanup code a lot
This commit is contained in:
parent
1eae3082c2
commit
41b528284c
@ -3,7 +3,6 @@ import random
|
||||
import goocanvas
|
||||
|
||||
from sugar.canvas.IconItem import IconItem
|
||||
import Theme
|
||||
|
||||
class FriendIcon(IconItem):
|
||||
def __init__(self, friend):
|
||||
@ -15,9 +14,6 @@ class FriendIcon(IconItem):
|
||||
return self._friend
|
||||
|
||||
class FriendsGroup(goocanvas.Group):
|
||||
WIDTH = 1200.0 * 1.9
|
||||
HEIGHT = 900.0 * 1.9
|
||||
|
||||
def __init__(self, shell, friends, icon_layout):
|
||||
goocanvas.Group.__init__(self)
|
||||
|
||||
@ -25,25 +21,11 @@ class FriendsGroup(goocanvas.Group):
|
||||
self._icon_layout = icon_layout
|
||||
self._friends = friends
|
||||
|
||||
self._theme = Theme.get_instance()
|
||||
self._theme.connect("theme-changed", self.__theme_changed_cb)
|
||||
|
||||
color = self._theme.get_home_friends_color()
|
||||
self._friends_rect = goocanvas.Rect(width=FriendsGroup.WIDTH,
|
||||
height=FriendsGroup.HEIGHT,
|
||||
line_width=0, fill_color=color,
|
||||
radius_x=60, radius_y=60)
|
||||
self.add_child(self._friends_rect)
|
||||
|
||||
for friend in self._friends:
|
||||
self.add_friend(friend)
|
||||
|
||||
friends.connect('friend-added', self.__friend_added_cb)
|
||||
|
||||
def __theme_changed_cb(self, theme):
|
||||
color = self._theme.get_home_friends_color()
|
||||
self._friends_rect.set_property("fill-color", color)
|
||||
|
||||
def __friend_clicked_cb(self, icon):
|
||||
activity = self._shell.get_current_activity()
|
||||
buddy = icon.get_friend().get_buddy()
|
||||
|
@ -6,7 +6,6 @@ import conf
|
||||
from sugar.canvas.IconItem import IconItem
|
||||
from sugar.canvas.IconColor import IconColor
|
||||
from home.DonutItem import DonutItem
|
||||
import Theme
|
||||
|
||||
class TasksItem(DonutItem):
|
||||
def __init__(self, shell):
|
||||
@ -44,22 +43,9 @@ class TasksItem(DonutItem):
|
||||
activity.present()
|
||||
|
||||
class HomeGroup(goocanvas.Group):
|
||||
WIDTH = 1200.0
|
||||
HEIGHT = 900.0
|
||||
|
||||
def __init__(self, shell):
|
||||
goocanvas.Group.__init__(self)
|
||||
|
||||
self._theme = Theme.get_instance()
|
||||
self._theme.connect("theme-changed", self.__theme_changed_cb)
|
||||
|
||||
color = self._theme.get_home_activities_color()
|
||||
self._home_rect = goocanvas.Rect(width=HomeGroup.WIDTH,
|
||||
height=HomeGroup.HEIGHT,
|
||||
line_width=0, fill_color=color,
|
||||
radius_x=30, radius_y=30)
|
||||
self.add_child(self._home_rect)
|
||||
|
||||
tasks = TasksItem(shell)
|
||||
tasks.translate(600, 450)
|
||||
self.add_child(tasks)
|
||||
@ -70,7 +56,3 @@ class HomeGroup(goocanvas.Group):
|
||||
me.translate(600 - (me.get_property('size') / 2),
|
||||
450 - (me.get_property('size') / 2))
|
||||
self.add_child(me)
|
||||
|
||||
def __theme_changed_cb(self, theme):
|
||||
color = self._theme.get_home_activities_color()
|
||||
self._home_rect.set_property("fill-color", color)
|
||||
|
@ -2,6 +2,7 @@ import gtk
|
||||
import goocanvas
|
||||
import cairo
|
||||
|
||||
from sugar.canvas.CanvasView import CanvasView
|
||||
from home.MeshGroup import MeshGroup
|
||||
from home.HomeGroup import HomeGroup
|
||||
from home.FriendsGroup import FriendsGroup
|
||||
@ -12,65 +13,43 @@ class HomeWindow(gtk.Window):
|
||||
def __init__(self, shell):
|
||||
gtk.Window.__init__(self)
|
||||
self._shell = shell
|
||||
self._width = MeshGroup.WIDTH
|
||||
self._height = MeshGroup.HEIGHT
|
||||
|
||||
self._view = goocanvas.CanvasView()
|
||||
self._view.set_size_request(gtk.gdk.screen_width(),
|
||||
gtk.gdk.screen_height())
|
||||
self.set_zoom_level(sugar.ZOOM_HOME)
|
||||
model = goocanvas.CanvasModelSimple()
|
||||
self._view.set_model(model)
|
||||
|
||||
self.add(self._view)
|
||||
self._view.show()
|
||||
|
||||
self.realize()
|
||||
self.window.set_type_hint(gtk.gdk.WINDOW_TYPE_HINT_DESKTOP)
|
||||
|
||||
def set_owner(self, owner):
|
||||
root = self._view.get_model().get_root_item()
|
||||
view = CanvasView()
|
||||
self.add(view)
|
||||
view.show()
|
||||
|
||||
friends_x = (self._width - FriendsGroup.WIDTH) / 2
|
||||
friends_y = (self._height - FriendsGroup.HEIGHT) / 2
|
||||
model = goocanvas.CanvasModelSimple()
|
||||
self._root = model.get_root_item()
|
||||
view.set_model(model)
|
||||
|
||||
home_x = (self._width - HomeGroup.WIDTH) / 2
|
||||
home_y = (self._height - HomeGroup.HEIGHT) / 2
|
||||
|
||||
layout = IconLayout(MeshGroup.WIDTH, MeshGroup.HEIGHT)
|
||||
layout.set_internal_bounds(friends_x, friends_y,
|
||||
friends_x + FriendsGroup.WIDTH,
|
||||
friends_y + FriendsGroup.HEIGHT)
|
||||
|
||||
self._mesh_group = MeshGroup(self._shell, layout)
|
||||
root.add_child(self._mesh_group)
|
||||
|
||||
layout = IconLayout(FriendsGroup.WIDTH, FriendsGroup.HEIGHT)
|
||||
layout.set_internal_bounds(home_x - friends_x, home_y - friends_y,
|
||||
home_x - friends_x + HomeGroup.WIDTH,
|
||||
home_y - friends_y + HomeGroup.HEIGHT)
|
||||
|
||||
friends = owner.get_friends()
|
||||
self._friends_group = FriendsGroup(self._shell, friends, layout)
|
||||
self._friends_group.translate(friends_x, friends_y)
|
||||
root.add_child(self._friends_group)
|
||||
bg = goocanvas.Rect(width=1900, height=1200,
|
||||
line_width=0, fill_color='#e2e2e2')
|
||||
self._root.add_child(bg)
|
||||
|
||||
self._home_group = HomeGroup(self._shell)
|
||||
self._home_group.translate(home_x, home_y)
|
||||
root.add_child(self._home_group)
|
||||
self._root.add_child(self._home_group)
|
||||
self._current_group = self._home_group
|
||||
|
||||
def set_owner(self, owner):
|
||||
layout = IconLayout(1900, 1200)
|
||||
friends = owner.get_friends()
|
||||
self._friends_group = FriendsGroup(self._shell, friends, layout)
|
||||
|
||||
layout = IconLayout(1900, 1200)
|
||||
self._mesh_group = MeshGroup(self._shell, layout)
|
||||
|
||||
def _set_group(self, group):
|
||||
self._root.remove_child(self._current_group)
|
||||
self._root.add_child(group)
|
||||
self._current_group = group
|
||||
|
||||
def set_zoom_level(self, level):
|
||||
if level == sugar.ZOOM_HOME:
|
||||
width = HomeGroup.WIDTH * 1.1
|
||||
height = HomeGroup.HEIGHT * 1.1
|
||||
self._set_group(self._home_group)
|
||||
elif level == sugar.ZOOM_FRIENDS:
|
||||
width = FriendsGroup.WIDTH * 1.1
|
||||
height = FriendsGroup.HEIGHT * 1.1
|
||||
self._set_group(self._friends_group)
|
||||
elif level == sugar.ZOOM_MESH:
|
||||
width = MeshGroup.WIDTH
|
||||
height = MeshGroup.HEIGHT
|
||||
|
||||
self._view.set_bounds((self._width - width) / 2,
|
||||
(self._height - height) / 2,
|
||||
width, height)
|
||||
self._view.set_scale(gtk.gdk.screen_width() / width)
|
||||
self._set_group(self._mesh_group)
|
||||
|
@ -6,12 +6,6 @@ class IconLayout:
|
||||
self._width = width
|
||||
self._height = height
|
||||
|
||||
def set_internal_bounds(self, x1, y1, x2, y2):
|
||||
self._x1 = x1
|
||||
self._y1 = y1
|
||||
self._x2 = x2
|
||||
self._y2 = y2
|
||||
|
||||
def add_icon(self, icon):
|
||||
self._icons.append(icon)
|
||||
self._layout_icon(icon)
|
||||
@ -27,10 +21,6 @@ class IconLayout:
|
||||
border < y < self._height - icon_size - border):
|
||||
return False
|
||||
|
||||
if self._x1 - icon_size - border < x < self._x2 + border and \
|
||||
self._y1 - icon_size - border < y < self._y2 + border:
|
||||
return False
|
||||
|
||||
return True
|
||||
|
||||
def _layout_icon(self, icon):
|
||||
|
@ -7,8 +7,6 @@ from sugar.canvas.IconItem import IconItem
|
||||
from sugar.canvas.IconItem import IconColor
|
||||
from sugar.presence import PresenceService
|
||||
|
||||
import Theme
|
||||
|
||||
class ActivityItem(IconItem):
|
||||
def __init__(self, service):
|
||||
self._service = service
|
||||
@ -34,23 +32,12 @@ class ActivityItem(IconItem):
|
||||
return self._service
|
||||
|
||||
class MeshGroup(goocanvas.Group):
|
||||
WIDTH = 1200.0 * 3.5
|
||||
HEIGHT = 900.0 * 3.5
|
||||
|
||||
def __init__(self, shell, icon_layout):
|
||||
goocanvas.Group.__init__(self)
|
||||
self._shell = shell
|
||||
self._icon_layout = icon_layout
|
||||
self._activities = {}
|
||||
|
||||
self._theme = Theme.get_instance()
|
||||
|
||||
color = self._theme.get_home_mesh_color()
|
||||
self._mesh_rect = goocanvas.Rect(width=MeshGroup.WIDTH,
|
||||
height=MeshGroup.HEIGHT,
|
||||
fill_color=color)
|
||||
self.add_child(self._mesh_rect)
|
||||
|
||||
pservice = PresenceService.get_instance()
|
||||
pservice.connect("service-appeared", self.__service_appeared_cb)
|
||||
|
||||
|
@ -1,57 +0,0 @@
|
||||
import gobject
|
||||
|
||||
|
||||
|
||||
class Theme(gobject.GObject):
|
||||
__gsignals__ = {
|
||||
'theme-changed': (gobject.SIGNAL_RUN_FIRST, gobject.TYPE_NONE,
|
||||
([]))
|
||||
}
|
||||
|
||||
# from OLPC_PLAN_14.swf
|
||||
__colors = {
|
||||
'blue': ("#c7d2fb", "#bbc8fa", "#afbffa"),
|
||||
'turquoise': ("#c8dce8", "#bdd4e3", "#b1cdde"),
|
||||
'green': ("#ccebac", "#c1e79a", "#b6e388"),
|
||||
'tan': ("#e8ead1", "#e4e5c8", "#dfe1be"),
|
||||
'gray': ("#dbe1dd", "#d3dbd5", "#ccd5ce"),
|
||||
'dark-gray': ("#dad1d4", "#d2c7cb", "#cabdc2")
|
||||
}
|
||||
|
||||
def __init__(self):
|
||||
gobject.GObject.__init__(self)
|
||||
self._cur_theme = 'blue'
|
||||
|
||||
def set(self, theme):
|
||||
updated = False
|
||||
if type(theme) == type(""):
|
||||
theme = theme.lower()
|
||||
if self.__colors.has_key(theme):
|
||||
self._cur_theme = theme
|
||||
updated = True
|
||||
elif type(theme) == type(1):
|
||||
try:
|
||||
theme = self.__colors.keys()[theme]
|
||||
self._cur_theme = theme
|
||||
updated = True
|
||||
except IndexError:
|
||||
pass
|
||||
if updated:
|
||||
self.emit('theme-changed')
|
||||
|
||||
def get_home_activities_color(self):
|
||||
return self.__colors[self._cur_theme][0]
|
||||
|
||||
def get_home_friends_color(self):
|
||||
return self.__colors[self._cur_theme][1]
|
||||
|
||||
def get_home_mesh_color(self):
|
||||
return self.__colors[self._cur_theme][2]
|
||||
|
||||
# Use this accessor, don't create more than one theme object
|
||||
_theme = None
|
||||
def get_instance():
|
||||
global _theme
|
||||
if not _theme:
|
||||
_theme = Theme()
|
||||
return _theme
|
Loading…
Reference in New Issue
Block a user