[pitivi] Save effect configurations when undoing



commit 4a3b719fb2f4181703f6cc0ca9f5823e7a94e1b3
Author: Thibault Saunier <tsaunier gnome org>
Date:   Fri Jul 16 23:05:41 2010 -0400

    Save effect  configurations when undoing

 pitivi/timeline/timeline_undo.py  |   53 ++++++++++++++++++++++++++++++-------
 pitivi/ui/effectsconfiguration.py |    7 +++--
 pitivi/ui/gstwidget.py            |   20 ++++++++++----
 3 files changed, 61 insertions(+), 19 deletions(-)
---
diff --git a/pitivi/timeline/timeline_undo.py b/pitivi/timeline/timeline_undo.py
index 46f21e3..0ff64fe 100644
--- a/pitivi/timeline/timeline_undo.py
+++ b/pitivi/timeline/timeline_undo.py
@@ -19,11 +19,15 @@
 # Free Software Foundation, Inc., 59 Temple Place - Suite 330,
 # Boston, MA 02111-1307, USA.
 
+import gobject
+
 from pitivi.signalinterface import Signallable
 from pitivi.utils import PropertyChangeTracker
 from pitivi.undo import UndoableAction
 from pitivi.timeline.track import TrackEffect
 
+from pitivi.ui.effectsconfiguration import PROPS_TO_IGNORE
+
 class TimelineObjectPropertyChangeTracker(PropertyChangeTracker):
     # no out-point
     property_names = ["start", "duration", "in-point",
@@ -151,38 +155,67 @@ class TimelineObjectRemoved(UndoableAction):
             track.addTrackObject(track_object)
 
         self.timeline.addTimelineObject(self.timeline_object)
+
         self._undone()
 
-class TrackEffectRemoved(UndoableAction):
+class TrackEffectAdded(UndoableAction):
     def __init__(self, timeline_object, track_object):
         self.track_object = track_object
         self.timeline_object = timeline_object
         self.track = self.track_object.track
+        self.effect_props = []
 
     def do(self):
-        self.timeline_object.removeTrackObject(self.track_object)
-        self.track.removeTrackObject(self.track_object)
+        self.track.addTrackObject(self.track_object)
+        self.timeline_object.addTrackObject(self.track_object)
+
+        element = self.track_object.getElement()
+        for prop_name, prop_value in self.effect_props:
+            element.set_property(prop_name, prop_value)
+
         self._done()
 
     def undo(self):
-        self.track.addTrackObject(self.track_object)
-        self.timeline_object.addTrackObject(self.track_object)
+        element = self.track_object.getElement()
+        props =  gobject.list_properties(element)
+        self.effect_props = [(prop.name, element.get_property(prop.name))
+                              for prop in props
+                              if prop.flags & gobject.PARAM_WRITABLE
+                              and prop.name not in PROPS_TO_IGNORE]
+
+        self.timeline_object.removeTrackObject(self.track_object)
+        self.track.removeTrackObject(self.track_object)
+
         self._undone()
 
-class TrackEffectAdded(UndoableAction):
+class TrackEffectRemoved(UndoableAction):
     def __init__(self, timeline_object, track_object):
         self.track_object = track_object
         self.timeline_object = timeline_object
         self.track = self.track_object.track
+        self.effect_props = []
 
     def do(self):
-        self.track.addTrackObject(self.track_object)
-        self.timeline_object.addTrackObject(self.track_object)
-        self._done()
+        element = self.track_object.getElement()
+        props =  gobject.list_properties(element)
+        self.effect_props = [(prop.name, element.get_property(prop.name))
+                              for prop in props
+                              if prop.flags & gobject.PARAM_WRITABLE
+                              and prop.name not in PROPS_TO_IGNORE]
 
-    def undo(self):
         self.timeline_object.removeTrackObject(self.track_object)
         self.track.removeTrackObject(self.track_object)
+
+        self._done()
+
+    def undo(self):
+        self.track.addTrackObject(self.track_object)
+        self.timeline_object.addTrackObject(self.track_object)
+
+        element = self.track_object.getElement()
+        for prop_name, prop_value in self.effect_props:
+            element.set_property(prop_name, prop_value)
+
         self._undone()
 
 class InterpolatorKeyframeAdded(UndoableAction):
diff --git a/pitivi/ui/effectsconfiguration.py b/pitivi/ui/effectsconfiguration.py
index da983c7..08958f6 100644
--- a/pitivi/ui/effectsconfiguration.py
+++ b/pitivi/ui/effectsconfiguration.py
@@ -2,7 +2,7 @@
 #       ui/effectsconfiguration.py
 #
 # Copyright (C) 2010 Thibault Saunier <tsaunier gnome org>
-# 
+#
 # 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
@@ -27,7 +27,7 @@ import gtk
 from pitivi.ui.gstwidget import GstElementSettingsWidget
 from pitivi.pipeline import PipelineError
 
-PROPERTIES_TO_IGNORE = ['name', 'qos']
+PROPS_TO_IGNORE = ['name', 'qos']
 
 class EffectsPropertiesHandling:
     def __init__(self):
@@ -44,7 +44,8 @@ class EffectsPropertiesHandling:
         if effect not in self.cache_dict:
             #Here we should handle special effects configuration UI
             effect_configuration_ui =  GstElementSettingsWidget()
-            effect_configuration_ui.setElement(effect, ignore=PROPERTIES_TO_IGNORE, default_btn=True)
+            effect_configuration_ui.setElement(effect, ignore=PROPS_TO_IGNORE,
+                                               default_btn=True, use_element_props=True)
             self._connectAllWidgetCbs(effect_configuration_ui, effect)
             self.cache_dict[effect] = effect_configuration_ui
         self.current_config_ui = self.cache_dict[effect]
diff --git a/pitivi/ui/gstwidget.py b/pitivi/ui/gstwidget.py
index 837b914..ccf4bbe 100644
--- a/pitivi/ui/gstwidget.py
+++ b/pitivi/ui/gstwidget.py
@@ -126,15 +126,16 @@ class GstElementSettingsWidget(gtk.VBox, Loggable):
         self.ignore = None
         self.properties = None
 
-    def setElement(self, element, properties={}, ignore=['name'], default_btn = False):
+    def setElement(self, element, properties={}, ignore=['name'],
+                   default_btn = False, use_element_props=False):
         """ Set given element on Widget, with optional properties """
-        self.info("element:%s, properties:%s", element, properties)
+        self.info("element:%s, use properties:%s", element, properties)
         self.element = element
         self.ignore = ignore
-        self.properties = properties
-        self._addWidgets(properties, default_btn)
+        self.properties = {}
+        self._addWidgets(properties, default_btn, use_element_props)
 
-    def _addWidgets(self, properties, default_btn):
+    def _addWidgets(self, properties, default_btn, use_element_props):
         props = [prop for prop in gobject.list_properties(self.element) if not prop.name in self.ignore]
         if not props:
             self.pack_start(gtk.Label(_("No properties...")))
@@ -153,15 +154,22 @@ class GstElementSettingsWidget(gtk.VBox, Loggable):
             label = gtk.Label(prop.nick)
             label.set_alignment(0.0, 0.5)
             table.attach(label, 0, 1, y, y+1, xoptions=gtk.FILL, yoptions=gtk.FILL)
-            widget = make_property_widget(self.element, prop, properties.get(prop.name))
+            if use_element_props:
+                prop_value  = self.element.get_property(prop.name)
+            else:
+                prop_value = properties.get(prop.name)
+            widget = make_property_widget(self.element, prop, prop_value)
+
             if hasattr(prop, 'description'): #TODO: check that
                 widget.set_tooltip_text(prop.description)
+
             table.attach(widget, 1, 2, y, y+1, yoptions=gtk.FILL)
             self.properties[prop] = widget
             if default_btn:
                 button = self._getResetToDefaultValueButton(prop, widget)
                 table.attach(button, 2, 3, y, y+1, xoptions=gtk.FILL, yoptions=gtk.FILL)
             y += 1
+
         self.pack_start(table)
         self.show_all()
 



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