pitivi r1141 - in branches/SOC_2008_BLEWIS: . pitivi/ui
- From: blewis svn gnome org
- To: svn-commits-list gnome org
- Subject: pitivi r1141 - in branches/SOC_2008_BLEWIS: . pitivi/ui
- Date: Sat, 7 Jun 2008 22:40:08 +0000 (UTC)
Author: blewis
Date: Sat Jun 7 22:40:08 2008
New Revision: 1141
URL: http://svn.gnome.org/viewvc/pitivi?rev=1141&view=rev
Log:
reviewed by: <delete if not using a buddy>
* pitivi/ui/test.py:
Tweaked test.py to handle changes to util.py
* pitivi/ui/testcomplex.py:
Contains ComplexTrack, a goocanvas item which manages objects in a
composition.
* pitivi/ui/util.py:
Added a "background" property to SmartGroup, which is a goocanvas item
that tracks the size and position of the items in the group. Can be
used to implement backgrounds or outlines for groups of items.
Added:
branches/SOC_2008_BLEWIS/pitivi/ui/testcomplex.py
Modified:
branches/SOC_2008_BLEWIS/ChangeLog
branches/SOC_2008_BLEWIS/pitivi/ui/test.py
branches/SOC_2008_BLEWIS/pitivi/ui/util.py
Modified: branches/SOC_2008_BLEWIS/pitivi/ui/test.py
==============================================================================
--- branches/SOC_2008_BLEWIS/pitivi/ui/test.py (original)
+++ branches/SOC_2008_BLEWIS/pitivi/ui/test.py Sat Jun 7 22:40:08 2008
@@ -65,7 +65,7 @@
height=50), e)
c = goocanvas.Canvas()
-t = HList(c)
+t = HList(canvas=c)
c.get_root_item().add_child(t)
for word in LABELS:
t.add(make_box(word))
Added: branches/SOC_2008_BLEWIS/pitivi/ui/testcomplex.py
==============================================================================
--- (empty file)
+++ branches/SOC_2008_BLEWIS/pitivi/ui/testcomplex.py Sat Jun 7 22:40:08 2008
@@ -0,0 +1,198 @@
+
+import gobject
+gobject.threads_init()
+import pygtk
+pygtk.require("2.0")
+import gtk
+import goocanvas
+import os
+from itertools import cycle
+from util import *
+
+SOURCES = (
+ ("source1", 300),
+ ("source2", 200),
+ ("source3", 50),
+)
+
+box = (
+ goocanvas.Rect,
+ {
+ "height" : 30,
+ "stroke_color" : "black",
+ "fill_color_rgba" : 0x55663388
+ },
+ {}
+)
+
+label = (
+ Text,
+ {
+ "font" : "Sans 9",
+ "text" : "will be replaced",
+ "fill_color_rgba" : 0x66AA66FF,
+ "anchor" : gtk.ANCHOR_CENTER
+ },
+ {}
+)
+
+class TestComposition(gobject.GObject):
+ __gtype_name__ = "TestComposition"
+ __gsignals__ = {
+ "source-added" : (gobject.SIGNAL_RUN_LAST,
+ gobject.TYPE_NONE,
+ (gobject.TYPE_PYOBJECT, )),
+ "source-removed" : (gobject.SIGNAL_RUN_LAST,
+ gobject.TYPE_NONE,
+ (gobject.TYPE_PYOBJECT, )),
+ }
+
+ def __init__(self, *args, **kwargs):
+ gobject.GObject.__init__(self, *args, **kwargs)
+
+ def addSource(self, source, position):
+ self.emit("source-added", source)
+
+ def removeSource(self, source):
+ self.emit("source-removed", source)
+
+class TestTimelineObject(gobject.GObject):
+ __gtype_name__ = "TestObject"
+ __gsignals__ = {
+ "start-duration-changed" : (gobject.SIGNAL_RUN_LAST,
+ gobject.TYPE_NONE,
+ (gobject.TYPE_PYOBJECT, gobject.TYPE_PYOBJECT, )),
+ }
+
+ duration = gobject.property(type=int)
+ start = gobject.property(type=int)
+
+ class Factory:
+ name=None
+
+ def __init__(self, name, start, duration):
+ gobject.GObject.__init__(self)
+ self.start = start
+ self.duration = duration
+ self.factory = self.Factory()
+ self.factory.name=name
+
+ def setStartDurationTime(self, start=-1, duration=-1):
+ if start != -1:
+ self.start = start
+ if duration != -1:
+ self.duration = duration
+ self.emit("start-duration-changed", self.start, self.duration)
+
+#class ComplexTimelineObject(goocanvas.Rect):
+#
+# def source_signals = (("start-duration-changed", self._set_size_position),)
+#
+# def __init__(self, source=None, *args, **kwargs):
+# goocanvas.Rect.__init__(self, *args, **kwargs)
+# if self.source:
+# self.set_source(source)
+#
+# def _connect(self, source):
+# self.sigids = [source.connect(sig, hdlr) for sig, hdlr
+# in self.source_signals]
+#
+# def _disconnect(self):
+# for sig in self.sigids:
+# self.source.disconnect(sig)
+#
+# def set_source(self, source):
+# if self.source:
+# self._disconnect()
+# self.source = source
+# if self.source:
+# self._connect(source)
+# self._set_size_position(source, source.props.start,
+# source.props.duration)
+#
+# def _set_size_position(self, source, start, duration):
+# pass
+
+class ComplexTrack(SmartGroup):
+ __gtype_name__ = 'ComplexTrack'
+
+ def __init__(self, *args, **kwargs):
+ SmartGroup.__init__(self, *args, **kwargs)
+ self.widgets = {}
+ self.elements = {}
+ self.sig_ids = None
+ self.comp = None
+
+ def set_composition(self, comp):
+ if self.sig_ids:
+ for sig in self.sig_ids:
+ comp.disconnect(sig)
+ self.comp = comp
+ if comp:
+ added = comp.connect("source-added", self._objectAdded)
+ removed = comp.connect("source-removed", self._objectRemoved)
+ self.sig_ids = (added, removed)
+
+ def _objectAdded(self, timeline, element):
+ w = self.make_element_widget(element)
+ self.widgets[element] = w
+ self.elements[w] = element
+ self.add_child(w)
+
+ def _objectRemoved(self, timeline, element):
+ w = self.widgets[element]
+ self.remove(w)
+ del self.widgets[element]
+ del self.element[w]
+
+ def start_duration_cb(self, obj, start, duration, widget):
+ widget.props.width = duration
+ self.set_child_pos(widget, (start, 0))
+
+ def _child_mouse_down(self, item, target, event):
+ item.raise_(None)
+
+ def _child_mouse_up(self, item, target, event):
+ pass
+
+ def drag_cb(self, item, target, event, element):
+ if item.get_data("dragging"):
+ x,y = point_sum(item.get_data("pendown"), event_coords(self.canvas,
+ event))
+ element.setStartDurationTime(max(x, 0), -1)
+ return True
+ return False
+
+ def make_element_widget(self, element):
+ text = make_item(label)
+ text.props.text = os.path.basename(element.factory.name)
+ rect = make_item(box)
+ rect.props.width = element.props.duration
+ rect.props.x = element.props.start
+ set_pos(text, center(rect))
+ ret = group(rect, text)
+ element.connect("start-duration-changed", self.start_duration_cb, ret)
+ ret.connect("button-press-event", drag_start, self.canvas, None, None)
+ ret.connect("button-release-event", drag_end, None)
+ ret.connect("motion-notify-event", self.drag_cb, element)
+ return ret
+
+c = goocanvas.Canvas()
+t = ComplexTrack(c)
+model = TestComposition()
+t.set_composition(model)
+c.get_root_item().add_child(t)
+cur = 0
+for name, duration in SOURCES:
+ model.addSource(TestTimelineObject(name, cur, duration), None)
+ cur += duration
+s = gtk.ScrolledWindow()
+s.set_policy(gtk.POLICY_ALWAYS, gtk.POLICY_NEVER)
+s.add(c)
+w = gtk.Window()
+w.add(s)
+w.show_all()
+w.connect("destroy", gtk.main_quit)
+gtk.main()
+
+
Modified: branches/SOC_2008_BLEWIS/pitivi/ui/util.py
==============================================================================
--- branches/SOC_2008_BLEWIS/pitivi/ui/util.py (original)
+++ branches/SOC_2008_BLEWIS/pitivi/ui/util.py Sat Jun 7 22:40:08 2008
@@ -25,6 +25,12 @@
## GooCanvas Convenience Functions
+def null_true(*args):
+ return True
+
+def null_false(*args):
+ return False
+
def event_coords(canvas, event):
"""returns the coordinates of an event"""
return canvas.convert_from_pixels(canvas.props.scale_x * event.x,
@@ -191,6 +197,13 @@
for sig in signals:
item.disconnect(sig)
+def make_resizable(horizontal, vertical, canvas, item):
+ pass
+
+def unmake_resizable(item):
+ pass
+
+
class Text(goocanvas.Text):
'''adds the "missing" height property to goocanvas.Text'''
#TODO: width/height are dumy props in this class...they
@@ -214,18 +227,34 @@
width = gobject.property(type=float, default=0)
height = gobject.property(type=float, default=0)
- def __init__(self, *args, **kwargs):
+ def __init__(self, canvas=None, background=None, *args, **kwargs):
goocanvas.Group.__init__(self, *args, **kwargs)
self.children = {}
self.signals = {}
self.connect("notify::x", self.move_x_children)
self.connect("notify::y", self.move_y_children)
+ self.set_canvas(canvas)
+ self.background = None
+ self.set_background(background)
+
+ def set_background(self, bg):
+ if self.background:
+ self.background.remove()
+ goocanvas.Group.add_child(self, bg, 0)
+ self.background = bg
+
+ def set_canvas(self, canvas):
+ self.canvas = canvas
def move_x_children(self, object, prop):
+ if self.background:
+ self.background.props.x = self.x
for child, (x, y) in self.children.items():
child.set_property('x', self.x + x)
def move_y_children(self, object, prop):
+ if self.background:
+ self.background.props.y = self.y
for child, (x, y) in self.children.items():
child.set_property('y', self.y + y)
@@ -234,12 +263,16 @@
return (c.get_property('width') + p[0])
widths = (compute(c, p) for c, p in self.children.items())
self.width = max(widths) if len(self.children) else float(0)
+ if self.background:
+ self.background.props.width = self.width
def update_height(self, obj, prop):
def compute(c, p):
return (c.get_property('height') + p[1])
heights = (compute(c, p) for c, p in self.children.items())
self.height = max(heights) if len(self.children) else float(0)
+ if self.background:
+ self.background.props.height = self.height
def set_child_pos(self, child, pos_):
set_pos(child, point_sum(pos(self), pos_))
@@ -268,31 +301,24 @@
class List(SmartGroup):
__gytpe_name__ = 'List'
- spacing = gobject.property(type=float)
+ spacing = gobject.property(type=float, default=5.0)
reorderable = gobject.property(type=bool, default=False)
def __len__(self):
return len(self.order)
- def __init__(self, canvas, spacing=5.0, *args, **kwargs):
+ def __init__(self, *args, **kwargs):
SmartGroup.__init__(self, *args, **kwargs)
self.cur_pos = 0
- self.spacing = spacing
self.order = []
- self.canvas = canvas
+ if kwargs.has_key("spacing"):
+ self.spacing = kwargs["spacing"]
self.draging = None
self.right = None
self.left = None
self.initial = None
self.l_thresh = None
self.r_thresh = None
- self.lthresh_line = goocanvas.Polyline()
- self.lthresh_line.props.stroke_color = "blue"
- self.rthresh_line = goocanvas.Polyline()
- self.rthresh_line.props.stroke_color = "red"
- canvas.get_root_item().add_child(self.lthresh_line)
- canvas.get_root_item().add_child(self.rthresh_line)
-
self.connect("notify::spacing", self._set_spacing)
self.connect("notify::reorderable", self._set_reorderable)
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]