[pitivi: 3/8] timeline.timeline: move timeline selection methods to selection class
- From: Edward Hervey <edwardrv src gnome org>
- To: svn-commits-list gnome org
- Subject: [pitivi: 3/8] timeline.timeline: move timeline selection methods to selection class
- Date: Sun, 3 May 2009 03:02:49 -0400 (EDT)
commit 20c14464645035294c3469de9fdf1c036d4379ae
Author: Brandon Lewis <brandon_lewis berkeley edu>
Date: Tue Apr 21 19:16:15 2009 -0700
timeline.timeline: move timeline selection methods to selection class
---
pitivi/timeline/timeline.py | 69 ++++++++++++++++++++++++++++---------------
pitivi/ui/timeline.py | 6 ++--
2 files changed, 48 insertions(+), 27 deletions(-)
diff --git a/pitivi/timeline/timeline.py b/pitivi/timeline/timeline.py
index 84c50cd..b2537b2 100644
--- a/pitivi/timeline/timeline.py
+++ b/pitivi/timeline/timeline.py
@@ -279,9 +279,40 @@ class TimelineObject(object, Signallable, Loggable):
except ValueError:
raise TimelineError()
-class Selection(object):
+class Selection(object, Signallable):
- pass
+ __signals__ = {
+ "selection-changed" : []
+ }
+
+ def __init__(self):
+ self.selected = set([])
+
+ def setToObj(self, obj, mode):
+ self.setTo(set([obj]), mode)
+
+ def setTo(self, selection, mode):
+ selection = set([obj.timeline_object for obj in selection])
+ old_selection = self.selected
+ if mode == SELECT:
+ self.selected = selection
+ elif mode == SELECT_ADD:
+ self.selected.update(selection)
+ elif mode == UNSELECT:
+ self.selected.difference(selection)
+
+ for obj in self.selected:
+ obj.selected = True
+ for obj in old_selection - self.selected:
+ obj.selected = False
+
+ self.emit("selection-changed")
+
+ def __len__(self):
+ return len(self.selected)
+
+ def __iter__(self):
+ return iter(self.selected)
class LinkEntry(object):
def __init__(self, start, duration):
@@ -448,7 +479,8 @@ class Timeline(object ,Signallable, Loggable):
def __init__(self):
Loggable.__init__(self)
self.tracks = []
- self.selections = []
+ self.selection = Selection()
+ self.selection.connect("selection-changed", self._selectionChanged)
self.timeline_objects = []
self.duration = 0
self.timeline_selection = set()
@@ -468,6 +500,9 @@ class Timeline(object ,Signallable, Loggable):
self.emit('track-added', track)
+ def _selectionChanged(self, selection):
+ self.emit("selection-changed")
+
def _trackStartChangedCb(self, track, duration):
self._updateDuration()
@@ -587,27 +622,13 @@ class Timeline(object ,Signallable, Loggable):
return None
def setSelectionToObj(self, obj, mode):
- self.setSelectionTo(set([obj]), mode)
+ self.selection.setToObj(obj, mode)
def setSelectionTo(self, selection, mode):
- selection = set([obj.timeline_object for obj in selection])
- old_selection = self.timeline_selection
- if mode == SELECT:
- self.timeline_selection = selection
- elif mode == SELECT_ADD:
- self.timeline_selection.update(selection)
- elif mode == UNSELECT:
- self.timeline_selection.difference(selection)
-
- for obj in self.timeline_selection:
- obj.selected = True
- for obj in old_selection - self.timeline_selection:
- obj.selected = False
-
- self.emit("selection-changed")
+ self.selection.setTo(selection, mode)
def linkSelection(self):
- if len(self.timeline_selection) < 2:
+ if len(self.selection) < 2:
return
# list of links that we joined and so need to be removed
@@ -616,7 +637,7 @@ class Timeline(object ,Signallable, Loggable):
# we start with a new empty link and we expand it as we find new objects
# and links
link = Link()
- for timeline_object in self.timeline_selection:
+ for timeline_object in self.selection:
if timeline_object.link is not None:
old_links.append(timeline_object.link)
@@ -632,7 +653,7 @@ class Timeline(object ,Signallable, Loggable):
def unlinkSelection(self):
empty_links = set()
- for timeline_object in self.timeline_selection:
+ for timeline_object in self.selection:
if timeline_object.link is None:
continue
@@ -684,9 +705,9 @@ class Timeline(object ,Signallable, Loggable):
def deleteSelection(self):
self.unlinkSelection()
- for timeline_object in self.timeline_selection:
+ for timeline_object in self.selection:
self.removeTimelineObject(timeline_object, deep=True)
- self.timeline_selection = set()
+ self.selection.setTo(set([]), SELECT)
def rebuildEdges(self):
self.edges = TimelineEdges()
diff --git a/pitivi/ui/timeline.py b/pitivi/ui/timeline.py
index 87b523c..2383466 100644
--- a/pitivi/ui/timeline.py
+++ b/pitivi/ui/timeline.py
@@ -377,11 +377,11 @@ class Timeline(gtk.Table, Loggable, Zoomable):
delete = False
link = False
unlink = False
- if timeline.timeline_selection:
+ if timeline.selection:
delete = True
- if len(timeline.timeline_selection) > 1:
+ if len(timeline.selection) > 1:
link = True
- for obj in self.timeline.timeline_selection:
+ for obj in self.timeline.selection:
if obj.link:
unlink = True
break
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]