[pitivi] Remove Serializable and all of its usage in pitivi
- From: Edward Hervey <edwardrv src gnome org>
- To: svn-commits-list gnome org
- Subject: [pitivi] Remove Serializable and all of its usage in pitivi
- Date: Fri, 17 Apr 2009 09:35:04 -0400 (EDT)
commit 2a428586c21a929d91e8a1dc8382b237ffc7e245
Author: Edward Hervey <bilboed bilboed com>
Date: Mon Mar 16 13:37:16 2009 +0100
Remove Serializable and all of its usage in pitivi
---
pitivi/Makefile.am | 1 -
pitivi/device.py | 7 +--
pitivi/project.py | 25 +-----------
pitivi/serializable.py | 105 ------------------------------------------------
pitivi/settings.py | 52 +-----------------------
pitivi/sourcelist.py | 23 +----------
6 files changed, 5 insertions(+), 208 deletions(-)
diff --git a/pitivi/Makefile.am b/pitivi/Makefile.am
index 85781c4..f68bbc9 100644
--- a/pitivi/Makefile.am
+++ b/pitivi/Makefile.am
@@ -28,7 +28,6 @@ pitivi_PYTHON = \
project.py \
projectsaver.py \
receiver.py \
- serializable.py \
settings.py \
signalgroup.py \
signalinterface.py \
diff --git a/pitivi/device.py b/pitivi/device.py
index 334ad68..5986b36 100644
--- a/pitivi/device.py
+++ b/pitivi/device.py
@@ -231,17 +231,16 @@ class SourceDeviceFactory(SourceFactory):
"""
Base class for ObjectFactory to control source devices
"""
- __data_type__ = "source-device-factory"
+ pass
class SinkDeviceFactory(ObjectFactory):
"""
Base class for ObjectFactory to control sink devices
"""
- __data_type__ = "sink-device-factory"
+ pass
class AlsaSourceDeviceFactory(SourceDeviceFactory):
"""ObjectFactory for Alsa source devices"""
- __data_type__ = "alsa-source-device-factory"
def __init__(self, card, device, *args, **kwargs):
SourceDeviceFactory.__init__(self, *args, **kwargs)
@@ -261,7 +260,6 @@ class AlsaSourceDeviceFactory(SourceDeviceFactory):
class AlsaSinkDeviceFactory(SinkDeviceFactory):
"""ObjectFactory for Alsa sink devices"""
- __data_type__ = "alsa-sink-device-factory"
def __init__(self, card, device, *args, **kwargs):
SinkDeviceFactory.__init__(self, *args, **kwargs)
@@ -283,7 +281,6 @@ class AlsaSinkDeviceFactory(SinkDeviceFactory):
class V4LSourceDeviceFactory(SourceDeviceFactory):
"""ObjectFactory for Video4Linux source devices"""
- __data_type__ = "v4l-source-device-factory"
def __init__(self, device, *args, **kwargs):
SourceDeviceFactory.__init__(self, *args, **kwargs)
diff --git a/pitivi/project.py b/pitivi/project.py
index 6689ee9..1360998 100644
--- a/pitivi/project.py
+++ b/pitivi/project.py
@@ -37,12 +37,11 @@ from pitivi.factories.timeline import TimelineSourceFactory
from pitivi.sourcelist import SourceList
from pitivi.settings import ExportSettings
from pitivi.configure import APPNAME
-from pitivi.serializable import Serializable, to_object_from_data_type
from pitivi.projectsaver import ProjectSaver, ProjectLoadError
from pitivi.signalinterface import Signallable
from pitivi.action import ViewAction
-class Project(Serializable, Signallable, Loggable):
+class Project(object, Signallable, Loggable):
""" The base class for PiTiVi projects
Signals
@@ -79,8 +78,6 @@ class Project(Serializable, Signallable, Loggable):
"missing-plugins": ["uri", "detail", "description"]
}
- __data_type__ = "project"
-
def __init__(self, name="", uri=None, **kwargs):
"""
name : the name of the project
@@ -302,26 +299,6 @@ class Project(Serializable, Signallable, Loggable):
def _sourceListMissingPluginsCb(self, source_list, uri, detail, description):
return self.emit('missing-plugins', uri, detail, description)
- # Serializable methods
-
- def toDataFormat(self):
- ret = Serializable.toDataFormat(self)
- ret["name"] = self.name
- ret["settings"] = self.getSettings().toDataFormat()
- ret["sources"] = self.sources.toDataFormat()
- ret["timeline"] = self.timeline.toDataFormat()
- return ret
-
- def fromDataFormat(self, obj):
- Serializable.fromDataFormat(self, obj)
- self.name = obj["name"]
- # calling this makes sure settigns-changed signal is emitted
- self.setSettings(to_object_from_data_type(obj["settings"]))
- # these objects already exist, so we initialize them from file
- # to make sure UI catches signals
- self.sources.fromDataFormat(obj["sources"])
- self.timeline.fromDataFormat(obj["timeline"])
-
def uri_is_valid(uri):
""" Checks if the given uri is a valid uri (of type file://) """
return gst.uri_get_protocol(uri) == "file"
diff --git a/pitivi/serializable.py b/pitivi/serializable.py
deleted file mode 100644
index 004cc5a..0000000
--- a/pitivi/serializable.py
+++ /dev/null
@@ -1,105 +0,0 @@
-# PiTiVi , Non-linear video editor
-#
-# pitivi/serializable.py
-#
-# Copyright (c) 2005, Edward Hervey <bilboed bilboed 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.
-
-"""
-Interface for object serialization
-"""
-
-import gst
-
-class Serializable(object):
- """An interface which all objects expected to be saved/loaded into project
- files must implement."""
- __data_type__ = "serializable"
-
- def toDataFormat(self):
- """
- Return the Data Format dictionnary containing serializable information for
- this object.
-
- All serializable objects must chain up to the parent class function before
- filling in the returned dictionnary.
- """
- return { "datatype" : self.__data_type__ }
-
- def fromDataFormat(self, obj):
- """
- Fill self with the information contained in the 'obj' dictionnary.
-
- All serializable objects must chain up to the parent class function before
- extracting their information.
- """
- gst.log("obj : %r" % obj)
- if not obj["datatype"]:
- raise Exception("dictionnary doesn't contain the type information !!")
- if not obj["datatype"] == self.__data_type__:
- raise Exception("Mismatch in dictionnary data-type (%s) and class data-type (%s)" % (obj["datatype"],
- self.__data_type__))
- return
-
-
-def get_serialized_classes():
- """
- Returns a dictionnary of serialized classes.
- Mapping is type-name (string) => class
- """
- def __get_valid_subclasses(cls):
- res = [(cls.__data_type__, cls)]
- for i in cls.__subclasses__():
- res.extend(__get_valid_subclasses(i))
- return res
-
- listclasses = __get_valid_subclasses(Serializable)
-
- # add a little check for duplicates here !
- check = {}
- for i, j in listclasses:
- if not i in check:
- check[i] = j
- else:
- raise Exception("ERROR ! Type %r and %r share the same __data_type__ : %s" % (j, check[i], i))
-
- return dict(listclasses)
-
-def to_object_from_data_type(data):
- """
- Attempts to create an object from the given intermediary data set.
- """
- # 1. Find class for data-type
- dt = data["datatype"]
-
- # FIXME: do we really want to rebuils this list EVERY time we
- # call to_object_from_data_type? this could make project loading
- # slower than it has to be. Morever, the list is not likely to
- # change at runtime, unlike, say, the list of implemented file
- # formats. Probably we only want to build this list once.
-
- classes = get_serialized_classes()
- if not dt in classes:
- raise Exception, "Don't have a class to handle data-type %r" % dt
- gst.log("Creating obj of type %s , kwargs:%r" % (dt, data))
- if dt == "serializable":
- # base class
- obj = classes[dt]()
- else:
- obj = classes[dt](**data)
- obj.fromDataFormat(data)
- return obj
diff --git a/pitivi/settings.py b/pitivi/settings.py
index ec6f8c2..9e53469 100644
--- a/pitivi/settings.py
+++ b/pitivi/settings.py
@@ -30,7 +30,6 @@ from ConfigParser import SafeConfigParser, ParsingError
from gettext import gettext as _
-from pitivi.serializable import Serializable
from pitivi.signalinterface import Signallable
from pitivi.encode import available_muxers, available_video_encoders, \
available_audio_encoders, available_combinations, \
@@ -393,7 +392,7 @@ class RenderSettings(object):
def __repr__(self):
return "<RenderSettings %s [%d streams]>" % (self.muxer, len(self.settings))
-class ExportSettings(Serializable, Signallable, Loggable):
+class ExportSettings(object, Signallable, Loggable):
"""
Multimedia export settings
@@ -407,8 +406,6 @@ class ExportSettings(Serializable, Signallable, Loggable):
"encoders-changed" : None,
}
- __data_type__ = "export-settings"
-
# Audio/Video settings for processing/export
# TODO : Add PAR/DAR for video
@@ -529,53 +526,6 @@ class ExportSettings(Serializable, Signallable, Loggable):
if changed:
self.emit("encoders-changed")
- ## Serializable methods
-
- def toDataFormat(self):
- ret = Serializable.toDataFormat(self)
- ret["video-width"] = self.videowidth
- ret["video-height"] = self.videoheight
- ret["video-rate"] = [ self.videorate.num,
- self.videorate.denom ]
- ret["video-par"] = [ self.videopar.num,
- self.videopar.denom ]
- ret["audio-channels"] = self.audiochannels
- ret["audio-rate"] = self.audiorate
- ret["audio-depth"] = self.audiodepth
- ret["video-encoder"] = self.vencoder
- ret["audio-encoder"] = self.aencoder
- ret["muxer"] = self.muxer
- if self.containersettings:
- ret["container-settings"] = self.containersettings
- if self.acodecsettings:
- ret["audio-encoder-settings"] = self.acodecsettings
- if self.vcodecsettings:
- ret["video-encoder-settings"] = self.vcodecsettings
- return ret
-
- def fromDataFormat(self, obj):
- Serializable.fromDataFormat(self, obj)
- self.videowidth = obj["video-width"]
- self.videoheight = obj["video-height"]
- self.videorate = gst.Fraction(*obj["video-rate"])
- self.videopar = gst.Fraction(*obj["video-par"])
-
- self.audiochannels = obj["audio-channels"]
- self.audiorate = obj["audio-rate"]
- self.audiodepth = obj["audio-depth"]
-
- # FIXME : check if the given encoder/muxer are available
- self.vencoder = obj["video-encoder"]
- self.aencoder = obj["audio-encoder"]
- self.muxer = obj["muxer"]
- if "container-settings" in obj:
- self.containersettings = obj["container-settings"]
- if "audio-encoder-settings" in obj:
- self.acodecsettings = obj["audio-encoder-settings"]
- if "video-encoder-settings" in obj:
- self.vcodecsettings = obj["video-encoder-settings"]
-
-
def export_settings_to_render_settings(export):
# Get the audio and video caps/encoder/settings
astream = get_stream_for_caps(export.getAudioCaps())
diff --git a/pitivi/sourcelist.py b/pitivi/sourcelist.py
index 1a93f96..468f96a 100644
--- a/pitivi/sourcelist.py
+++ b/pitivi/sourcelist.py
@@ -24,11 +24,10 @@ Handles the list of source for a project
"""
import urllib
from pitivi.discoverer import Discoverer
-from pitivi.serializable import Serializable, to_object_from_data_type
from pitivi.signalinterface import Signallable
from pitivi.log.loggable import Loggable
-class SourceList(Serializable, Signallable, Loggable):
+class SourceList(object, Signallable, Loggable):
"""
Contains the sources for a project, stored as FileSourceFactory
@@ -51,8 +50,6 @@ class SourceList(Serializable, Signallable, Loggable):
"missing-plugins": ["uri", "detail", "description"]
}
- __data_type__ = "source-list"
-
def __init__(self, project=None):
Loggable.__init__(self)
self.log("new sourcelist for project %s", project)
@@ -172,21 +169,3 @@ class SourceList(Serializable, Signallable, Loggable):
def _discovererMissingPluginsCb(self, discoverer, uri, detail, description):
self.missing_plugins[uri] = True
return self.emit('missing-plugins', uri, detail, description)
-
- ## Serializable methods
-
- def toDataFormat(self):
- ret = Serializable.toDataFormat(self)
- d = {}
- for uri, factory in self:
- d[uri] = factory.toDataFormat()
- ret["sources-factories"] = d
- return ret
-
- def fromDataFormat(self, obj):
- Serializable.fromDataFormat(self, obj)
- # FIXME : We're supposing we have complete objectfactories
- # with all information !!!
- if "sources-factories" in obj:
- for uri, factory in obj["sources-factories"].iteritems():
- self.addFactory(uri, to_object_from_data_type(factory))
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]