[pitivi: 36/94] RenderPresetManager subclass with rewritten load() and save() for json operation
- From: Thibault Saunier <tsaunier src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [pitivi: 36/94] RenderPresetManager subclass with rewritten load() and save() for json operation
- Date: Sun, 11 Sep 2011 16:15:28 +0000 (UTC)
commit dc440f91f1a5e0eab059814d6a137c04ef004f02
Author: Feroze Naina <ferozenaina gmail com>
Date: Thu Jul 14 23:53:01 2011 +0530
RenderPresetManager subclass with rewritten load() and save() for json operation
pitivi/ui/preset.py | 84 +++++++++++++++++++++++++++++++++++++++++++++++++--
1 files changed, 81 insertions(+), 3 deletions(-)
---
diff --git a/pitivi/ui/preset.py b/pitivi/ui/preset.py
index 472206e..be4729f 100644
--- a/pitivi/ui/preset.py
+++ b/pitivi/ui/preset.py
@@ -26,13 +26,15 @@ import gst
import gtk
from pitivi.settings import xdg_data_home
+from pitivi.configure import get_data_dir
+import json
+import os
class DuplicatePresetNameException(Exception):
"""Raised when an operation would result in a duplicated preset name."""
pass
-
class PresetManager(object):
"""Abstract class for storing a list of presets.
@@ -228,7 +230,6 @@ class PresetManager(object):
return any((values[field] != getter()
for field, (setter, getter) in self.widget_map.iteritems()))
-
class VideoPresetManager(PresetManager):
filename = "video_presets"
@@ -264,7 +265,6 @@ class VideoPresetManager(PresetManager):
parser.set(section, "par-denom",
str(int(values["par"].denom)))
-
class AudioPresetManager(PresetManager):
filename = "audio_presets"
@@ -284,3 +284,81 @@ class AudioPresetManager(PresetManager):
parser.set(section, "channels", str(values["channels"]))
parser.set(section, "depth", str(values["depth"]))
parser.set(section, "sample-rate", str(values["sample-rate"]))
+
+class RenderPresetManager(PresetManager):
+ """ load() and save() are rewritten to save widget values to json """
+
+ path = os.path.join(get_data_dir(), 'profiles') # Temporary path for dev
+
+ def load(self):
+ for file in os.listdir(self.path):
+ if file.endswith("json"):
+ self.loadSection(os.path.join(self.path, file))
+
+ def loadSection(self, filepath):
+ parser = json.loads(open(filepath).read())
+
+ name = parser["name"]
+ container = parser["container"]
+ acodec = parser["acodec"]
+ vcodec = parser["vcodec"]
+
+ width = parser["width"]
+ height = parser["height"]
+ framerate_num = parser["framerate-num"]
+ framerate_denom = parser["framerate-denom"]
+ framerate = gst.Fraction(framerate_num, framerate_denom)
+
+ channels = parser["channels"]
+ depth = parser["depth"]
+ sample_rate = parser["sample-rate"]
+
+ self.addPreset(name, {
+ "container": container,
+ "acodec": acodec,
+ "vcodec": vcodec,
+ "width": width,
+ "height": height,
+ "frame-rate": framerate,
+ "channels": channels,
+ "depth": depth,
+ "sample-rate": sample_rate,
+ "filepath": filepath,
+ })
+
+ def save(self):
+ for name, properties in self.ordered:
+ try:
+ filepath = self.presets[name]["filepath"]
+ except:
+ filename = name + ".json"
+ filepath = os.path.join(self.path, filename)
+ fout = open(filepath, "w")
+ self.saveSection(fout, name)
+
+ def saveSection(self, fout, section):
+ values = self.presets[section]
+ data = json.dumps({
+ "name": section,
+ "container": str(values["container"]),
+ "acodec": str(values["acodec"]),
+ "vcodec": str(values["vcodec"]),
+ "width": int(values["width"]),
+ "height": int(values["height"]),
+ "framerate-num": values["frame-rate"].num,
+ "framerate-denom": values["frame-rate"].denom,
+ "channels": values["channels"],
+ "depth": int(values["depth"]),
+ "sample-rate": int(values["sample-rate"]),
+ }, indent=4)
+ fout.write(data)
+
+ def removePreset(self, name):
+ os.remove(self.presets[name]["filepath"]) # Deletes json file
+ self.presets.pop(name)
+ for i, row in enumerate(self.ordered):
+ if row[0] == name:
+ del self.ordered[i]
+ break
+ if self.cur_preset == name:
+ self.cur_preset = None
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]