pitivi r1157 - in branches/SOC_2008_BLEWIS: . pitivi/ui
- From: blewis svn gnome org
- To: svn-commits-list gnome org
- Subject: pitivi r1157 - in branches/SOC_2008_BLEWIS: . pitivi/ui
- Date: Wed, 9 Jul 2008 10:24:08 +0000 (UTC)
Author: blewis
Date: Wed Jul 9 10:24:07 2008
New Revision: 1157
URL: http://svn.gnome.org/viewvc/pitivi?rev=1157&view=rev
Log:
* pitivi/ui/util.py:
check in selection managment code taken from gst-editor.py
Modified:
branches/SOC_2008_BLEWIS/ChangeLog
branches/SOC_2008_BLEWIS/pitivi/ui/util.py
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 Wed Jul 9 10:24:07 2008
@@ -209,6 +209,119 @@
def unmake_resizable(item):
pass
+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 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)
+ """
+
+ def objects_under_marquee(event):
+ pos, size = normalize_rect(mouse_down[0], event_coords(
+ canvas, event))
+ bounds = goocanvas.Bounds(*(pos + point_sum(pos, size)))
+ selected = canvas.get_items_in_area(bounds, True, overlap,
+ containers)
+ if selected:
+ return set((found for found in selected if
+ found.get_data("selectable")))
+ return set()
+
+ def selection_start(item, target, event):
+ root.add_child(marquee)
+ cursor = event_coords(canvas, event)
+ set_pos(marquee, cursor)
+ selecting[0] = True
+ mouse_down[0] = cursor
+ set_pos(marquee, cursor)
+ set_size(marquee, (0, 0))
+ return True
+
+ def selection_end(item, target, event):
+ selecting[0] = False
+ marquee.remove()
+ prev = canvas.get_data("selected_objects")
+ selected = objects_under_marquee(event)
+ canvas.set_data("selected_objects", selected)
+ if changed_cb:
+ changed_cb(selected, prev.difference(selected))
+ return True
+
+ def selection_drag(item, target, event):
+ if selecting[0]:
+ pos_, size_ = normalize_rect(mouse_down[0],
+ event_coords(canvas, event))
+ set_size(marquee, size_)
+ set_pos(marquee, pos_)
+ return True
+ return False
+
+ canvas.set_data("selected_objects", set())
+ canvas.set_data("selection_callback", changed_cb)
+ containers = True
+ selecting = [False]
+ mouse_down = [None]
+ root = canvas.get_root_item()
+ root.connect("button_press_event", selection_start)
+ root.connect("button_release_event", selection_end)
+ root.connect("motion_notify_event", selection_drag)
class Text(goocanvas.Text):
'''adds the "missing" height property to goocanvas.Text'''
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]