pitivi r1129 - in branches/SOC_2008_BLEWIS: . pitivi/ui
- From: blewis svn gnome org
- To: svn-commits-list gnome org
- Subject: pitivi r1129 - in branches/SOC_2008_BLEWIS: . pitivi/ui
- Date: Mon, 2 Jun 2008 00:07:02 +0000 (UTC)
Author: blewis
Date: Mon Jun 2 00:07:01 2008
New Revision: 1129
URL: http://svn.gnome.org/viewvc/pitivi?rev=1129&view=rev
Log:
* pitivi/ui/test.py:
now tests HList rather than SimpleTimeline. now I can test the
timeline independently of PiTiVi, and yet still run PiTiVi.
* pitivi/ui/timelineobjects.py:
moved out list reordering code
* pitivi/ui/util.py:
movded list reordering into HList. made improvements to reordering
interaction. there is still a glitch you will notice if you drag the
end of the list. the object won't move until the mouse cursor reaches
the edge of the object
Modified:
branches/SOC_2008_BLEWIS/ChangeLog
branches/SOC_2008_BLEWIS/pitivi/ui/test.py
branches/SOC_2008_BLEWIS/pitivi/ui/timelineobjects.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 Mon Jun 2 00:07:01 2008
@@ -4,10 +4,8 @@
pygtk.require("2.0")
import gtk
import goocanvas
-import timelineobjects
from itertools import cycle
-from util import make_item, set_pos, center, Text, group
-
+from util import *
LABELS = "one two three four five six seven".split()
@@ -56,14 +54,15 @@
b = gtk.Button(text)
return goocanvas.Widget(widget=b, width=75,
height=50)
-
-t = timelineobjects.SimpleTimeline()
+c = goocanvas.Canvas()
+t = HList(c)
+c.get_root_item().add_child(t)
for word in LABELS:
t.add(make_box(word))
-
+t.reorderable = True
s = gtk.ScrolledWindow()
s.set_policy(gtk.POLICY_ALWAYS, gtk.POLICY_NEVER)
-s.add(t)
+s.add(c)
w = gtk.Window()
w.add(s)
w.show_all()
Modified: branches/SOC_2008_BLEWIS/pitivi/ui/timelineobjects.py
==============================================================================
--- branches/SOC_2008_BLEWIS/pitivi/ui/timelineobjects.py (original)
+++ branches/SOC_2008_BLEWIS/pitivi/ui/timelineobjects.py Mon Jun 2 00:07:01 2008
@@ -80,7 +80,8 @@
self.props.automatic_bounds = False
self.root = self.get_root_item()
- self.items = HList()
+ self.items = HList(self)
+ self.items.reorderable = True
self.root.add_child(self.items)
self.left = None
@@ -132,18 +133,16 @@
# self.childheight = int(DEFAULT_SIMPLE_ELEMENT_HEIGHT)
# self.childwidth = int(DEFAULT_SIMPLE_ELEMENT_WIDTH)
self.set_size_request(int(MINIMUM_WIDTH), int(MINIMUM_HEIGHT))
-#
-# # drag and drop
-# self.drag_dest_set(gtk.DEST_DEFAULT_DROP | gtk.DEST_DEFAULT_MOTION,
-# [dnd.FILESOURCE_TUPLE],
-# gtk.gdk.ACTION_COPY)
-# self.connect("drag-data-received", self._dragDataReceivedCb)
-# self.connect("drag-leave", self._dragLeaveCb)
-# self.connect("drag-motion", self._dragMotionCb)
-# self.slotposition = -1
-#
-# self.draggedelement = None
-#
+
+ # drag and drop
+ self.drag_dest_set(gtk.DEST_DEFAULT_DROP | gtk.DEST_DEFAULT_MOTION,
+ [dnd.FILESOURCE_TUPLE],
+ gtk.gdk.ACTION_COPY)
+ self.connect("drag-data-received", self._dragDataReceivedCb)
+ self.connect("drag-leave", self._dragLeaveCb)
+ self.connect("drag-motion", self._dragMotionCb)
+ self.slotposition = -1
+ self.draggedelement = None
def _request_size(self, item, prop):
self.set_size_request(int(self.items.width), int(
@@ -160,72 +159,11 @@
self.set_scale(self.scale)
return True
- def _child_drag_start(self, child):
- child.raise_(None)
- self.draging = child
- self.initial = child.props.x
- self._set_drag_thresholds()
- return True
-
- def _set_drag_thresholds(self):
- items = self.items
- index = items.index(self.draging)
- self.left = None
- self.right = None
- if index > 0:
- self.left = items.item_at(index - 1)
- self.l_thresh = (self.initial - self.left.props.width / 2)
- if index < len(items) - 1:
- self.right = items.item_at(index + 1)
- self.r_thresh = (self.right.props.x - self.draging.props.width -
- self.items.spacing + self.right.width / 2)
- #lthresh_line = goocanvas.Polyline(stroke_color="red",
- # points=goocanvas.Points(
- # [(self.l_thresh, 0), (self.l_thresh, items.height)]))
- #rthresh_line = goocanvas.Polyline(points=goocanvas.Points(
- # [(self.r_thresh, 0), (self.r_thresh, items.height)]))
- #self.root.add_child(lthresh_line)
- #self.root.add_child(rthresh_line)
-
- def _child_drag_end(self, child):
- self.left = None
- self.right = None
- self.initial = None
- self.draging = None
- self.items.tidy()
- return True
-
- def _swap_right(self):
- self._swap(self.draging, self.right)
-
- def _swap_left(self):
- self._swap(self.draging, self.left)
-
- def _swap(self, a, b):
- self.items.swap(a, b)
- self.items.tidy()
- self._set_drag_thresholds()
-
- def _child_drag(self, pos_):
- x, y = pos_
- x = (min(self.items.width, max(0, x)))
- if self.left:
- if x <= self.l_thresh:
- self._swap_left()
- if self.right:
- if x >= self.r_thresh:
- self._swap_right()
- return (x, 0)
-
def add(self, child):
self.items.add_child(child)
- make_dragable(self, child, self._child_drag, self._child_drag_start,
- self._child_drag_end)
def remove(self, child):
self.items.remove(child)
- unmake_dragable(self, child)
-
## Project callbacks
@@ -418,12 +356,12 @@
# ## Drag and Drop callbacks
#
-# def _dragMotionCb(self, unused_layout, unused_context, x, unused_y,
-# unused_timestamp):
-# # TODO show where the dragged item would go
+ def _dragMotionCb(self, unused_layout, unused_context, x, unused_y,
+ unused_timestamp):
+ # TODO show where the dragged item would go
# pos = self._getNearestSourceSlotPixels(x + (self.hadjustment.get_value()))
# rpos = self._getNearestSourceSlot(x + self.hadjustment.get_value())
-# gst.log("SimpleTimeline x:%d , source would go at %d" % (x, rpos))
+ gst.log("SimpleTimeline x:%d , source would go at %d" % (x, 0))
# if not pos == self.slotposition:
# if not self.slotposition == -1:
# # erase previous slot position
@@ -432,15 +370,15 @@
# self.slotposition = pos
# self._drawDragSlot()
#
-# def _dragLeaveCb(self, unused_layout, unused_context, unused_timestamp):
-# gst.log("SimpleTimeline")
+ def _dragLeaveCb(self, unused_layout, unused_context, unused_timestamp):
+ gst.log("SimpleTimeline")
# self._eraseDragSlot()
# self.slotposition = -1
# # TODO remove the drag emplacement
#
-# def _dragDataReceivedCb(self, unused_layout, context, x, y, selection,
-# targetType, timestamp):
-# gst.log("SimpleTimeline, targetType:%d, selection.data:%s" % (targetType, selection.data))
+ def _dragDataReceivedCb(self, unused_layout, context, x, y, selection,
+ targetType, timestamp):
+ gst.log("SimpleTimeline, targetType:%d, selection.data:%s" % (targetType, selection.data))
# if targetType == dnd.TYPE_PITIVI_FILESOURCE:
# uri = selection.data
# else:
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 Mon Jun 2 00:07:01 2008
@@ -104,6 +104,12 @@
def height(item):
return item.props.height
+def left(item):
+ return item.props.x
+
+def right(item):
+ return item.props.x + item.props.width
+
def center(item):
return point_sum(pos(item), point_mul(0.5, size(item)))
@@ -135,13 +141,13 @@
"""A callback which starts the drag operation of a dragable
object"""
item.set_data("dragging", True)
+ if start_cb:
+ start_cb(item)
if transform:
coords = transform(event_coords(canvas, event))
else:
coords = event_coords(canvas, event)
item.set_data("pendown", point_difference(pos(item), coords))
- if start_cb:
- start_cb(item)
return True
def drag_end(item, target, event, end_cb):
@@ -235,9 +241,6 @@
set_pos(child, point_sum(pos(self), pos_))
self.children[child] = pos_
- def _child_drag_transform(self, pos):
- return self.cur(min(0, max(self.width, pos[0])))
-
def add_child(self, child, p=None):
goocanvas.Group.add_child(self, child)
cw = child.connect("notify::width", self.update_width)
@@ -267,11 +270,24 @@
def __len__(self):
return len(self.order)
- def __init__(self, spacing=5.0, *args, **kwargs):
+ def __init__(self, canvas, spacing=5.0, *args, **kwargs):
SmartGroup.__init__(self, *args, **kwargs)
self.cur_pos = 0
self.spacing = spacing
self.order = []
+ self.canvas = canvas
+ 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)
@@ -282,10 +298,10 @@
def _set_reorderable(self, unused_object, unused_property):
if self.reorderable:
for child in self.order:
- self.make_reorderable(self, child)
+ self.make_reorderable(child)
else:
for child in self.order:
- self.unmake_reorderable(self, child)
+ self.unmake_reorderable(child)
def tidy(self):
cur = 0
@@ -303,13 +319,45 @@
def index(self, child):
return child.get_data("index")
- def reorder(self, new_order):
+ def _reorder(self, new_order):
order = []
for index in new_order:
order.append(self.order[index])
self.order = order
- def swap(self, a, b):
+ def reorder(self, new_order):
+ self._reorder(new_order)
+ self.tidy()
+
+ def _child_drag_start(self, child):
+ child.raise_(None)
+ self.draging = child
+ self.dwidth = width(self.draging)
+ self._set_drag_thresholds()
+ return True
+
+ def _set_drag_thresholds(self):
+ index = self.draging.get_data("index")
+ self.left = None
+ self.right = None
+ if index > 0:
+ self.left = self.order[index - 1]
+ self.l_thresh = (right(self.left) - 0.5 * width(self.left)
+ + self.spacing)
+ if index < len(self.order) - 1:
+ self.right = self.order[index + 1]
+ self.r_thresh = (left(self.right) + 0.5 * width(self.right)
+ - width(self.draging) + self.spacing)
+
+ def _child_drag_end(self, child):
+ self.left = None
+ self.right = None
+ self.initial = None
+ self.draging = None
+ self.tidy()
+ return True
+
+ def _swap(self, a, b):
a_index = a.get_data("index")
b_index = b.get_data("index")
self.order[a_index] = b
@@ -317,6 +365,31 @@
a.set_data("index", b_index)
b.set_data("index", a_index)
+ def _child_drag(self, pos_):
+ x, y = pos_
+ x = (min(self.width - width(self.draging), max(0, x)))
+ if self.left:
+ if x <= self.l_thresh:
+ self._swap(self.draging, self.left)
+ if self.right:
+ self.left.x = (left(self.right) -
+ width(self.left) - self.spacing)
+ else:
+ self.left.x = self.width - width(self.left)
+ self._set_drag_thresholds()
+ if self.right:
+ if x >= self.r_thresh:
+ self._swap(self.draging, self.right)
+ if self.left:
+ self.right.x = right(self.left) + self.spacing
+ else:
+ self.right.x = 0
+ self._set_drag_thresholds()
+ return self.cur(x)
+
+ def swap(self, a, b):
+ self._swap(a, b)
+
def remove_child(self, child):
SmartGroup.remove_child(self, child)
self.order.remove(child)
@@ -324,8 +397,9 @@
self.unmake_reorderable(child)
self.tidy()
- def make_reordrable(self, child):
- make_dragable(child, self._child_drag)
+ def make_reorderable(self, child):
+ make_dragable(self.canvas, child, self._child_drag,
+ self._child_drag_start, self._child_drag_end)
def unmake_reorderable(self, child):
unmake_dragble(child)
@@ -355,8 +429,11 @@
def cur(self, value):
return (0, value)
+ def position(self, child):
+ return child.props.y
+
def dimension(self, child):
- return height(child)
+ return child.props.height
class HList(List):
__gtype_name__ = 'HList'
@@ -367,7 +444,10 @@
def cur(self, value):
return (value, 0)
+ def position(self, child):
+ return child.props.x
+
def dimension(self, child):
- return width(child)
+ return child.props.width
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]