[pitivi] git add pitivi/timeline/timeline_undo.py
- From: Edward Hervey <edwardrv src gnome org>
- To: svn-commits-list gnome org
- Subject: [pitivi] git add pitivi/timeline/timeline_undo.py
- Date: Thu, 11 Jun 2009 12:38:53 -0400 (EDT)
commit 67d117172f83b42a96706a5eea7e8324f30123ac
Author: Alessandro Decina <alessandro d gmail com>
Date: Wed Jun 10 13:36:07 2009 +0200
git add pitivi/timeline/timeline_undo.py
pitivi/timeline/timeline_undo.py | 92 ++++++++++++++++++++++++++++++++++++++
1 files changed, 92 insertions(+), 0 deletions(-)
---
diff --git a/pitivi/timeline/timeline_undo.py b/pitivi/timeline/timeline_undo.py
new file mode 100644
index 0000000..aeeb243
--- /dev/null
+++ b/pitivi/timeline/timeline_undo.py
@@ -0,0 +1,92 @@
+# PiTiVi , Non-linear video editor
+#
+# pitivi/timeline/timeline_undo.py
+#
+# Copyright (c) 2009, Alessandro Decina <alessandro d gmail com>
+#
+# This program is free software; you can redistribute it and/or
+# modify it under the terms of the GNU Lesser General Public
+# License as published by the Free Software Foundation; either
+# version 2.1 of the License, or (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+# Lesser General Public License for more details.
+#
+# You should have received a copy of the GNU Lesser General Public
+# License along with this program; if not, write to the
+# Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+# Boston, MA 02111-1307, USA.
+
+from pitivi.utils import PropertyChangeTracker
+from pitivi.undo import UndoableAction
+
+class TimelineObjectPropertyChangeTracker(PropertyChangeTracker):
+ property_names = ["start", "duration", "in-point", "out-point",
+ "media-duration", "priority", "selected"]
+
+class TimelineObjectPropertyChanged(UndoableAction):
+ def __init__(self, timeline_object, property_name, old_value, new_value):
+ self.timeline_object = timeline_object
+ self.property_name = property_name
+ self.old_value = old_value
+ self.new_value = new_value
+
+ def do(self):
+ setattr(self.timeline_object,
+ self.property_name.replace("-", "_"), self.new_value)
+ self._done()
+
+ def undo(self):
+ setattr(self.timeline_object,
+ self.property_name.replace("-", "_"), self.old_value)
+ self._undone()
+
+class TimelineLogObserver(object):
+ def __init__(self, log):
+ self.log = log
+ self.property_trackers = {}
+
+ def startObserving(self, timeline):
+ self._connectToTimeline(timeline)
+ for timeline_object in timeline.timeline_objects:
+ self._connectToTimelineObject(timeline_object)
+
+ def stopObserving(self, timeline):
+ self._disconnectFromTimeline(timeline)
+ for timeline_object in timeline.timeline_objects:
+ self._disconnectFromTimelineObject(timeline_object)
+
+ def _connectToTimeline(self, timeline):
+ timeline.connect("object-added", self._timelineObjectAddedCb)
+ timeline.connect("object-removed", self._timelineObjectRemovedCb)
+
+ def _disconnectFromTimeline(self, timeline):
+ timeline.disconnect_by_func(self._timelineObjectAddedCb)
+ timeline.disconnect_by_func(self._timelineObjectRemovedCb)
+
+ def _connectToTimelineObject(self, timeline_object):
+ tracker = TimelineObjectPropertyChangeTracker()
+ tracker.connectToObject(timeline_object)
+ for property_name in tracker.property_names:
+ tracker.connect(property_name + "-changed",
+ self._timelineObjectPropertyChangedCb, property_name)
+ self.property_trackers[timeline_object] = tracker
+
+ def _disconnectFromTimelineObject(self, timeline_object):
+ tracker = self.property_trackers.pop(timeline_object)
+ tracker.disconnectFromObject(timeline_object)
+ tracker.disconnect_by_func(self._timelineObjectPropertyChangedCb)
+
+ def _timelineObjectAddedCb(self, timeline, timeline_object):
+ self._connectToTimelineObject(timeline_object)
+
+ def _timelineObjectRemovedCb(self, timeline, timeline_object):
+ self._disconnectFromTimelineObject(timeline_object)
+
+ def _timelineObjectPropertyChangedCb(self, tracker, timeline_object,
+ old_value, new_value, property_name):
+ action = TimelineObjectPropertyChanged(timeline_object,
+ property_name, old_value, new_value)
+ self.log.push(action)
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]