[pitivi] Start implementing scenario serialization
- From: Thibault Saunier <tsaunier src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [pitivi] Start implementing scenario serialization
- Date: Sat, 15 Nov 2014 10:31:58 +0000 (UTC)
commit 81cf532b252cccc3738763be634eea8a6052986d
Author: Mathieu Duponchelle <mathieu duponchelle opencreed com>
Date: Thu May 1 13:30:11 2014 +0200
Start implementing scenario serialization
https://bugzilla.gnome.org/show_bug.cgi?id=739251
pitivi/application.py | 17 ++++++++++++++---
pitivi/project.py | 16 +++++++++++++++-
pitivi/undo/timeline.py | 27 +++++++++++++++++++++++++++
pitivi/undo/undo.py | 16 +++++++++++++++-
4 files changed, 71 insertions(+), 5 deletions(-)
---
diff --git a/pitivi/application.py b/pitivi/application.py
index a000919..e1712bd 100644
--- a/pitivi/application.py
+++ b/pitivi/application.py
@@ -29,7 +29,7 @@ from gi.repository import Gtk
from pitivi.effects import EffectsManager
from pitivi.configure import VERSION, RELEASES_URL
-from pitivi.settings import GlobalSettings
+from pitivi.settings import GlobalSettings, xdg_cache_home, get_dir
from pitivi.utils.threads import ThreadMaster
from pitivi.mainwindow import PitiviMainWindow
from pitivi.project import ProjectManager, ProjectLogObserver
@@ -37,10 +37,11 @@ from pitivi.undo.undo import UndoableActionLog
from pitivi.undo.timeline import TimelineLogObserver
from pitivi.dialogs.startupwizard import StartUpWizard
-from pitivi.utils.misc import quote_uri
+from pitivi.utils.misc import quote_uri, path_from_uri
from pitivi.utils.system import getSystem
from pitivi.utils.loggable import Loggable
import pitivi.utils.loggable as log
+from datetime import datetime
class Pitivi(Gtk.Application, Loggable):
@@ -72,10 +73,15 @@ class Pitivi(Gtk.Application, Loggable):
self.system = None
self.project_manager = ProjectManager(self)
- self.action_log = UndoableActionLog()
+ self.action_log = UndoableActionLog(self)
self.timeline_log_observer = None
self.project_log_observer = None
+ cache_dir = get_dir(os.path.join(xdg_cache_home(), "scenarios"))
+ uri = os.path.join(cache_dir, str(datetime.now()) + ".scenario")
+ uri = quote_uri(uri)
+ self.log_file = open(path_from_uri(uri), "w")
+
self.gui = None
self.welcome_wizard = None
@@ -85,6 +91,10 @@ class Pitivi(Gtk.Application, Loggable):
self.connect("activate", self._activateCb)
self.connect("open", self.openCb)
+ def write_action(self, structure):
+ self.log_file.write(structure.to_string() + "\r\n")
+ self.log_file.flush()
+
def _startupCb(self, unused_app):
# Init logging as early as possible so we can log startup code
enable_color = not os.environ.get('PITIVI_DEBUG_NO_COLOR', '0') in ('', '1')
@@ -183,6 +193,7 @@ class Pitivi(Gtk.Application, Loggable):
self.gui.destroy()
self.threads.stopAllThreads()
self.settings.storeSettings()
+ self.log_file.close()
self.quit()
return True
diff --git a/pitivi/project.py b/pitivi/project.py
index 990c3dd..1d09256 100644
--- a/pitivi/project.py
+++ b/pitivi/project.py
@@ -73,6 +73,13 @@ class AssetRemovedAction(UndoableAction):
def do(self):
self.project.remove_asset(self.asset)
+ def serializeLastAction(self):
+ st = Gst.Structure.new_empty("remove-asset")
+ st.set_value("id", self.asset.get_info().get_uri())
+ type_string = GObject.type_name(self.asset.get_extractable_type())
+ st.set_value("type", type_string)
+ return st
+
class AssetAddedAction(UndoableAction):
def __init__(self, project, asset):
@@ -86,6 +93,13 @@ class AssetAddedAction(UndoableAction):
def do(self):
self.project.add_asset(self.asset)
+ def serializeLastAction(self):
+ st = Gst.Structure.new_empty("add-asset")
+ st.set_value("id", self.asset.get_info().get_uri())
+ type_string = GObject.type_name(self.asset.get_extractable_type())
+ st.set_value("type", type_string)
+ return st
+
class ProjectSettingsChanged(UndoableAction):
@@ -933,7 +947,7 @@ class Project(Loggable, GES.Project):
self.timeline.props.auto_transition = True
self._calculateNbLoadingAssets()
- self.pipeline = Pipeline()
+ self.pipeline = Pipeline(self.app)
try:
self.pipeline.set_timeline(self.timeline)
except PipelineError as e:
diff --git a/pitivi/undo/timeline.py b/pitivi/undo/timeline.py
index 173cd8b..0c1203b 100644
--- a/pitivi/undo/timeline.py
+++ b/pitivi/undo/timeline.py
@@ -19,6 +19,7 @@
# Free Software Foundation, Inc., 51 Franklin St, Fifth Floor,
# Boston, MA 02110-1301, USA.
+from gi.repository import Gst
from gi.repository import GES
from gi.repository import GObject
@@ -129,6 +130,17 @@ class ClipAdded(UndoableAction):
self.layer.remove_clip(self.clip)
self._undone()
+ def serializeLastAction(self):
+ st = Gst.Structure.new_empty("add-clip")
+ st.set_value("name", self.clip.get_name())
+ st.set_value("layer-priority", self.layer.props.priority)
+ st.set_value("asset-id", self.clip.get_asset().get_id())
+ st.set_value("type", GObject.type_name(self.clip))
+ st.set_value("start", float(self.clip.props.start / Gst.SECOND))
+ st.set_value("inpoint", float(self.clip.props.in_point / Gst.SECOND))
+ st.set_value("duration", float(self.clip.props.duration / Gst.SECOND))
+ return st
+
class ClipRemoved(UndoableAction):
@@ -146,6 +158,11 @@ class ClipRemoved(UndoableAction):
self.layer.get_timeline().commit()
self._undone()
+ def serializeLastAction(self):
+ st = Gst.Structure.new_empty("remove-clip")
+ st.set_value("name", self.clip.get_name())
+ return st
+
class LayerAdded(UndoableAction):
def __init__(self, timeline, layer):
@@ -158,6 +175,11 @@ class LayerAdded(UndoableAction):
def undo(self):
self.timeline.remove_layer(self.layer)
+ def serializeLastAction(self):
+ st = Gst.Structure.new_empty("add-layer")
+ st.set_value("priority", self.layer.props.priority)
+ return st
+
class LayerRemoved(UndoableAction):
def __init__(self, timeline, layer):
@@ -170,6 +192,11 @@ class LayerRemoved(UndoableAction):
def undo(self):
self.timeline.add_layer(self.layer)
+ def serializeLastAction(self):
+ st = Gst.Structure.new_empty("remove-layer")
+ st.set_value("priority", self.layer.props.priority)
+ return st
+
class InterpolatorKeyframeAdded(UndoableAction):
diff --git a/pitivi/undo/undo.py b/pitivi/undo/undo.py
index 1c35d76..e9f21db 100644
--- a/pitivi/undo/undo.py
+++ b/pitivi/undo/undo.py
@@ -23,6 +23,8 @@
Base classes for undo/redo.
"""
+import weakref
+
from gi.repository import GObject
from pitivi.utils.loggable import Loggable
@@ -63,6 +65,9 @@ class UndoableAction(GObject.Object):
# Meant to be overridden by UndoableActionStack?
pass
+ def serializeLastAction(self):
+ raise NotImplementedError()
+
def _done(self):
self.emit("done")
@@ -127,10 +132,11 @@ class UndoableActionLog(GObject.Object, Loggable):
"cleaned": (GObject.SIGNAL_RUN_LAST, None, ()),
}
- def __init__(self):
+ def __init__(self, app=None):
GObject.Object.__init__(self)
Loggable.__init__(self)
+ self.app = weakref.proxy(app)
self.undo_stacks = []
self.redo_stacks = []
self.stacks = []
@@ -151,6 +157,14 @@ class UndoableActionLog(GObject.Object, Loggable):
def push(self, action):
self.debug("Pushing %s", action)
+
+ try:
+ st = action.serializeLastAction()
+ if self.app is not None:
+ self.app.write_action(st)
+ except NotImplementedError:
+ self.warning("No serialization method for that action")
+
if self.running:
self.debug("Abort because already running")
return
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]