pitivi r1126 - in branches/SOC_2008_BLEWIS: . pitivi/ui



Author: blewis
Date: Sun Jun  1 00:52:42 2008
New Revision: 1126
URL: http://svn.gnome.org/viewvc/pitivi?rev=1126&view=rev

Log:
* pitivi/ui/test.py:
now imports timelineobjects.py
* pitivi/ui/timelineobjects.py:
SimpleTimeline replaced with new class, basic UI interaction done
* pitivi/ui/util.py:
changes to make SimpleTimeline code work better


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	Sun Jun  1 00:52:42 2008
@@ -57,7 +57,7 @@
     return goocanvas.Widget(widget=b, width=75,
         height=50)
 
-t = timeline.SimpleTimeline()
+t = timelineobjects.SimpleTimeline()
 for word in LABELS:
     t.add(make_box(word))
 

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	Sun Jun  1 00:52:42 2008
@@ -29,18 +29,18 @@
 import gtk
 import gst
 import pango
-import pitivi.instance as instance
-from pitivi.timeline.source import TimelineFileSource, TimelineSource, TimelineBlankSource
-from pitivi.timeline.effects import TimelineTransition
-from pitivi.timeline.objects import MEDIA_TYPE_AUDIO, MEDIA_TYPE_VIDEO
-from pitivi.configure import get_pixmap_dir
-import pitivi.dnd as dnd
-from pitivi.bin import SmartFileBin
-from pitivi.signalgroup import SignalGroup
-from pitivi.thumbnailer import Thumbnailer
-from pitivi.ui.slider import PipelineSlider
-from sourcefactories import beautify_length
-from gettext import gettext as _
+#import pitivi.instance as instance
+#from pitivi.timeline.source import TimelineFileSource, TimelineSource, TimelineBlankSource
+#from pitivi.timeline.effects import TimelineTransition
+#from pitivi.timeline.objects import MEDIA_TYPE_AUDIO, MEDIA_TYPE_VIDEO
+#from pitivi.configure import get_pixmap_dir
+#import pitivi.dnd as dnd
+#from pitivi.bin import SmartFileBin
+#from pitivi.signalgroup import SignalGroup
+#from pitivi.thumbnailer import Thumbnailer
+#from pitivi.ui.slider import PipelineSlider
+#from sourcefactories import beautify_length
+#from gettext import gettext as _
 
 import goocanvas
 from util import *
@@ -87,14 +87,12 @@
         self.l_thresh = None
         self.right = None
         self.r_thresh = None
-        self.drag_sigid = None
+        self.initial = None
 
         self.connect("size_allocate", self._size_allocate)
         self.items.connect("notify::width", self._request_size)
         self.items.connect("notify::height", self._request_size)
 
-        self.signals = {}
-
         self.scale = 1.0
 
     def _request_size(self, item, prop):
@@ -112,61 +110,81 @@
             self.set_scale(self.scale)
         return True
 
-    def _child_drag_start(self, child, unused, event):
+    def _child_drag_start(self, child):
         child.raise_(None)
-        self.drag_sigid = child.connect("motion_notify_event", 
-            self._child_drag)
-        x, y = event_coords(self, event)
-        self.pen_down = child.props.x - (x * self.scale)
-        self._set_drag_thresholds(child)
+        self.draging = child
+        self.initial = child.props.x
+        self._set_drag_thresholds()
         return True
 
-    def _set_drag_thresholds(self, item):
-        index = self.items.index(item)
+    def _set_drag_thresholds(self):
+        items = self.items
+        index = items.index(self.draging)
+        self.left = None
+        self.right = None
         if index > 0:
-            self.left = self.items.item_at(index - 1)
-            self.l_thresh = (self.left.props.x -
-                self.left.props.width / 2)
-        if index < len(self.items):
-            self.right = self.items.item_at(index + 1)
-            self.r_thresh = (self.right.props.x + 
-                self.right.props.width / 2 - item.props.width) 
+            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, target, event):
-        self.items.tidy()
-        if self.drag_sigid:
-            child.disconnect(self.drag_sigid)
-        self.drag_sigid = None
+    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):
+        #if self.left:
+        #    self.right.props.x = (self.left.x + self.left.width + 
+        #    self.items.spacing)
+        #else:
+        #    self.right.props.x = 0
+        self._swap(self.draging, self.right)
+
+    def _swap_left(self):
+        #if self.right:
+        #    self.left.props.x = (self.right.props.x + self.right.props.width 
+        #       + self.items.spacing)
+        #else:
+        #    self.right.props.x = self.items.width - self.right.props.width
+        self._swap(self.draging, self.left)
 
-    def _child_drag(self, child, unused, event):
-        x, y = event_coords(self, event)
-        x = (min(self.items.width, max(0, self.scale * x +
-            self.pen_down)))
-        child.props.x = x
+    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.items.swap(child, self.left)
-                self._set_drag_thresholds(child)
+                self._swap_left()
         if self.right:
             if x >= self.r_thresh:
