Rewrite the zoom logic. Regress some stuff... will fix.
This commit is contained in:
parent
f75d36055f
commit
a29230c183
@ -210,10 +210,4 @@ class Shell(gobject.GObject):
|
||||
self._screen.toggle_showing_desktop(False)
|
||||
else:
|
||||
self._screen.toggle_showing_desktop(True)
|
||||
|
||||
if level == sugar.ZOOM_HOME:
|
||||
self._home_window.set_view(HomeWindow.HOME_VIEW)
|
||||
elif level == sugar.ZOOM_FRIENDS:
|
||||
self._home_window.set_view(HomeWindow.FRIENDS_VIEW)
|
||||
elif level == sugar.ZOOM_MESH:
|
||||
self._home_window.set_view(HomeWindow.MESH_VIEW)
|
||||
self._home_window.set_zoom_level(level)
|
||||
|
@ -16,32 +16,24 @@ class FriendIcon(IconItem):
|
||||
def get_friend(self):
|
||||
return self._friend
|
||||
|
||||
class Model(goocanvas.CanvasModelSimple):
|
||||
class FriendsGroup(goocanvas.Group):
|
||||
def __init__(self, data_model):
|
||||
goocanvas.CanvasModelSimple.__init__(self)
|
||||
goocanvas.Group.__init__(self)
|
||||
self._friend_to_child = {}
|
||||
|
||||
self._theme = Theme.get_instance()
|
||||
self._theme.connect("theme-changed", self.__theme_changed_cb)
|
||||
|
||||
self._root = self.get_root_item()
|
||||
|
||||
color = self._theme.get_home_mesh_color()
|
||||
self._mesh_rect = goocanvas.Rect(width=1200, height=900,
|
||||
fill_color=color)
|
||||
self._root.add_child(self._mesh_rect)
|
||||
line_width=0, fill_color=color)
|
||||
self.add_child(self._mesh_rect)
|
||||
|
||||
color = self._theme.get_home_friends_color()
|
||||
self._friends_rect = goocanvas.Rect(x=100, y=100, width=1000, height=700,
|
||||
self._friends_rect = goocanvas.Rect(x=50, y=50, width=1100, height=800,
|
||||
line_width=0, fill_color=color,
|
||||
radius_x=30, radius_y=30)
|
||||
self._root.add_child(self._friends_rect)
|
||||
|
||||
color = self._theme.get_home_activities_color()
|
||||
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)
|
||||
self._root.add_child(self._home_rect)
|
||||
self.add_child(self._friends_rect)
|
||||
|
||||
for friend in data_model:
|
||||
self.add_friend(friend)
|
||||
@ -50,8 +42,6 @@ class Model(goocanvas.CanvasModelSimple):
|
||||
data_model.connect('friend-removed', self.__friend_removed_cb)
|
||||
|
||||
def __theme_changed_cb(self, theme):
|
||||
color = self._theme.get_home_activities_color()
|
||||
self._home_rect.set_property("fill-color", color)
|
||||
color = self._theme.get_home_friends_color()
|
||||
self._friends_rect.set_property("fill-color", color)
|
||||
color = self._theme.get_home_mesh_color()
|
||||
@ -59,12 +49,12 @@ class Model(goocanvas.CanvasModelSimple):
|
||||
|
||||
def add_friend(self, friend):
|
||||
icon = FriendIcon(friend)
|
||||
self._root.add_child(icon)
|
||||
self.add_child(icon)
|
||||
self._friend_to_child[friend] = icon
|
||||
|
||||
def remove_friend(self, friend):
|
||||
icon = self._friend_to_child[friend]
|
||||
self._root.remove_child(self._root.find_child(icon))
|
||||
self.remove_child(self._root.find_child(icon))
|
||||
del self._friend_to_child[friend]
|
||||
|
||||
def __friend_added_cb(self, data_model, friend):
|
||||
@ -72,16 +62,3 @@ class Model(goocanvas.CanvasModelSimple):
|
||||
|
||||
def __friend_removed_cb(self, data_model, friend):
|
||||
self.remove_friend(friend)
|
||||
|
||||
class FriendsView(goocanvas.CanvasView):
|
||||
def __init__(self, shell, data_model):
|
||||
goocanvas.CanvasView.__init__(self)
|
||||
self._shell = shell
|
||||
|
||||
self.connect("item_view_created", self.__item_view_created_cb)
|
||||
|
||||
canvas_model = Model(data_model)
|
||||
self.set_model(canvas_model)
|
||||
|
||||
def __item_view_created_cb(self, view, item_view, item):
|
||||
pass
|
@ -50,65 +50,48 @@ class Background(goocanvas.Group):
|
||||
|
||||
color = self._theme.get_home_friends_color()
|
||||
self._friends_rect = goocanvas.Rect(width=1200, height=900,
|
||||
fill_color=color)
|
||||
line_width=0, fill_color=color)
|
||||
self.add_child(self._friends_rect)
|
||||
|
||||
color = self._theme.get_home_activities_color()
|
||||
self._home_rect = goocanvas.Rect(x=100, y=100, width=1000, height=700,
|
||||
line_width=0, fill_color=color,
|
||||
radius_x=30, radius_y=30)
|
||||
self._home_rect = goocanvas.Rect(x=50, y=50, width=1100, height=800,
|
||||
line_width=0, fill_color=color,
|
||||
radius_x=30, radius_y=30)
|
||||
self.add_child(self._home_rect)
|
||||
|
||||
item = goocanvas.Text(text="My Activities",
|
||||
x=12, y=12, fill_color="black",
|
||||
font="Sans 21")
|
||||
self.add_child(item)
|
||||
|
||||
def __theme_changed_cb(self, theme):
|
||||
color = self._theme.get_home_activities_color()
|
||||
self._home_rect.set_property("fill-color", color)
|
||||
color = self._theme.get_friends_colors()
|
||||
color = self._theme.get_home_friends_color()
|
||||
self._friends_rect.set_property("fill-color", color)
|
||||
|
||||
class Model(goocanvas.CanvasModelSimple):
|
||||
class HomeGroup(goocanvas.Group):
|
||||
def __init__(self, shell):
|
||||
goocanvas.CanvasModelSimple.__init__(self)
|
||||
|
||||
root = self.get_root_item()
|
||||
goocanvas.Group.__init__(self)
|
||||
|
||||
background = Background()
|
||||
root.add_child(background)
|
||||
self.add_child(background)
|
||||
|
||||
tasks = TasksItem(shell)
|
||||
tasks.translate(600, 450)
|
||||
root.add_child(tasks)
|
||||
self.add_child(tasks)
|
||||
|
||||
profile = sugar.conf.get_profile()
|
||||
me = IconItem(icon_name = 'stock-buddy',
|
||||
color = profile.get_color(), size = 150)
|
||||
me.translate(600 - (me.get_property('width') / 2),
|
||||
450 - (me.get_property('height') / 2))
|
||||
root.add_child(me)
|
||||
self.add_child(me)
|
||||
|
||||
class HomeView(goocanvas.CanvasView):
|
||||
def __init__(self, shell):
|
||||
goocanvas.CanvasView.__init__(self)
|
||||
self._shell = shell
|
||||
|
||||
self.connect("item_view_created", self.__item_view_created_cb)
|
||||
|
||||
canvas_model = Model(shell)
|
||||
self.set_model(canvas_model)
|
||||
|
||||
def __item_view_created_cb(self, view, item_view, item):
|
||||
if isinstance(item, PieceItem) or \
|
||||
isinstance(item, PieceIcon):
|
||||
item_view.connect("button_press_event",
|
||||
self.__task_button_press_cb)
|
||||
|
||||
def __activity_button_press_cb(self, view, target, event, activity_id):
|
||||
self._shell.start_activity(activity_id)
|
||||
|
||||
def __task_button_press_cb(self, view, target, event):
|
||||
activity = view.get_item().get_data('activity')
|
||||
activity.present()
|
||||
# def __item_view_created_cb(self, view, item_view, item):
|
||||
# if isinstance(item, PieceItem) or \
|
||||
# isinstance(item, PieceIcon):
|
||||
# item_view.connect("button_press_event",
|
||||
# self.__task_button_press_cb)
|
||||
#
|
||||
# def __activity_button_press_cb(self, view, target, event, activity_id):
|
||||
# self._shell.start_activity(activity_id)
|
||||
#
|
||||
# def __task_button_press_cb(self, view, target, event):
|
||||
# activity = view.get_item().get_data('activity')
|
||||
# activity.present()
|
@ -1,50 +1,66 @@
|
||||
import gtk
|
||||
import goocanvas
|
||||
import cairo
|
||||
|
||||
from home.MeshView import MeshView
|
||||
from home.HomeView import HomeView
|
||||
from home.FriendsView import FriendsView
|
||||
from home.MeshGroup import MeshGroup
|
||||
from home.HomeGroup import HomeGroup
|
||||
from home.FriendsGroup import FriendsGroup
|
||||
import sugar
|
||||
|
||||
class HomeWindow(gtk.Window):
|
||||
HOME_VIEW = 0
|
||||
FRIENDS_VIEW = 1
|
||||
MESH_VIEW = 2
|
||||
|
||||
CANVAS_WIDTH = 1200
|
||||
CANVAS_HEIGHT = 900
|
||||
def __init__(self, shell):
|
||||
gtk.Window.__init__(self)
|
||||
self._shell = shell
|
||||
|
||||
self.connect('realize', self.__realize_cb)
|
||||
|
||||
self._nb = gtk.Notebook()
|
||||
self._nb.set_show_tabs(False)
|
||||
self._nb.set_show_border(False)
|
||||
|
||||
self.add(self._nb)
|
||||
self._nb.show()
|
||||
self.realize()
|
||||
self.window.set_type_hint(gtk.gdk.WINDOW_TYPE_HINT_DESKTOP)
|
||||
|
||||
def set_model(self, model):
|
||||
home_view = HomeView(self._shell)
|
||||
self._nb.append_page(home_view)
|
||||
self._setup_canvas(home_view)
|
||||
home_view.show()
|
||||
self._model = goocanvas.CanvasModelSimple()
|
||||
root = self._model.get_root_item()
|
||||
|
||||
friends_view = FriendsView(self._shell, model.get_friends())
|
||||
self._nb.append_page(friends_view)
|
||||
self._setup_canvas(friends_view)
|
||||
friends_view.show()
|
||||
|
||||
mesh_view = MeshView(self._shell, model.get_mesh())
|
||||
self._setup_canvas(mesh_view)
|
||||
self._nb.append_page(mesh_view)
|
||||
mesh_view.show()
|
||||
data_model = model.get_mesh()
|
||||
self._mesh_group = MeshGroup(data_model)
|
||||
root.add_child(self._mesh_group)
|
||||
|
||||
def set_view(self, view):
|
||||
self._nb.set_current_page(view)
|
||||
data_model = model.get_friends()
|
||||
self._friends_group = FriendsGroup(data_model)
|
||||
root.add_child(self._friends_group)
|
||||
|
||||
def _setup_canvas(self, canvas):
|
||||
canvas.set_bounds(0, 0, 1200, 900)
|
||||
canvas.set_scale(float(gtk.gdk.screen_width()) / float(1200))
|
||||
canvas.set_size_request(gtk.gdk.screen_width(), gtk.gdk.screen_height())
|
||||
self._home_group = HomeGroup(self._shell)
|
||||
root.add_child(self._home_group)
|
||||
|
||||
def __realize_cb(self, window):
|
||||
self.window.set_type_hint(gtk.gdk.WINDOW_TYPE_HINT_DESKTOP)
|
||||
canvas = goocanvas.CanvasView()
|
||||
canvas.set_bounds(0, 0, HomeWindow.CANVAS_WIDTH,
|
||||
HomeWindow.CANVAS_HEIGHT)
|
||||
canvas.set_scale(float(gtk.gdk.screen_width()) /
|
||||
float(HomeWindow.CANVAS_WIDTH))
|
||||
canvas.set_size_request(gtk.gdk.screen_width(),
|
||||
gtk.gdk.screen_height())
|
||||
canvas.set_model(self._model)
|
||||
|
||||
self.add(canvas)
|
||||
canvas.show()
|
||||
|
||||
def _set_group_scale(self, group, d):
|
||||
x = HomeWindow.CANVAS_WIDTH * (1 - d) / 2
|
||||
y = HomeWindow.CANVAS_HEIGHT * (1 - d) / 2
|
||||
|
||||
matrix = cairo.Matrix(1, 0, 0, 1, 0, 0)
|
||||
matrix.translate(x, y)
|
||||
matrix.scale(d, d)
|
||||
|
||||
group.set_transform(matrix)
|
||||
|
||||
def set_zoom_level(self, level):
|
||||
if level == sugar.ZOOM_HOME:
|
||||
self._set_group_scale(self._home_group, 1.0)
|
||||
elif level == sugar.ZOOM_FRIENDS:
|
||||
self._set_group_scale(self._home_group, 0.5)
|
||||
self._set_group_scale(self._friends_group, 1.0)
|
||||
elif level == sugar.ZOOM_MESH:
|
||||
self._set_group_scale(self._home_group, 0.2)
|
||||
self._set_group_scale(self._friends_group, 0.4)
|
||||
self._set_group_scale(self._mesh_group, 1.0)
|
||||
|
60
shell/home/MeshGroup.py
Normal file
60
shell/home/MeshGroup.py
Normal file
@ -0,0 +1,60 @@
|
||||
import random
|
||||
|
||||
import goocanvas
|
||||
|
||||
from sugar.canvas.IconItem import IconItem
|
||||
from sugar.canvas.IconItem import IconColor
|
||||
from sugar import conf
|
||||
|
||||
import Theme
|
||||
|
||||
class ActivityItem(IconItem):
|
||||
def __init__(self, activity):
|
||||
registry = conf.get_activity_registry()
|
||||
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)
|
||||
|
||||
self._activity = activity
|
||||
|
||||
def get_service(self):
|
||||
return self._activity.get_service()
|
||||
|
||||
class MeshGroup(goocanvas.Group):
|
||||
def __init__(self, data_model):
|
||||
goocanvas.Group.__init__(self)
|
||||
self._theme = Theme.get_instance()
|
||||
self._theme.connect("theme-changed", self.__theme_changed_cb)
|
||||
|
||||
color = self._theme.get_home_mesh_color()
|
||||
self._mesh_rect = goocanvas.Rect(width=1200, height=900,
|
||||
fill_color=color)
|
||||
self.add_child(self._mesh_rect)
|
||||
|
||||
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
|
||||
|
||||
def add_activity(self, activity):
|
||||
item = ActivityItem(activity)
|
||||
item.set_property('x', random.random() * 1100)
|
||||
item.set_property('y', random.random() * 800)
|
||||
self.add_child(item)
|
||||
|
||||
def __activity_added_cb(self, data_model, activity):
|
||||
self.add_activity(activity)
|
||||
|
||||
# def __activity_button_press_cb(self, view, target, event, service):
|
||||
# self._shell.join_activity(service)
|
||||
#
|
||||
# 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_service())
|
@ -1,86 +0,0 @@
|
||||
import random
|
||||
|
||||
import goocanvas
|
||||
|
||||
from sugar.canvas.IconItem import IconItem
|
||||
from sugar.canvas.IconItem import IconColor
|
||||
from sugar import conf
|
||||
|
||||
import Theme
|
||||
|
||||
class ActivityItem(IconItem):
|
||||
def __init__(self, activity):
|
||||
registry = conf.get_activity_registry()
|
||||
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)
|
||||
|
||||
self._activity = activity
|
||||
|
||||
def get_service(self):
|
||||
return self._activity.get_service()
|
||||
|
||||
class Model(goocanvas.CanvasModelSimple):
|
||||
def __init__(self, data_model):
|
||||
goocanvas.CanvasModelSimple.__init__(self)
|
||||
self._theme = Theme.get_instance()
|
||||
self._theme.connect("theme-changed", self.__theme_changed_cb)
|
||||
|
||||
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)
|
||||
|
||||
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
|
||||
|
||||
def add_activity(self, activity):
|
||||
root = self.get_root_item()
|
||||
|
||||
item = ActivityItem(activity)
|
||||
item.set_property('x', random.random() * 1100)
|
||||
item.set_property('y', random.random() * 800)
|
||||
root.add_child(item)
|
||||
|
||||
def __activity_added_cb(self, data_model, activity):
|
||||
self.add_activity(activity)
|
||||
|
||||
class MeshView(goocanvas.CanvasView):
|
||||
def __init__(self, shell, data_model):
|
||||
goocanvas.CanvasView.__init__(self)
|
||||
self._shell = shell
|
||||
|
||||
self.connect("item_view_created", self.__item_view_created_cb)
|
||||
|
||||
canvas_model = Model(data_model)
|
||||
self.set_model(canvas_model)
|
||||
|
||||
def __activity_button_press_cb(self, view, target, event, service):
|
||||
self._shell.join_activity(service)
|
||||
|
||||
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_service())
|
Loading…
Reference in New Issue
Block a user