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

77 lines
2.3 KiB
Python
Raw Normal View History

2006-08-19 01:29:42 +02:00
import gtk
import goocanvas
import cairo
2006-08-19 01:29:42 +02:00
from home.MeshGroup import MeshGroup
from home.HomeGroup import HomeGroup
from home.FriendsGroup import FriendsGroup
from home.IconLayout import IconLayout
import sugar
2006-08-19 01:29:42 +02:00
class HomeWindow(gtk.Window):
def __init__(self, shell):
2006-08-19 01:29:42 +02:00
gtk.Window.__init__(self)
self._shell = shell
2006-08-29 14:39:34 +02:00
self._width = MeshGroup.WIDTH
self._height = MeshGroup.HEIGHT
2006-08-19 01:29:42 +02:00
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()
2006-08-19 01:29:42 +02:00
icon_layout = IconLayout(MeshGroup.WIDTH, MeshGroup.HEIGHT)
x1 = (self._width - FriendsGroup.WIDTH) / 2
y1 = (self._height - FriendsGroup.HEIGHT) / 2
x2 = x1 + FriendsGroup.WIDTH
y2 = y1 + FriendsGroup.HEIGHT
icon_layout.set_bounds(x1, y1, x2, y2)
self._mesh_group = MeshGroup(self._shell, icon_layout)
root.add_child(self._mesh_group)
2006-08-19 01:29:42 +02:00
icon_layout = IconLayout(FriendsGroup.WIDTH, FriendsGroup.HEIGHT)
x1 = (self._width - HomeGroup.WIDTH) / 2
y1 = (self._height - HomeGroup.HEIGHT) / 2
x2 = x1 + HomeGroup.WIDTH
y2 = y1 + HomeGroup.HEIGHT
icon_layout.set_bounds(x1, y1, x2, y2)
2006-09-04 14:30:44 +02:00
self._friends_group = FriendsGroup(self._shell, owner.get_friends(),
icon_layout)
2006-08-29 14:39:34 +02:00
self._friends_group.translate((self._width - FriendsGroup.WIDTH) / 2,
(self._height - FriendsGroup.HEIGHT) / 2)
root.add_child(self._friends_group)
self._home_group = HomeGroup(self._shell)
2006-08-29 14:39:34 +02:00
self._home_group.translate((self._width - HomeGroup.WIDTH) / 2,
(self._height - HomeGroup.HEIGHT) / 2)
root.add_child(self._home_group)
def set_zoom_level(self, level):
if level == sugar.ZOOM_HOME:
2006-08-29 14:39:34 +02:00
width = HomeGroup.WIDTH * 1.1
height = HomeGroup.HEIGHT * 1.1
elif level == sugar.ZOOM_FRIENDS:
2006-08-29 14:39:34 +02:00
width = FriendsGroup.WIDTH * 1.1
height = FriendsGroup.HEIGHT * 1.1
elif level == sugar.ZOOM_MESH:
2006-08-29 14:39:34 +02:00
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)