pitivi r1394 - trunk/pitivi/ui
- From: edwardrv svn gnome org
- To: svn-commits-list gnome org
- Subject: pitivi r1394 - trunk/pitivi/ui
- Date: Fri, 28 Nov 2008 17:34:55 +0000 (UTC)
Author: edwardrv
Date: Fri Nov 28 17:34:55 2008
New Revision: 1394
URL: http://svn.gnome.org/viewvc/pitivi?rev=1394&view=rev
Log:
pulled out useful code from ui/util.py and removed module
Added:
trunk/pitivi/ui/list.py
trunk/pitivi/ui/selection.py
Removed:
trunk/pitivi/ui/util.py
Added: trunk/pitivi/ui/list.py
==============================================================================
--- (empty file)
+++ trunk/pitivi/ui/list.py Fri Nov 28 17:34:55 2008
@@ -0,0 +1,197 @@
+
+class List(SmartGroup):
+ __gytpe_name__ = 'List'
+
+ spacing = gobject.property(type=float, default=5.0)
+ reorderable = gobject.property(type=bool, default=False)
+
+ def __len__(self):
+ return len(self.order)
+
+ def __iter__(self):
+ return self.order.__iter__()
+
+ def __init__(self, *args, **kwargs):
+ SmartGroup.__init__(self, *args, **kwargs)
+ self.cur_pos = 0
+ self.order = []
+ 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.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(child)
+ else:
+ for child in self.order:
+ self.unmake_reorderable(child)
+
+ def end(self, child):
+ return self.position(child) + self.dimension(child)
+
+ def tidy(self):
+ cur = 0
+ i = 0
+ for child in self.order:
+ self.set_child_pos(child, self.cur(cur))
+ child.set_data("index", i)
+ cur += self.spacing + self.dimension(child)
+ i += 1
+ self.cur_pos = cur
+ if self.draging:
+ self._set_drag_thresholds()
+
+ def item_at(self, index):
+ return self.order[index]
+
+ def index(self, child):
+ return child.get_data("index")
+
+ def point_to_index(self, point):
+ x, y = point
+ bounds = goocanvas.Bounds(x, y, x, y)
+ items = self.canvas.get_items_in_area(bounds, True, True, True)
+ if items:
+ return [i for i in items if i.get_data("index")][0]
+ return None
+
+ def _reorder(self, new_order):
+ order = []
+ for index in new_order:
+ order.append(self.order[index])
+ self.order = order
+
+ 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 = self.dimension(child)
+ 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 = (self.end(self.left) - 0.5 * self.dimension(self.left)
+ + self.spacing)
+ if index < len(self.order) - 1:
+ self.right = self.order[index + 1]
+ self.r_thresh = (self.position(self.right) + 0.5 * self.dimension(self.right)
+ - self.dimension(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
+ self.order[b_index] = a
+ a.set_data("index", b_index)
+ b.set_data("index", a_index)
+ self.tidy()
+ return True
+
+ def _child_drag(self, pos_):
+ coord = self.coord(pos_)
+ coord = (min(self.dimension(self) - self.dimension(self.draging), max(0, coord)))
+ if self.left:
+ if coord <= self.l_thresh:
+ self.swap(self.draging, self.left)
+ if self.right:
+ if coord >= self.r_thresh:
+ self.swap(self.draging, self.right)
+ return self.cur(coord)
+
+ def remove_child(self, child):
+ SmartGroup.remove_child(self, child)
+ self.order.remove(child)
+ if self.reorderable:
+ self.unmake_reorderable(child)
+ self.tidy()
+
+ def remove_all(self):
+ while len(self.order):
+ self.remove_child(self.order[0])
+
+ 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_dragable(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) - 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(index, child)
+ self.tidy()
+
+class VList(List):
+ __gtype_name__ = 'VList'
+
+ def __init__(self, *args, **kwargs):
+ List.__init__(self, *args, **kwargs)
+
+ def cur(self, value):
+ return (0, value)
+
+ def coord(self, point):
+ return point[1]
+
+ def position(self, child):
+ return child.props.y
+
+ def dimension(self, child):
+ return child.props.height
+
+class HList(List):
+ __gtype_name__ = 'HList'
+
+ def __init__(self, *args, **kwargs):
+ List.__init__(self, *args, **kwargs)
+
+ def coord(self, point):
+ return point[0]
+
+ def cur(self, value):
+ return (value, 0)
+
+ def position(self, child):
+ return child.props.x
+
+ def dimension(self, child):
+ return child.props.width
+
Added: trunk/pitivi/ui/selection.py
==============================================================================
--- (empty file)
+++ trunk/pitivi/ui/selection.py Fri Nov 28 17:34:55 2008
@@ -0,0 +1,117 @@
+
+def normalize_rect(mouse_down, cur_pos):
+ """Given two points, representing the upper left and bottom right
+ corners of a rectangle (the order is irrelevant), return the tuple
+ ((x,y), (width, height))"""
+ w, h = point_difference(cur_pos, mouse_down)
+ x, y = mouse_down
+
+ if w < 0:
+ w = abs(w)
+ x -= w
+ if h < 0:
+ h = abs(h)
+ y -= h
+
+ return (x, y), (w, h)
+
+def object_select_cb(item, target, event, canvas, changed_cb):
+ prev = canvas.get_data("selected_objects")
+ if item in prev:
+ return
+ if (event.state & gtk.gdk.SHIFT_MASK):
+ prev.add(item)
+ changed_cb(prev, set())
+ else:
+ selected = set()
+ selected.add(item)
+ canvas.set_data("selected_objects", selected)
+ changed_cb(selected, prev)
+ return False
+
+def make_selectable(canvas, object):
+ """Make the object selectable with respect to canvas. This means
+ that the item will be included in the current selection, and that
+ clicking the object will select it. Must be called before
+ make_dragable, as it will block the action of this handler"""
+ object.set_data("selectable", True)
+ object.connect("button_press_event", object_select_cb, canvas,
+ canvas.get_data("selection_callback"))
+
+def delete_from_selection(canvas, item):
+ selected = canvas.get_data("selected_objects")
+ set_selection(canvas, selected - set([item]))
+
+def set_selection(canvas, new):
+ prev = canvas.get_data("selected_objects")
+ deselected = prev - new
+ canvas.set_data("selected_objects", new)
+ canvas.get_data("selection_callback")(new, deselected)
+
+def objects_under_marquee(event, canvas, overlap):
+ pos, size = normalize_rect(canvas.mouse_down, event_coords(
+ canvas, event))
+ bounds = goocanvas.Bounds(*(pos + point_sum(pos, size)))
+ selected = canvas.get_items_in_area(bounds, True, overlap,
+ True)
+ if selected:
+ return set((found for found in selected if
+ found.get_data("selectable")))
+ return set()
+
+def selection_start(item, target, event, canvas, marquee):
+ root = canvas.get_root_item()
+ root.add_child(marquee)
+ cursor = event_coords(canvas, event)
+ set_pos(marquee, cursor)
+ canvas.selecting = True
+ canvas.mouse_down = cursor
+ set_pos(marquee, cursor)
+ set_size(marquee, (0, 0))
+ return True
+
+def selection_end(item, target, event, canvas, marquee, overlap, changed_cb):
+ canvas.selecting = False
+ marquee.remove()
+ prev = canvas.get_data("selected_objects")
+ selected = objects_under_marquee(event, canvas, overlap)
+ canvas.set_data("selected_objects", selected)
+ if changed_cb:
+ changed_cb(selected, prev.difference(selected))
+ return True
+
+def selection_drag(item, target, event, canvas, marquee):
+ if canvas.selecting:
+ pos_, size_ = normalize_rect(canvas.mouse_down,
+ event_coords(canvas, event))
+ set_size(marquee, size_)
+ set_pos(marquee, pos_)
+ return True
+ return False
+
+
+def manage_selection(canvas, marquee, overlap, changed_cb=None):
+ """Keep track of the current selection in canvas, including
+ * providing a rectangular selection marquee
+ * tracking specific canvas objects
+ Note: objects must be made selectable by calling make_selectable()
+ on the object before they will be reported by any selection changes
+ - overlap: True if you want items that merely intersect the
+ data field to be considered selected.
+ - marquee: a goocanvas.Rectangle() to be used as the selection
+ marquee (really, any canvas item with x, y, width, height
+ properties). This object should not already be added to the
+ canvas.
+ - changed_cb: a callback with signature (selected, deselected)
+ """
+
+ canvas.selecting = False
+ canvas.mouse_down = None
+ canvas.set_data("selected_objects", set())
+ canvas.set_data("selection_callback", changed_cb)
+ root = canvas.get_root_item()
+ root.connect("button_press_event", selection_start, canvas, marquee)
+ root.connect("button_release_event", selection_end, canvas, marquee, overlap, changed_cb)
+ root.connect("motion_notify_event", selection_drag, canvas, marquee)
+
+
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]