-                self.items.swap(child, self.right)
-                self._set_drag_thresholds(child)
-
-        return True
+                self._swap_right()
+        return (x, 0)
 
     def add(self, child):
         self.items.add_child(child)
-        dn = child.connect("button_press_event", self._child_drag_start)
-        up = child.connect("button_release_event", self._child_drag_end)
-        self.signals[child] = (up, dn)
+        make_dragable(self, child, self._child_drag, self._child_drag_start,
+            self._child_drag_end)
 
     def remove(self, child):
         self.items.remove(child)
-        for sig in self.signals[child]:
-            child.disconnect(sig)
+        unmake_dragable(self, child)
 
 #class SimpleTimeline(gtk.Layout):
 #    """ Simple Timeline representation """

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	Sun Jun  1 00:52:42 2008
@@ -27,7 +27,8 @@
 
 def event_coords(canvas, event):
     """returns the coordinates of an event"""
-    return canvas.convert_from_pixels(event.x, event.y)
+    sx, sy = (canvas.props.scale_x, canvas.props.scale_y)
+    return canvas.convert_from_pixels(sx * event.x, sy * event.y)
 
 def point_difference(p1, p2):
     """Returns the 2-dvector difference p1 - p2"""
@@ -136,7 +137,6 @@
     item.set_data("dragging", True)
     if transform:
         coords = transform(event_coords(canvas, event))
-        print coords
     else:
         coords = event_coords(canvas, event)
     item.set_data("pendown", point_difference(pos(item), coords))
@@ -169,10 +169,17 @@
     after make_selectable, or it will prevent the latter from working.
     """
     item.set_data("dragging", False)
-    item.connect("button_press_event", drag_start, canvas, start, transform)
-    item.connect("button_release_event", drag_end, end)
-    item.connect("motion_notify_event", translate_item_group, canvas,
+    dwn = item.connect("button_press_event", drag_start, canvas, start, transform)
+    up = item.connect("button_release_event", drag_end, end)
+    mv = item.connect("motion_notify_event", translate_item_group, canvas,
         transform)
+    item.set_data("drag_sigids", (up, dwn, mv))
+
+def unmake_dragable(item):
+    signals = item.get_data("drag_sigids")
+    if signals:
+        for sig in signals:
+            item.disconnect(sig)
 
 class Text(goocanvas.Text):
     '''adds the "missing" height property to goocanvas.Text'''
@@ -228,6 +235,9 @@
         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)
@@ -251,8 +261,8 @@
 class List(SmartGroup):
     __gytpe_name__ = 'List'
 
-    #TODO: changing this property should force update of list
     spacing = gobject.property(type=float)
+    reorderable = gobject.property(type=bool, default=False)
 
     def __len__(self):
         return len(self.order)
@@ -263,6 +273,20 @@
         self.spacing = spacing
         self.order = []
 
+        self.connect("notify::spacing", self._set_spacing)
+        self.connect("notify::reorderable", self._set_reorderable)
+    
+    def _set_spacing(self, unused_object, unused_property):
+        self.tidy()
+
+    def _set_reorderable(self, unused_object, unused_property):
+        if self.reorderable:
+            for child in self.order:
+                self.make_reorderable(self, child)
+        else:
+            for child in self.order:
+                self.unmake_reorderable(self, child)
+
     def tidy(self):
         cur = 0
         i = 0
@@ -284,32 +308,42 @@
         for index in new_order:
             order.append(self.order[index])
         self.order = order
-        self.tidy()
 
     def swap(self, a, b):
         a_index = a.get_data("index")
         b_index = b.get_data("index")
         self.order[a_index] = b
         self.order[b_index] = a
-
+        a.set_data("index", b_index)
+        b.set_data("index", a_index)
 
     def remove_child(self, child):
         SmartGroup.remove_child(self, child)
         self.order.remove(child)
+        if self.reorderable:
+            self.unmake_reorderable(child)
         self.tidy()
+    
+    def make_reordrable(self, child):
+        make_dragable(child, self._child_drag)
+
+    def unmake_reorderable(self, child):
+        unmake_dragble(child)
 
     def add_child(self, child):
         SmartGroup.add_child(self, child, self.cur(self.cur_pos))
         self.cur_pos += self.spacing + self.dimension(child)
         self.order.append(child)
-        child.set_data("index", len(self.order))
+        child.set_data("index", len(self.order) - 1)
+        if self.reorderable:
+            self.make_reorderable(child)
 
     def add(self, child):
         self.add_child(child)
 
     def insert_child(self, child, index):
         SmartGroup.add_child(self, child, self.cur(self.cur_pos))
-        self.order.insert(child, index)
+        self.order.insert(index, child)
         self.tidy()
 
 class VList(List):



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]