Get rid of old grid implementation leftovers

This commit is contained in:
Marco Pesenti Gritti 2006-09-13 13:53:27 +02:00
parent 5086f2835e
commit 016891ec9a
7 changed files with 1 additions and 294 deletions

View File

@ -6,8 +6,6 @@ from frame.BottomPanel import BottomPanel
from frame.RightPanel import RightPanel
from frame.TopPanel import TopPanel
from frame.PanelWindow import PanelWindow
from sugar.canvas.ScreenContainer import ScreenContainer
from sugar.canvas.Grid import Grid
class Frame:

View File

@ -1,51 +0,0 @@
import goocanvas
from sugar.canvas.GridLayout import GridGroup
from sugar.canvas.GridLayout import GridConstraints
class GridBox(GridGroup, goocanvas.Item):
__gtype_name__ = 'GridBox'
VERTICAL = 0
HORIZONTAL = 1
def __init__(self, direction, size, padding):
if direction == GridBox.VERTICAL:
GridGroup.__init__(self, 1, size)
else:
GridGroup.__init__(self, size, 1)
self._direction = direction
self._padding = padding
def _update_constraints(self, item, position):
if self._direction == GridBox.HORIZONTAL:
col = position
row = 0
else:
col = 0
row = position
constraints = GridConstraints(col, row, 1, 1, self._padding)
self._layout.set_constraints(item, constraints)
def do_add_child(self, item, position=-1):
if position == -1:
position = self.get_n_children()
self._update_constraints(item, position)
i = position
while i < self.get_n_children():
self._update_constraints(self.get_child(i), i + 1)
i += 1
GridGroup.do_add_child(self, item, position)
def do_remove_child(self, position):
GridGroup.do_remove_child(self, position)
i = position
while i < self.get_n_children():
self._update_constraints(self.get_child(i), i)
i += 1

View File

@ -1,138 +0,0 @@
import cairo
import gobject
import goocanvas
class GridConstraints:
def __init__(self, x, y, width, height, padding=0):
self.x = x
self.y = y
self.width = width
self.height = height
self.padding = padding
class GridLayout:
def __init__(self, cols=16, rows=12):
self._rows = rows
self._cols = cols
self._constraints = {}
def set_constraints(self, component, constraints):
self._constraints[component] = constraints
if isinstance(component, goocanvas.Item):
self.layout_canvas_item(component)
def _get_geometry(self, container, component):
constraints = self._constraints[component]
if constraints:
return self.get_bounds(container, constraints)
else:
return [0, 0, 0, 0]
def get_bounds(self, container, constraints):
w = container.props.width
h = container.props.height
padding = constraints.padding
x = constraints.x * w / self._cols + padding
y = constraints.y * h / self._rows + padding
width = constraints.width * w / self._cols - padding * 2
height = constraints.height * h / self._rows - padding * 2
width = max(0, width)
height = max(0, height)
return [x, y, width, height]
def layout_canvas_item(self, item):
group = item.get_parent()
if group == None:
return
[x, y, width, height] = self._get_geometry(group, item)
item.props.x = x
item.props.y = y
try:
item.props.width = width
item.props.height = height
except:
item.props.size = width
def layout_screen(self, screen):
for window in screen.get_windows():
[x, y, width, height] = self._get_geometry(screen, window)
window.move(int(x), int(y))
window.resize(int(width), int(height))
class GridGroup(goocanvas.Group):
__gproperties__ = {
'x' : (float, None, None, -10e6, 10e6, 800.0,
gobject.PARAM_READWRITE),
'y' : (float, None, None, -10e6, 10e6, 600.0,
gobject.PARAM_READWRITE),
'width' : (float, None, None, 0, 10e6, 800.0,
gobject.PARAM_READWRITE),
'height' : (float, None, None, 0, 10e6, 600.0,
gobject.PARAM_READWRITE)
}
def _update_position(self):
if self._x != 0 or self._y != 0:
matrix = cairo.Matrix(1, 0, 0, 1, 0, 0)
matrix.translate(self._x, self._y)
self.set_transform(matrix)
def _update_layout(self):
i = 0
while i < self.get_n_children():
self._layout.layout_canvas_item(self.get_child(i))
i += 1
def do_set_property(self, pspec, value):
if pspec.name == 'width':
self._width = value
self._update_layout()
elif pspec.name == 'height':
self._height = value
self._update_layout()
elif pspec.name == 'x':
self._x = value
self._update_position()
elif pspec.name == 'y':
self._y = value
self._update_position()
def do_get_property(self, pspec):
if pspec.name == 'width':
return self._width
elif pspec.name == 'height':
return self._height
elif pspec.name == 'x':
return self._x
elif pspec.name == 'x':
return self._x
def __init__(self, cols=-1, rows=-1):
self._x = 0
self._y = 0
self._width = 0
self._height = 0
goocanvas.Group.__init__(self)
if rows < 0 and cols < 0:
self._layout = GridLayout()
else:
self._layout = GridLayout(cols, rows)
self.connect('child-added', self.__child_added_cb)
def get_layout(self):
return self._layout
def __child_added_cb(self, group, position):
item = group.get_child(position)
self._layout.layout_canvas_item(item)

