[pitivi: 4/10] Expose viewer API externally



commit 8e951681faf18a21f8cf21019501633bb8cfc45a
Author: Brandon Lewis <brandon_lewis berkeley edu>
Date:   Sun Mar 8 23:50:48 2009 -0700

    Expose viewer API externally
---
 pitivi/ui/actions.xml   |    2 +
 pitivi/ui/mainwindow.py |   66 +++++++++++++++++++++++++++++++++++++++++-
 pitivi/ui/timeline.py   |   20 ++++++------
 pitivi/ui/viewer.py     |   73 ++++++++++++++++++++++++++++++++++++----------
 4 files changed, 134 insertions(+), 27 deletions(-)

diff --git a/pitivi/ui/actions.xml b/pitivi/ui/actions.xml
index 5a279c8..353ae90 100644
--- a/pitivi/ui/actions.xml
+++ b/pitivi/ui/actions.xml
@@ -38,5 +38,7 @@
     <toolitem action="FullScreen" />
   </toolbar>
   <toolbar name="TimelineToolBar">
+        <placeholder name="Timeline" />
+        <separator />
   </toolbar>
 </ui>
diff --git a/pitivi/ui/mainwindow.py b/pitivi/ui/mainwindow.py
index 97c6420..a158d59 100644
--- a/pitivi/ui/mainwindow.py
+++ b/pitivi/ui/mainwindow.py
@@ -204,6 +204,14 @@ class PitiviMainWindow(gtk.Window, Loggable):
         self.render_button.set_sensitive(sensitive)
 
     def _setActions(self):
+        PLAY = _("Start Playback")
+        PAUSE = _("Stop Playback")
+        FRAME_FORWARD = _("Forward one frame")
+        FAST_FORWARD = _("Fast Forward")
+        LOOP = _("Loop over selected area")
+        REWIND = _("Rewind")
+        FRAME_BACK = _("Back one frame")
+
         """ sets up the GtkActions """
         self.actions = [
             ("NewProject", gtk.STOCK_NEW, None,
@@ -236,6 +244,20 @@ class PitiviMainWindow(gtk.Window, Loggable):
             ("File", None, _("_File")),
             ("Edit", None, _("_Edit")),
             ("View", None, _("_View")),
+            ("Rewind", gtk.STOCK_MEDIA_REWIND, None, None, REWIND,
+                self.rewind),
+            ("FrameBack", gtk.STOCK_MEDIA_PREVIOUS, None, None, FRAME_BACK,
+                self.frameBack),
+            ("Play", gtk.STOCK_MEDIA_PLAY, None, None, PLAY,
+                self.play),
+            ("Pause", gtk.STOCK_MEDIA_PAUSE, None, None, PAUSE,
+                self.pause),
+            ("FrameForward", gtk.STOCK_MEDIA_NEXT, None, None, FRAME_FORWARD,
+                self.frameForward),
+            ("FastForward", gtk.STOCK_MEDIA_FORWARD, None, None, FAST_FORWARD,
+                self.fastForward),
+            ("Loop", gtk.STOCK_REFRESH, _("Loop"), None, LOOP,
+                self.loop),
             ("Help", None, _("_Help")),
         ]
 
@@ -265,7 +287,8 @@ class PitiviMainWindow(gtk.Window, Loggable):
             elif action_name in [
                 "ProjectSettings", "Quit", "File", "Edit", "Help",
                 "About", "View", "FullScreen", "ImportSources",
-                "ImportSourcesFolder", "PluginManager"]:
+                "ImportSourcesFolder", "PluginManager",
+                "Play", "Pause"]:
                 action.set_sensitive(True)
             elif action_name in ["SaveProject", "SaveProjectAs",
                     "NewProject", "OpenProject"]:
@@ -562,6 +585,27 @@ class PitiviMainWindow(gtk.Window, Loggable):
         else:
             self.webcam_button.set_sensitive(True)
 
+    def rewind(self, unused_action):
+        pass
+
+    def frameBack(self, unused_action):
+        pass
+
+    def play(self, unused_action):
+        self.viewer.play()
+
+    def pause(self, unused_action):
+        self.viewer.pause()
+
+    def frameForward(self, unused_action):
+        pass
+
+    def fastForward(self, unused_action):
+        pass
+
+    def loop(self, unused_action):
+        pass
+
     ## PiTiVi main object callbacks
 
     def _newProjectLoadedCb(self, unused_pitivi, project):
@@ -716,6 +760,26 @@ class PitiviMainWindow(gtk.Window, Loggable):
         self.app.current.timeline.addSourceFactory(factory)
         context.finish(True, False, timestamp)
 
+    def _getTimelinePipeline(self):
+        # FIXME: the timeline pipeline should probably be moved in project
+        try:
+            return self._timeline_pipeline, self._timeline_view_action
+        except AttributeError:
+            pass
+
+        timeline = self.pitivi.current.timeline
+        factory = TimelineSourceFactory(timeline)
+        pipeline = Pipeline()
+        pipeline.activatePositionListener()
+        pipeline.connect('position', self._timelinePipelinePositionChangedCb)
+        action = ViewAction()
+        action.addProducers(factory)
+
+        self._timeline_pipeline = pipeline
+        self._timeline_view_action = action
+
+        return self._timeline_pipeline, self._timeline_view_action
+
     def _timelineRulerSeekCb(self, ruler, position):
         self.debug("position:%s", gst.TIME_ARGS (position))
         self.viewer.setAction(self.project.view_action)
