pitivi r1327 - in trunk: . pitivi pitivi/ui tests
- From: edwardrv svn gnome org
- To: svn-commits-list gnome org
- Subject: pitivi r1327 - in trunk: . pitivi pitivi/ui tests
- Date: Thu, 16 Oct 2008 14:20:35 +0000 (UTC)
Author: edwardrv
Date: Thu Oct 16 14:20:35 2008
New Revision: 1327
URL: http://svn.gnome.org/viewvc/pitivi?rev=1327&view=rev
Log:
* pitivi/pitivi.py:
Remove dependency on gtk
Make subclass for Interactive pitivi
Use pure python properties
Clean up code and add comments
* pitivi/ui/complextimeline.py:
* pitivi/ui/mainwindow.py:
* tests/test_basic.py:
* tests/test_file_load_save.py:
Adapt code for modifications in pitivi.py
Modified:
trunk/ChangeLog
trunk/pitivi/pitivi.py
trunk/pitivi/ui/complextimeline.py
trunk/pitivi/ui/mainwindow.py
trunk/tests/test_basic.py
trunk/tests/test_file_load_save.py
Modified: trunk/pitivi/pitivi.py
==============================================================================
--- trunk/pitivi/pitivi.py (original)
+++ trunk/pitivi/pitivi.py Thu Oct 16 14:20:35 2008
@@ -23,7 +23,7 @@
Main application
"""
import os
-import gtk
+import gobject
import gst
import check
import instance
@@ -49,6 +49,8 @@
# AND THEN load up the required parts.
# This will result in a much better end-user experience
+# FIXME : maybe we should have subclasses for UI and CLI
+
class Pitivi(object, Signallable):
"""
Pitivi's main class
@@ -87,15 +89,14 @@
"shutdown" : None
}
- def __init__(self, args=[], use_ui=True):
+ def __init__(self, filepath=None):
"""
initialize pitivi with the command line arguments
"""
gst.log("starting up pitivi...")
- self.project = None
- self._use_ui = use_ui
# patch gst-python for new behaviours
+ # FIXME : this shouldn't be in this class
patch_gst_python()
# store ourself in the instance global
@@ -105,14 +106,8 @@
% APPNAME)
instance.PiTiVi = self
- # FIXME: use gnu getopt or somethign of the sort
- project_file = None
- if len(args) > 1:
- if os.path.exists(args[1]):
- project_file = args[1]
-
# get settings
- self.settings = GlobalSettings()
+ self._settings = GlobalSettings()
self.threads = ThreadMaster()
#self.screencast = False
@@ -121,30 +116,45 @@
self.settings.get_plugin_settings_path())
self.playground = PlayGround()
- self.current = Project(_("New Project"))
+ self._current = Project(_("New Project"))
self.effects = Magician()
self.deviceprobe = device.get_probe()
- if self._use_ui:
- self.uimanager = gtk.UIManager()
- # we're starting a GUI for the time being
- self.gui = mainwindow.PitiviMainWindow()
- self.gui.show()
- if project_file:
- self.loadProject(filepath=project_file)
+ ## properties
- def do_closing_project(self, project):
- return True
+ def _get_settings(self):
+ return self._settings
+
+ def _set_settings(self, settings):
+ self._settings = settings
+ # FIXME : we could notify this
+ settings = property(_get_settings, _set_settings,
+ doc="The project-wide output settings")
+
+ def _get_current(self):
+ return self._current
+
+ def _set_current(self, project):
+ self._current = project
+ # FIXME : we could notify this
+ current = property(_get_current, _set_current,
+ doc="The currently used Project")
+
+ ## public methods
def loadProject(self, uri=None, filepath=None):
""" Load the given file through it's uri or filepath """
gst.info("uri:%s, filepath:%s" % (uri, filepath))
if not uri and not filepath:
- self.emit("new-project-failed", _("Not a valid project file."),
+ self.emit("new-project-failed", _("No location given."),
uri)
return
if filepath:
+ if not os.path.exists(filepath):
+ self.emit("new-project-failed",
+ _("File '%s' does not exist"), filepath)
+ return
uri = "file://" + filepath
# is the given filepath a valid pitivi project
if not file_is_project(uri):
@@ -171,7 +181,7 @@
if self.current.hasUnsavedModifications():
if not self.current.save():
return False
- if not self.emit("closing-project", self.current):
+ if self.emit("closing-project", self.current) == False:
return False
self.playground.pause()
self.emit("project-closed", self.current)
@@ -189,26 +199,80 @@
self.emit("new-project-loaded", self.current)
def shutdown(self):
- """ close PiTiVi """
+ """ Close PiTiVi
+ Returns True if PiTiVi was successfully closed, else False
+ """
gst.debug("shutting down")
# we refuse to close if we're running a user interface and the user
# doesn't want us to close the current project.
if not self._closeRunningProject():
gst.warning("Not closing since running project doesn't want to close")
- return
+ return False
self.threads.stopAllThreads()
self.playground.shutdown()
instance.PiTiVi = None
self.emit("shutdown")
+ return True
+
-def shutdownCb(pitivi):
- """ shutdown callback used by main()"""
- gst.debug("Exiting main loop")
- gtk.main_quit()
+
+class InteractivePitivi(Pitivi):
+ """ Class for PiTiVi instances that provide user interaction """
+
+ def __init__(self, filepath=None, mainloop=None, *args, **kwargs):
+ Pitivi.__init__(self, filepath=None,
+ *args, **kwargs)
+ self.mainloop = mainloop
+
+ # we're starting a GUI for the time being
+ self._gui = mainwindow.PitiviMainWindow(self)
+ self._gui.load()
+ self._gui.show()
+
+ if filepath:
+ self.loadProject(filepath=filepath)
+
+ # properties
+
+ def _get_mainloop(self):
+ return self._mainloop
+
+ def _set_mainloop(self, mainloop):
+ if hasattr(self, "_mainloop"):
+ if self._mainloop != None:
+ raise Exception("Mainloop already set !")
+ if mainloop == None:
+ mainloop = gobject.MainLoop()
+ self._mainloop = mainloop
+ mainloop = property(_get_mainloop, _set_mainloop,
+ doc="The MainLoop running the program")
+
+ @property
+ def gui(self):
+ """The user interface"""
+ return self._gui
+
+
+ # PiTiVi method overrides
+ def shutdown(self):
+ if Pitivi.shutdown(self):
+ if self.mainloop:
+ self.mainloop.quit()
+ return True
+ return False
+
+ def run(self):
+ if self.mainloop:
+ self.mainloop.run()
def main(argv):
""" Start PiTiVi ! """
+ from optparse import OptionParser
check.initial_checks()
- ptv = Pitivi(argv)
- ptv.connect('shutdown', shutdownCb)
- gtk.main()
+ parser = OptionParser()
+ (unused_options, args) = parser.parse_args(argv[1:])
+ if len(args) > 0:
+ ptv = InteractivePitivi(filepath=args[0])
+ else:
+ ptv = InteractivePitivi()
+ ptv.run()
Modified: trunk/pitivi/ui/complextimeline.py
==============================================================================
--- trunk/pitivi/ui/complextimeline.py (original)
+++ trunk/pitivi/ui/complextimeline.py Thu Oct 16 14:20:35 2008
@@ -727,8 +727,9 @@
self.actiongroup = gtk.ActionGroup("complextimeline")
self.actiongroup.add_actions(actions)
self.actiongroup.set_visible(False)
- instance.PiTiVi.uimanager.insert_action_group(self.actiongroup, 0)
- instance.PiTiVi.uimanager.add_ui_from_string(ui)
+ uiman = instance.PiTiVi.gui.uimanager
+ uiman.insert_action_group(self.actiongroup, 0)
+ uiman.add_ui_from_string(ui)
## Project callbacks
Modified: trunk/pitivi/ui/mainwindow.py
==============================================================================
--- trunk/pitivi/ui/mainwindow.py (original)
+++ trunk/pitivi/ui/mainwindow.py Thu Oct 16 14:20:35 2008
@@ -72,11 +72,15 @@
"""
- def __init__(self):
+ def __init__(self, instance):
""" initialize with the Pitivi object """
gst.log("Creating MainWindow")
gtk.Window.__init__(self)
+ self.pitivi = instance
+
+ def load(self):
+ """ load the user interface """
self._createStockIcons()
self._setActions()
self._createUi()
@@ -87,14 +91,14 @@
self.isFullScreen = False
self.errorDialogBox = None
- instance.PiTiVi.connect("new-project-loaded", self._newProjectLoadedCb)
- instance.PiTiVi.connect("new-project-loading", self._newProjectLoadingCb)
- instance.PiTiVi.connect("closing-project", self._closingProjectCb)
- instance.PiTiVi.connect("new-project-failed", self._notProjectCb)
- instance.PiTiVi.current.connect("save-uri-requested", self._saveAsDialogCb)
- instance.PiTiVi.current.connect("confirm-overwrite", self._confirmOverwriteCb)
- instance.PiTiVi.playground.connect("error", self._playGroundErrorCb)
- instance.PiTiVi.current.sources.connect("file_added", self._sourcesFileAddedCb)
+ self.pitivi.connect("new-project-loaded", self._newProjectLoadedCb)
+ self.pitivi.connect("new-project-loading", self._newProjectLoadingCb)
+ self.pitivi.connect("closing-project", self._closingProjectCb)
+ self.pitivi.connect("new-project-failed", self._notProjectCb)
+ self.pitivi.current.connect("save-uri-requested", self._saveAsDialogCb)
+ self.pitivi.current.connect("confirm-overwrite", self._confirmOverwriteCb)
+ self.pitivi.playground.connect("error", self._playGroundErrorCb)
+ self.pitivi.current.sources.connect("file_added", self._sourcesFileAddedCb)
# Start dbus service
session_bus = dbus.SessionBus()
@@ -114,20 +118,20 @@
self.show_all()
def _encodingDialogDestroyCb(self, unused_dialog):
- instance.PiTiVi.gui.set_sensitive(True)
+ self.pitivi.gui.set_sensitive(True)
def _recordCb(self, unused_button):
# pause timeline !
- instance.PiTiVi.playground.pause()
+ self.pitivi.playground.pause()
- win = EncodingDialog(instance.PiTiVi.current)
+ win = EncodingDialog(self.pitivi.current)
win.window.connect("destroy", self._encodingDialogDestroyCb)
- instance.PiTiVi.gui.set_sensitive(False)
+ self.pitivi.gui.set_sensitive(False)
win.show()
def _timelineDurationChangedCb(self, unused_composition, unused_start,
duration):
- if not isinstance(instance.PiTiVi.playground.current, SmartTimelineBin):
+ if not isinstance(self.pitivi.playground.current, SmartTimelineBin):
return
self.render_button.set_sensitive((duration > 0) and True or False)
@@ -228,12 +232,12 @@
action.set_sensitive(True)
elif action.get_name() in ["SaveProject", "SaveProjectAs",
"NewProject", "OpenProject"]:
- if not instance.PiTiVi.settings.fileSupportEnabled:
+ if not self.pitivi.settings.fileSupportEnabled:
action.set_sensitive(False)
else:
action.set_sensitive(False)
- self.uimanager = instance.PiTiVi.uimanager
+ self.uimanager = gtk.UIManager()
self.add_accel_group(self.uimanager.get_accel_group())
self.uimanager.insert_action_group(self.actiongroup, 0)
self.uimanager.add_ui_from_file(os.path.join(os.path.dirname(
@@ -276,7 +280,7 @@
# Viewer
self.viewer = PitiviViewer()
- instance.PiTiVi.playground.connect("current-changed",
+ self.pitivi.playground.connect("current-changed",
self._currentPlaygroundChangedCb)
hpaned.pack1(self.sourcefactories, resize=False, shrink=False)
@@ -329,7 +333,7 @@
def _sourcesFileAddedCb(self, unused_sources, unused_factory):
#if (len(self.sourcefactories.sourcelist.storemodel) == 1
- # and not len(instance.PiTiVi.current.timeline.videocomp):
+ # and not len(self.pitivi.current.timeline.videocomp):
pass
## UI Callbacks
@@ -346,7 +350,7 @@
pass
- instance.PiTiVi.shutdown()
+ self.pitivi.shutdown()
def _keyPressEventCb(self, unused_widget, event):
@@ -356,7 +360,7 @@
## Toolbar/Menu actions callback
def _newProjectMenuCb(self, unused_action):
- instance.PiTiVi.newBlankProject()
+ self.pitivi.newBlankProject()
def _openProjectCb(self, unused_action):
chooser = gtk.FileChooserDialog(_("Open File ..."),
@@ -381,22 +385,22 @@
if response == gtk.RESPONSE_OK:
path = chooser.get_filename()
- instance.PiTiVi.loadProject(filepath = path)
+ self.pitivi.loadProject(filepath = path)
chooser.destroy()
return True
def _saveProjectCb(self, unused_action):
- instance.PiTiVi.current.save()
+ self.pitivi.current.save()
def _saveProjectAsCb(self, unused_action):
- instance.PiTiVi.current.saveAs()
+ self.pitivi.current.saveAs()
def _projectSettingsCb(self, unused_action):
- l = ProjectSettingsDialog(self, instance.PiTiVi.current)
+ l = ProjectSettingsDialog(self, self.pitivi.current)
l.show()
def _quitCb(self, unused_action):
- instance.PiTiVi.shutdown()
+ self.pitivi.shutdown()
def _fullScreenCb(self, unused_action):
self.toggleFullScreen()
@@ -434,7 +438,7 @@
self.sourcefactories.sourcelist.showImportSourcesDialog(True)
def _pluginManagerCb(self, unused_action):
- PluginManagerDialog(instance.PiTiVi.plugin_manager)
+ PluginManagerDialog(self.pitivi.plugin_manager)
@@ -636,7 +640,7 @@
if self.outfile and not self.rendering:
if self.bin.record(self.outfile, self.settings):
self.timestarted = time.time()
- self.positionhandler = instance.PiTiVi.playground.connect('position', self._positionCb)
+ self.positionhandler = self.pitivi.playground.connect('position', self._positionCb)
self.rendering = True
self.cancelbutton.set_label("gtk-cancel")
self.progressbar.set_text(_("Rendering"))
@@ -663,7 +667,7 @@
def _eosCb(self, unused_bus, unused_message):
self.rendering = False
if self.positionhandler:
- instance.PiTiVi.playground.disconnect(self.positionhandler)
+ self.pitivi.playground.disconnect(self.positionhandler)
self.positionhandler = 0
self.progressbar.set_text(_("Rendering Complete"))
self.progressbar.set_fraction(1.0)
@@ -675,7 +679,7 @@
def _cancelButtonClickedCb(self, unused_button):
self.bin.stopRecording()
if self.positionhandler:
- instance.PiTiVi.playground.disconnect(self.positionhandler)
+ self.pitivi.playground.disconnect(self.positionhandler)
self.positionhandler = 0
- instance.PiTiVi.playground.pause()
+ self.pitivi.playground.pause()
self.destroy()
Modified: trunk/tests/test_basic.py
==============================================================================
--- trunk/tests/test_basic.py (original)
+++ trunk/tests/test_basic.py Thu Oct 16 14:20:35 2008
@@ -8,7 +8,7 @@
"""
def testBasic(self):
- ptv = pitivi.pitivi.Pitivi(use_ui=False)
+ ptv = pitivi.pitivi.Pitivi()
# was the pitivi object created
self.assert_(ptv)
Modified: trunk/tests/test_file_load_save.py
==============================================================================
--- trunk/tests/test_file_load_save.py (original)
+++ trunk/tests/test_file_load_save.py Thu Oct 16 14:20:35 2008
@@ -62,7 +62,7 @@
"""
def setUp(self):
- self.ptv = pitivi.pitivi.Pitivi(use_ui=False)
+ self.ptv = pitivi.pitivi.Pitivi()
# was the pitivi object created
self.assert_(self.ptv)
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]