View File

@ -1,36 +0,0 @@
import goocanvas
from sugar.canvas.GridLayout import GridGroup
# FIXME model subclassing doesn't work in pygoocanvas
class GridModel:
def __init__(self, bg_color):
self._model = goocanvas.CanvasModelSimple()
self._width = 1200
self._height = 900
item = goocanvas.Rect(width=self._width, height=self._height,
line_width=0, fill_color=bg_color)
self._model.get_root_item().add_child(item)
self._root = GridGroup()
self._root.props.width = self._width
self._root.props.height = self._height
self._model.get_root_item().add_child(self._root)
def add(self, child):
self._root.add_child(child)
def get(self):
return self._model
def get_width(self):
return self._width
def get_bounds(self, constraints):
return self.get_layout().get_bounds(self._root, constraints)
def get_layout(self):
return self._root.get_layout()

View File

@ -1,25 +0,0 @@
import gtk
import goocanvas
class GridWindow(gtk.Window):
def __init__(self, model):
gtk.Window.__init__(self)
self._model = model
self._view = goocanvas.CanvasView()
self._view.set_model(model.get())
self.add(self._view)
self._view.show()
def scale_to_screen(self):
self._view.set_scale(float(gtk.gdk.screen_width()) /
float(self._model.get_width()))
def set_bounds(self, constraints):
bounds = self._model.get_bounds(constraints)
self._view.set_bounds(bounds[0], bounds[1],
bounds[2], bounds[3])
def get_view(self):
return self._view

View File

@ -5,10 +5,5 @@ sugar_PYTHON = \
CanvasBox.py \
Colors.py \
Grid.py \
GridBox.py \
GridLayout.py \
GridModel.py \
GridWindow.py \
IconItem.py \
IconColor.py \
ScreenContainer.py
IconColor.py

View File

@ -1,36 +0,0 @@
import gobject
import gtk
class ScreenContainer(gobject.GObject):
__gproperties__ = {
'width' : (float, None, None, 0, 10e6, 800.0,
gobject.PARAM_READABLE),
'height' : (float, None, None, 0, 10e6, 600.0,
gobject.PARAM_READABLE)
}
def __init__(self, windows, **kwargs):
self._width = gtk.gdk.screen_width()
self._height = gtk.gdk.screen_height()
self._windows = windows
gobject.GObject.__init__(self, **kwargs)
def do_set_property(self, pspec, value):
if pspec.name == 'width':
self._width = value
elif pspec.name == 'height':
self._height = value
def do_get_property(self, pspec):
if pspec.name == 'width':
return self._width
elif pspec.name == 'height':
return self._height
def set_layout(self, layout):
self._layout = layout
self._layout.layout_screen(self)
def get_windows(self):
return self._windows