diff --git a/pitivi/ui/timeline.py b/pitivi/ui/timeline.py
index fd391a2..2809a2f 100644
--- a/pitivi/ui/timeline.py
+++ b/pitivi/ui/timeline.py
@@ -53,16 +53,16 @@ SELECT_AFTER = ("Select all after selected")
 ui = '''
 <ui>
     <toolbar name="TimelineToolBar">
-        <toolitem action="ZoomOut" />
-        <toolitem action="ZoomIn" />
-        <separator />
-        <toolitem action="Razor" />
-        <separator />
-        <toolitem action="DeleteObj" />
-        <toolitem action="UnlinkObj" />
-        <toolitem action="LinkObj" />
-        <toolitem action="UngroupObj" />
-        <toolitem action="GroupObj" />
+        <placeholder name="Timeline">
+            <toolitem action="ZoomOut" />
+            <toolitem action="ZoomIn" />
+            <separator />
+            <toolitem action="Razor" />
+            <separator />
+            <toolitem action="DeleteObj" />
+            <toolitem action="UnlinkObj" />
+            <toolitem action="LinkObj" />
+        </placeholder>
     </toolbar>
     <accelerator action="DeleteObj" />
 </ui>
diff --git a/pitivi/ui/viewer.py b/pitivi/ui/viewer.py
index bb94077..70743e0 100644
--- a/pitivi/ui/viewer.py
+++ b/pitivi/ui/viewer.py
@@ -36,6 +36,13 @@ class ViewerError(Exception):
 # TODO : Switch to using Pipeline and Action
 
 class PitiviViewer(gtk.VBox, Loggable):
+
+    __gtype_name__ = 'PitiviViewer'
+    __gsignals__ = {
+        "activate-playback-controls" : (gobject.SIGNAL_RUN_LAST, 
+            gobject.TYPE_NONE, (gobject.TYPE_BOOLEAN,)),
+    }
+
     """
     A Widget to control and visualize a Pipeline
 
@@ -116,6 +123,7 @@ class PitiviViewer(gtk.VBox, Loggable):
             # get the default action
             action = self._getDefaultAction()
         self._connectToAction(action)
+        self.showControls()
 
     def _connectToPipeline(self, pipeline):
         self.debug("pipeline:%r", pipeline)
@@ -161,6 +169,7 @@ class PitiviViewer(gtk.VBox, Loggable):
         # FIXME: fix this properly?
         self.drawingarea.action = action
         self.drawingarea.have_set_xid = False
+        self.showControls()
 
     def _disconnectFromAction(self):
         self.action = None
@@ -173,6 +182,8 @@ class PitiviViewer(gtk.VBox, Loggable):
                          self.playpause_button, self.next_button,
                          self.forward_button, self.timelabel]:
                 item.set_sensitive(active)
+        if active:
+            self.emit("activate-playback-controls", True)
 
     def _getDefaultAction(self):
         return ViewAction()
@@ -238,16 +249,26 @@ class PitiviViewer(gtk.VBox, Loggable):
         self.timelabel.set_alignment(1.0, 0.5)
         self.timelabel.set_padding(5, 5)
         bbox.pack_start(self.timelabel, expand=False, padding=10)
-
-        # self.detach_button = gtk.Button()
-        # image = gtk.Image()
-        # image.set_from_stock(gtk.STOCK_LEAVE_FULLSCREEN,
-        #     gtk.ICON_SIZE_SMALL_TOOLBAR)
-        # self.detach_button.set_image(image)
-        # bbox.pack_end(self.detach_button, expand=False, fill=False)
-
         self._haveUI = True
 
+    def showControls(self):
+        if not self.action:
+            return
+        if True:
+            self.rewind_button.show()
+            self.back_button.show()
+            self.playpause_button.show()
+            self.next_button.show()
+            self.forward_button.show()
+            self.slider.show()
+        else:
+            self.rewind_button.hide()
+            self.back_button.hide()
+            self.playpause_button.hide()
+            self.next_button.hide()
+            self.forward_button.hide()
+            self.slider.hide()
+
     def setDisplayAspectRatio(self, ratio):
         """ Sets the DAR of the Viewer to the given ratio """
         self.debug("Setting ratio of %f [%r]", float(ratio), ratio)
@@ -373,27 +394,47 @@ class PitiviViewer(gtk.VBox, Loggable):
     ## Control gtk.Button callbacks
 
     def _rewindCb(self, unused_button):
-        pass
+        self.rewind()
 
     def _backCb(self, unused_button):
-        raise NotImplementedError
+        self.back()
 
     def _playButtonCb(self, unused_button, isplaying):
         if self.pipeline is None:
             return
 
         if isplaying:
-            if not self.pipeline.play() == gst.STATE_CHANGE_FAILURE:
-                self.currentState = gst.STATE_PLAYING
+            self.pause()
         else:
-            if not self.pipeline.pause() == gst.STATE_CHANGE_FAILURE:
-                self.currentState = gst.STATE_PAUSED
+            self.play()
 
     def _nextCb(self, unused_button):
-        raise NotImplementedError
+        self.next()
 
     def _forwardCb(self, unused_button):
-        pass
+        self.forward()
+
+    ## public methods for controlling playback
+
+    def play(self):
+        if not self.pipeline.play() == gst.STATE_CHANGE_FAILURE:
+            self.currentState = gst.STATE_PLAYING
+
+    def pause(self):
+        if not self.pipeline.pause() == gst.STATE_CHANGE_FAILURE:
+            self.currentState = gst.STATE_PAUSED
+
+    def rewind(self):
+        raise NotImplementedError
+
+    def back(self):
+        raise NotImplementedError
+
+    def next(self):
+        raise NotImplementedError
+
+    def forward(self):
+        raise NotImplementedError
 
     def _posCb(self, unused_pipeline, pos):
         self._newTime(pos)



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