Rewrite of the grid stuff. Simpler api and cleaner implementation.
Also follow the micro grids in pentagram design.
This commit is contained in:
parent
5ec92a2cab
commit
857b9cb659
@ -6,8 +6,7 @@ import conf
|
||||
from sugar.canvas.IconItem import IconItem
|
||||
from sugar.canvas.IconColor import IconColor
|
||||
from sugar.presence import PresenceService
|
||||
from sugar.canvas.GridLayout import GridGroup
|
||||
from sugar.canvas.GridBox import GridBox
|
||||
from sugar.canvas.CanvasBox import CanvasBox
|
||||
|
||||
class ActivityItem(IconItem):
|
||||
def __init__(self, activity):
|
||||
@ -33,9 +32,9 @@ class InviteItem(IconItem):
|
||||
def get_invite(self):
|
||||
return self._invite
|
||||
|
||||
class BottomPanel(GridBox):
|
||||
def __init__(self, shell, invites):
|
||||
GridBox.__init__(self, GridBox.HORIZONTAL, 14, 6)
|
||||
class BottomPanel(CanvasBox):
|
||||
def __init__(self, grid, shell, invites):
|
||||
CanvasBox.__init__(self, grid, CanvasBox.HORIZONTAL, 1)
|
||||
|
||||
self._shell = shell
|
||||
self._invite_to_item = {}
|
||||
@ -68,11 +67,13 @@ class BottomPanel(GridBox):
|
||||
def add_activity(self, activity):
|
||||
item = ActivityItem(activity)
|
||||
item.connect('clicked', self.__activity_clicked_cb)
|
||||
self.set_constraints(item, 3, 3)
|
||||
self.add_child(item)
|
||||
|
||||
def add_invite(self, invite):
|
||||
item = InviteItem(invite)
|
||||
item.connect('clicked', self.__invite_clicked_cb)
|
||||
self.set_constraints(item, 3, 3)
|
||||
self.add_child(item, 0)
|
||||
|
||||
self._invite_to_item[invite] = item
|
||||
|
@ -8,55 +8,43 @@ from frame.TopPanel import TopPanel
|
||||
from frame.PanelWindow import PanelWindow
|
||||
|
||||
from sugar.canvas.ScreenContainer import ScreenContainer
|
||||
from sugar.canvas.GridLayout import GridLayout
|
||||
from sugar.canvas.GridLayout import GridConstraints
|
||||
from sugar.canvas.GridLayout import GridGroup
|
||||
from sugar.canvas.GridModel import GridModel
|
||||
from sugar.canvas.Grid import Grid
|
||||
|
||||
class Frame:
|
||||
def __init__(self, shell, owner):
|
||||
self._windows = []
|
||||
|
||||
self._model = GridModel("#4f4f4f")
|
||||
layout = self._model.get_layout()
|
||||
model = goocanvas.CanvasModelSimple()
|
||||
root = model.get_root_item()
|
||||
|
||||
self._screen_layout = GridLayout()
|
||||
self._screen_container = ScreenContainer(self._windows)
|
||||
grid = Grid()
|
||||
|
||||
constraints = GridConstraints(0, 0, 16, 1)
|
||||
self._create_window(constraints)
|
||||
bg = goocanvas.Rect(fill_color="#4f4f4f")
|
||||
grid.set_constraints(bg, 0, 0, 80, 60)
|
||||
root.add_child(bg)
|
||||
|
||||
panel = TopPanel(shell)
|
||||
layout.set_constraints(panel, constraints)
|
||||
self._model.add(panel)
|
||||
panel = BottomPanel(grid, shell, owner.get_invites())
|
||||
grid.set_constraints(panel, 5, 55)
|
||||
root.add_child(panel)
|
||||
|
||||
constraints = GridConstraints(15, 1, 1, 10)
|
||||
self._create_window(constraints)
|
||||
panel_window = PanelWindow(grid, model, 0, 55, 80, 5)
|
||||
self._windows.append(panel_window)
|
||||
|
||||
panel = RightPanel(shell, owner.get_friends())
|
||||
layout.set_constraints(panel, constraints)
|
||||
self._model.add(panel)
|
||||
panel = TopPanel(grid, shell)
|
||||
root.add_child(panel)
|
||||
|
||||
self._create_window(GridConstraints(0, 11, 16, 1))
|
||||
panel_window = PanelWindow(grid, model, 0, 0, 80, 5)
|
||||
self._windows.append(panel_window)
|
||||
|
||||
panel = RightPanel(grid, shell, owner.get_friends())
|
||||
grid.set_constraints(panel, 75, 5)
|
||||
root.add_child(panel)
|
||||
|
||||
panel = BottomPanel(shell, owner.get_invites())
|
||||
layout.set_constraints(panel, GridConstraints(1, 11, 14, 1))
|
||||
self._model.add(panel)
|
||||
panel_window = PanelWindow(grid, model, 75, 5, 5, 50)
|
||||
self._windows.append(panel_window)
|
||||
|
||||
# Left
|
||||
constraints = GridConstraints(0, 1, 1, 10)
|
||||
self._create_window(constraints)
|
||||
|
||||
self._screen_container.set_layout(self._screen_layout)
|
||||
|
||||
def _create_window(self, constraints):
|
||||
window = PanelWindow(self._model)
|
||||
self._screen_layout.set_constraints(window, constraints)
|
||||
self._windows.append(window)
|
||||
|
||||
bounds = self._model.get_layout().get_bounds(self._model._root, constraints)
|
||||
window.scale_to_screen()
|
||||
window.set_bounds(constraints)
|
||||
panel_window = PanelWindow(grid, model, 0, 5, 5, 50)
|
||||
self._windows.append(panel_window)
|
||||
|
||||
def __hide_timeout_cb(self):
|
||||
self.hide()
|
||||
|
@ -1,10 +1,13 @@
|
||||
import gtk
|
||||
import goocanvas
|
||||
|
||||
from sugar.canvas.GridWindow import GridWindow
|
||||
from sugar.canvas.CanvasView import CanvasView
|
||||
|
||||
class PanelWindow(GridWindow):
|
||||
def __init__(self, model):
|
||||
GridWindow.__init__(self, model)
|
||||
class PanelWindow(gtk.Window):
|
||||
def __init__(self, grid, model, x, y, width, height):
|
||||
gtk.Window.__init__(self)
|
||||
|
||||
self._grid = grid
|
||||
|
||||
self.set_decorated(False)
|
||||
|
||||
@ -14,3 +17,11 @@ class PanelWindow(GridWindow):
|
||||
|
||||
screen = gtk.gdk.screen_get_default()
|
||||
self.window.set_transient_for(screen.get_root_window())
|
||||
|
||||
view = CanvasView()
|
||||
view.show()
|
||||
self.add(view)
|
||||
view.set_model(model)
|
||||
|
||||
self._grid.set_constraints(self, x, y, width, height)
|
||||
self._grid.set_constraints(view, x, y, width, height)
|
||||
|
@ -1,15 +1,13 @@
|
||||
import goocanvas
|
||||
|
||||
from frame.PanelWindow import PanelWindow
|
||||
from sugar.canvas.IconItem import IconItem
|
||||
from sugar.canvas.IconColor import IconColor
|
||||
from sugar.canvas.GridLayout import GridGroup
|
||||
from sugar.canvas.GridBox import GridBox
|
||||
from sugar.canvas.CanvasBox import CanvasBox
|
||||
from sugar.presence import PresenceService
|
||||
|
||||
class RightPanel(GridBox):
|
||||
def __init__(self, shell, friends):
|
||||
GridBox.__init__(self, GridBox.VERTICAL, 10, 6)
|
||||
class RightPanel(CanvasBox):
|
||||
def __init__(self, grid, shell, friends):
|
||||
CanvasBox.__init__(self, grid, CanvasBox.VERTICAL, 1)
|
||||
self._shell = shell
|
||||
self._friends = friends
|
||||
self._activity_ps = None
|
||||
@ -26,7 +24,9 @@ class RightPanel(GridBox):
|
||||
def add(self, buddy):
|
||||
icon = IconItem(icon_name='stock-buddy',
|
||||
color=IconColor(buddy.get_color()))
|
||||
self.set_constraints(icon, 3, 3)
|
||||
icon.connect('clicked', self.__buddy_clicked_cb, buddy)
|
||||
|
||||
self.add_child(icon)
|
||||
|
||||
self._buddies[buddy.get_name()] = icon
|
||||
|
@ -1,44 +1,58 @@
|
||||
import goocanvas
|
||||
|
||||
from sugar.canvas.GridLayout import GridGroup
|
||||
from sugar.canvas.GridLayout import GridConstraints
|
||||
from sugar.canvas.CanvasBox import CanvasBox
|
||||
from sugar.canvas.IconItem import IconItem
|
||||
import sugar
|
||||
|
||||
class TopPanel(GridGroup):
|
||||
def __init__(self, shell):
|
||||
GridGroup.__init__(self, 16, 1)
|
||||
class TopPanel(goocanvas.Group):
|
||||
def __init__(self, grid, shell):
|
||||
goocanvas.Group.__init__(self)
|
||||
|
||||
self._grid = grid
|
||||
self._shell = shell
|
||||
|
||||
self.add_zoom_level(sugar.ZOOM_ACTIVITY, 'stock-zoom-activity', 1)
|
||||
self.add_zoom_level(sugar.ZOOM_HOME, 'stock-zoom-home', 2)
|
||||
self.add_zoom_level(sugar.ZOOM_FRIENDS, 'stock-zoom-friends', 3)
|
||||
self.add_zoom_level(sugar.ZOOM_MESH, 'stock-zoom-mesh', 4)
|
||||
box = CanvasBox(grid, CanvasBox.HORIZONTAL, 1)
|
||||
self._grid.set_constraints(box, 5, 0)
|
||||
self.add_child(box)
|
||||
|
||||
icon = IconItem(icon_name='stock-share', size=self._width)
|
||||
icon = IconItem(icon_name='stock-zoom-activity')
|
||||
icon.connect('clicked', self.__level_clicked_cb, sugar.ZOOM_ACTIVITY)
|
||||
box.set_constraints(icon, 3, 3)
|
||||
box.add_child(icon)
|
||||
|
||||
icon = IconItem(icon_name='stock-zoom-home')
|
||||
icon.connect('clicked', self.__level_clicked_cb, sugar.ZOOM_HOME)
|
||||
box.set_constraints(icon, 3, 3)
|
||||
box.add_child(icon)
|
||||
|
||||
icon = IconItem(icon_name='stock-zoom-friends')
|
||||
icon.connect('clicked', self.__level_clicked_cb, sugar.ZOOM_FRIENDS)
|
||||
box.set_constraints(icon, 3, 3)
|
||||
box.add_child(icon)
|
||||
|
||||
icon = IconItem(icon_name='stock-zoom-mesh')
|
||||
icon.connect('clicked', self.__level_clicked_cb, sugar.ZOOM_MESH)
|
||||
box.set_constraints(icon, 3, 3)
|
||||
box.add_child(icon)
|
||||
|
||||
box = CanvasBox(grid, CanvasBox.HORIZONTAL, 1)
|
||||
self._grid.set_constraints(box, 60, 0)
|
||||
self.add_child(box)
|
||||
|
||||
icon = IconItem(icon_name='stock-share')
|
||||
icon.connect('clicked', self.__share_clicked_cb)
|
||||
self.add_icon(icon, 12)
|
||||
box.set_constraints(icon, 3, 3)
|
||||
box.add_child(icon)
|
||||
|
||||
icon = IconItem(icon_name='stock-invite', size=self._width)
|
||||
icon = IconItem(icon_name='stock-invite')
|
||||
icon.connect('clicked', self.__invite_clicked_cb)
|
||||
self.add_icon(icon, 13)
|
||||
box.set_constraints(icon, 3, 3)
|
||||
box.add_child(icon)
|
||||
|
||||
icon = IconItem(icon_name='stock-chat', size=self._width)
|
||||
icon = IconItem(icon_name='stock-chat')
|
||||
icon.connect('clicked', self.__chat_clicked_cb)
|
||||
self.add_icon(icon, 14)
|
||||
|
||||
def add_zoom_level(self, level, icon_name, pos):
|
||||
icon = IconItem(icon_name=icon_name, size=self._height)
|
||||
icon.connect('clicked', self.__level_clicked_cb, level)
|
||||
|
||||
constraints = GridConstraints(pos, 0, 1, 1, 6)
|
||||
self._layout.set_constraints(icon, constraints)
|
||||
self.add_child(icon)
|
||||
|
||||
def add_icon(self, icon, pos):
|
||||
constraints = GridConstraints(pos, 0, 1, 1, 6)
|
||||
self._layout.set_constraints(icon, constraints)
|
||||
self.add_child(icon)
|
||||
box.set_constraints(icon, 3, 3)
|
||||
box.add_child(icon)
|
||||
|
||||
def __level_clicked_cb(self, item, level):
|
||||
self._shell.set_zoom_level(level)
|
||||
|
@ -5,7 +5,5 @@ class CanvasView(goocanvas.CanvasView):
|
||||
def __init__(self):
|
||||
goocanvas.CanvasView.__init__(self)
|
||||
|
||||
self.set_size_request(gtk.gdk.screen_width(),
|
||||
gtk.gdk.screen_height())
|
||||
self.set_bounds(0, 0, 1200, 900)
|
||||
self.set_scale(gtk.gdk.screen_width() / 1200.0)
|
||||
|
@ -2,7 +2,9 @@ sugardir = $(pythondir)/sugar/canvas
|
||||
sugar_PYTHON = \
|
||||
__init__.py \
|
||||
CanvasView.py \
|
||||
CanvasBox.py \
|
||||
Colors.py \
|
||||
Grid.py \
|
||||
GridBox.py \
|
||||
GridLayout.py \
|
||||
GridModel.py \
|
||||
|
@ -13,9 +13,8 @@ import goocanvas
|
||||
from sugar.canvas.IconColor import IconColor
|
||||
from sugar.canvas.IconItem import IconItem
|
||||
from sugar.canvas.CanvasView import CanvasView
|
||||
from sugar.canvas.GridBox import GridBox
|
||||
from sugar.canvas.GridModel import GridModel
|
||||
from sugar.canvas.GridLayout import GridConstraints
|
||||
from sugar.canvas.CanvasBox import CanvasBox
|
||||
from sugar.canvas.Grid import Grid
|
||||
|
||||
def _new_icon_clicked_cb(icon):
|
||||
box.remove_child(icon)
|
||||
@ -25,21 +24,26 @@ def _icon_clicked_cb(icon):
|
||||
icon.connect('clicked', _new_icon_clicked_cb)
|
||||
box.add_child(icon, 0)
|
||||
|
||||
model = GridModel('#4f4f4f')
|
||||
layout = model.get_layout()
|
||||
model = goocanvas.CanvasModelSimple()
|
||||
root = model.get_root_item()
|
||||
|
||||
box = GridBox(GridBox.HORIZONTAL, 5, 6)
|
||||
layout.set_constraints(box, GridConstraints(0, 0, 5, 1))
|
||||
model.add(box)
|
||||
grid = Grid()
|
||||
|
||||
box = CanvasBox(grid, CanvasBox.HORIZONTAL, 1)
|
||||
grid.set_constraints(box, 5, 5)
|
||||
root.add_child(box)
|
||||
|
||||
rect = goocanvas.Rect(fill_color='red')
|
||||
box.set_constraints(rect, 5, 5)
|
||||
box.add_child(rect)
|
||||
|
||||
icon = IconItem(color=IconColor(), icon_name='activity-web')
|
||||
icon.connect('clicked', _icon_clicked_cb)
|
||||
box.set_constraints(icon, 5, 5)
|
||||
box.add_child(icon)
|
||||
|
||||
icon = IconItem(color=IconColor(), icon_name='activity-groupchat')
|
||||
box.set_constraints(icon, 5, 5)
|
||||
box.add_child(icon)
|
||||
|
||||
window = gtk.Window()
|
||||
@ -49,6 +53,6 @@ window.show()
|
||||
canvas = CanvasView()
|
||||
canvas.show()
|
||||
window.add(canvas)
|
||||
canvas.set_model(model.get())
|
||||
canvas.set_model(model)
|
||||
|
||||
gtk.main()
|
||||
|
Loading…
Reference in New Issue
Block a user