[pitivi/ges: 240/287] Cleanup timeline var names and fix the render button sensitivity



commit dbf868262289b7fa1809cc5624c9c16c3d61f9ab
Author: Jean-FranÃois Fortin Tam <nekohayo gmail com>
Date:   Fri Jan 27 18:41:49 2012 +0100

    Cleanup timeline var names and fix the render button sensitivity
    
    timeline for the GESTimeline, timeline_ui for pitivi's timeline UI
    
    Also fix incorrect instanciation of the render dialog that forced
    the use of "self.app.app" instead of "self.app".

 pitivi/mainwindow.py        |   53 ++++++++++++++++++++++---------------------
 pitivi/medialibrary.py      |    2 +-
 pitivi/render.py            |    9 +++----
 pitivi/timeline/timeline.py |   27 ++++++++-------------
 pitivi/timeline/track.py    |    4 +-
 pitivi/utils/timeline.py    |    4 +-
 6 files changed, 46 insertions(+), 53 deletions(-)
---
diff --git a/pitivi/mainwindow.py b/pitivi/mainwindow.py
index be2f8cf..211f577 100644
--- a/pitivi/mainwindow.py
+++ b/pitivi/mainwindow.py
@@ -176,7 +176,6 @@ class PitiviMainWindow(gtk.Window, Loggable):
         self.actiongroup = None
         self.settings = instance.settings
         self.is_fullscreen = False
-        self.timelinepos = 0
         self.prefsdialog = None
         create_stock_icons()
         self._setActions(instance)
@@ -220,7 +219,7 @@ class PitiviMainWindow(gtk.Window, Loggable):
         """
         from pitivi.render import RenderDialog
 
-        dialog = RenderDialog(self, project)
+        dialog = RenderDialog(self.app, project)
         dialog.window.connect("destroy", self._renderDialogDestroyCb)
         self.set_sensitive(False)
         dialog.window.show()
@@ -322,9 +321,10 @@ class PitiviMainWindow(gtk.Window, Loggable):
         for action in self.actiongroup.list_actions():
             action_name = action.get_name()
             if action_name == "RenderProject":
-                # this will be set sensitive when the timeline duration changes
-                self.render_button = action
+                # the button is set sensitive when the timeline duration changes
+                action.set_sensitive(False)
                 action.props.is_important = True
+                self.render_button = action
             elif action_name in ["NewProject", "SaveProjectAs", "OpenProject"]:
                 if instance.settings.fileSupportEnabled:
                     action.set_sensitive(True)
@@ -377,13 +377,11 @@ class PitiviMainWindow(gtk.Window, Loggable):
         vbox.pack_start(vpaned)
         vpaned.show()
 
-        self.timeline = Timeline(instance, self.uimanager)
-        self.timeline.connect("duration-changed",
-                self._timelineDurationChangedCb)
+        self.timeline_ui = Timeline(instance, self.uimanager)
         self.project = None
 
-        vpaned.pack2(self.timeline, resize=True, shrink=False)
-        self.timeline.show()
+        vpaned.pack2(self.timeline_ui, resize=True, shrink=False)
+        self.timeline_ui.show()
         self.mainhpaned = gtk.HPaned()
         vpaned.pack1(self.mainhpaned, resize=True, shrink=False)
 
@@ -409,7 +407,7 @@ class PitiviMainWindow(gtk.Window, Loggable):
         # Actions with key accelerators that will be made unsensitive while
         # a gtk entry box is used to avoid conflicts.
         self.sensitive_actions = []
-        for action in self.timeline.playhead_actions:
+        for action in self.timeline_ui.playhead_actions:
             self.sensitive_actions.append(action[0])
         for action in self.toggleactions:
             self.sensitive_actions.append(action[0])
@@ -504,8 +502,8 @@ class PitiviMainWindow(gtk.Window, Loggable):
             if action.get_name() in action_names:
                 action.set_sensitive(sensitive)
 
-        if self.timeline:
-            for action_group in self.timeline.ui_manager.get_action_groups():
+        if self.timeline_ui:
+            for action_group in self.timeline_ui.ui_manager.get_action_groups():
                 for action in action_group.list_actions():
                     if action.get_name() in action_names:
                         action.set_sensitive(sensitive)
@@ -550,7 +548,7 @@ class PitiviMainWindow(gtk.Window, Loggable):
     def _mediaLibrarySourceRemovedCb(self, medialibrary, uri, unused_info):
         """When a clip is removed from the Media Library, tell the timeline
         to remove all instances of that clip."""
-        self.timeline.purgeObject(uri)
+        self.timeline_ui.purgeObject(uri)
 
 ## Toolbar/Menu actions callback
 
@@ -700,6 +698,8 @@ class PitiviMainWindow(gtk.Window, Loggable):
         """
         self.log("A new project is loaded, wait for clips")
         self._connectToProjectSources(project.medialibrary)
+        project.timeline.connect("notify::duration",
+                self._timelineDurationChangedCb)
 
         # This should only be done when loading a project, and disconnected
         # as soon as we receive the signal.
@@ -722,8 +722,9 @@ class PitiviMainWindow(gtk.Window, Loggable):
             self.actiongroup.get_action("SaveProject").set_sensitive(True)
             self._missingUriOnLoading = False
 
-        if self.timeline.duration != 0:
+        if self.app.current.timeline.props.duration != 0:
             self.setBestZoomRatio()
+            self.render_button.set_sensitive(True)
         else:
             self._zoom_duration_changed = True
 
@@ -737,10 +738,10 @@ class PitiviMainWindow(gtk.Window, Loggable):
 
     def setBestZoomRatio(self, p=0):
         """Set the zoom level so that the entire timeline is in view."""
-        ruler_width = self.timeline.ruler.get_allocation()[2]
+        ruler_width = self.timeline_ui.ruler.get_allocation()[2]
         # Add gst.SECOND - 1 to the timeline duration to make sure the
         # last second of the timeline will be in view.
-        duration = self.timeline.duration
+        duration = self.app.current.timeline.props.duration
         timeline_duration = duration + gst.SECOND - 1
         timeline_duration_s = int(timeline_duration / gst.SECOND)
 
@@ -995,11 +996,10 @@ class PitiviMainWindow(gtk.Window, Loggable):
         if project:
             self.project = project
             self.project_pipeline = self.project.pipeline
-            self.project_timeline = self.project.timeline
             self.viewer.setPipeline(project.pipeline)
             self._settingsChangedCb(project, None, project.settings)
-            if self.timeline:
-                self.timeline.setProject(self.project)
+            if self.timeline_ui:
+                self.timeline_ui.setProject(self.project)
                 self.clipconfig.project = self.project
                 #FIXME GES port undo/redo
                 #self.app.timelineLogObserver.pipeline = self.project.pipeline
@@ -1029,19 +1029,20 @@ class PitiviMainWindow(gtk.Window, Loggable):
 
     project_pipeline = property(getProjectPipeline, setProjectPipeline, None, "The Gst.Pipeline of the project")
 
-    def _timelinePipelineStateChanged(self, pipeline, state):
-        self.timeline.stateChanged(state)
+    def _timelinePipelineStateChanged(self, unused_pipeline, state):
+        self.timeline_ui.stateChanged(state)
 
 ## Project Timeline (not to be confused with UI timeline)
 
-    def _timelineDurationChangedCb(self, timeline, duration):
-        if timeline.duration > 0:
+    def _timelineDurationChangedCb(self, timeline, unused_duration):
+        self.debug("Timeline duration changed to %d", timeline.props.duration)
+        if timeline.props.duration > 0:
             sensitive = True
             if self._zoom_duration_changed:
                 self.setBestZoomRatio()
                 self._zoom_duration_changed = False
             else:
-                self.timeline.updateScrollAdjustments()
+                self.timeline_ui.updateScrollAdjustments()
         else:
             sensitive = False
         self.render_button.set_sensitive(sensitive)
@@ -1202,8 +1203,8 @@ class PitiviMainWindow(gtk.Window, Loggable):
 
     def _timelineSeekCb(self, ruler, position, format):
         try:
-            # CLAMP (0, position, self.timeline.getDuration())
-            position = sorted((0, position, self.timeline.getDuration()))[1]
+            # CLAMP (0, position, self.app.current.timeline.props.duration)
+            position = sorted((0, position, self.app.current.timeline.props.duration))[1]
 
             if not self.project_pipeline.seek(1.0, format, gst.SEEK_FLAG_FLUSH,
                     gst.SEEK_TYPE_SET, position, gst.SEEK_TYPE_NONE, -1):
diff --git a/pitivi/medialibrary.py b/pitivi/medialibrary.py
index 832ddd2..e3a89c6 100644
--- a/pitivi/medialibrary.py
+++ b/pitivi/medialibrary.py
@@ -542,7 +542,7 @@ class MediaLibraryWidget(gtk.VBox, Loggable):
         self.app.current.timeline.enable_update(False)
 
         # Handle the case of a blank project
-        self.app.gui.timeline._ensureLayer()
+        self.app.gui.timeline_ui._ensureLayer()
 
         self._sources_to_insert = self.getSelectedItems()
         # Start adding sources in the timeline
diff --git a/pitivi/render.py b/pitivi/render.py
index ac99306..0dce67b 100644
--- a/pitivi/render.py
+++ b/pitivi/render.py
@@ -321,7 +321,7 @@ class RenderingProgressDialog(Signallable):
 
     def __init__(self, app, parent):
         self.app = app
-        self.system = app.app.system
+        self.system = app.system
         self.builder = gtk.Builder()
         self.builder.add_from_file(os.path.join(configure.get_ui_dir(),
             "renderingprogress.ui"))
@@ -333,7 +333,7 @@ class RenderingProgressDialog(Signallable):
         self.play_pause_button = self.builder.get_object("play_pause_button")
         # Parent the dialog with mainwindow, since renderingdialog is hidden.
         # It allows this dialog to properly minimize together with mainwindow
-        self.window.set_transient_for(self.app)
+        self.window.set_transient_for(self.app.gui)
 
         # UI widgets
         self.window.set_icon_from_file(configure.get_pixmap_dir() + "/pitivi-render-16.png")
@@ -383,8 +383,7 @@ class RenderDialog(Loggable):
 
         self.app = app
         self.project = project
-        self.system = app.app.system
-        self._timeline = self.app.timeline
+        self.system = app.system
         self._seeker = Seeker(80)
         if pipeline != None:
             self._pipeline = pipeline
@@ -1001,7 +1000,7 @@ class RenderDialog(Loggable):
         if self.progress:
             text = None
             timediff = time.time() - self.timestarted
-            length = self._timeline.duration
+            length = self.app.current.timeline.props.duration
             fraction = float(min(position, length)) / float(length)
             if timediff > 5.0 and position:
                 # only display ETA after 5s in order to have enough averaging and
diff --git a/pitivi/timeline/timeline.py b/pitivi/timeline/timeline.py
index e6350cb..f8282d4 100644
--- a/pitivi/timeline/timeline.py
+++ b/pitivi/timeline/timeline.py
@@ -231,7 +231,7 @@ class TimelineCanvas(goocanvas.Canvas, Zoomable, Loggable):
 
     def from_event(self, event):
         x, y = event.x, event.y
-        x += self.app.gui.timeline.hadj.get_value()
+        x += self.app.gui.timeline_ui.hadj.get_value()
         return Point(*self.convert_from_pixels(x, y))
 
     def setExpanded(self, track_object, expanded):
@@ -323,7 +323,7 @@ class TimelineCanvas(goocanvas.Canvas, Zoomable, Loggable):
             self._got_motion_notify = True
             cur = self.from_event(event)
             pos, size = self._normalize(self._mousedown, cur,
-                self.app.gui.timeline.hadj.get_value())
+                self.app.gui.timeline_ui.hadj.get_value())
             self._marquee.props.x, self._marquee.props.y = pos
             self._marquee.props.width, self._marquee.props.height = size
             return True
@@ -555,12 +555,12 @@ class InfoStub(gtk.HBox, Loggable):
 
 
 class Timeline(gtk.Table, Loggable, Zoomable):
+    """
+    Initiate and manage the timeline's user interface components.
 
-    __gtype_name__ = 'Timeline'
-    __gsignals__ = {
-        "duration-changed": (gobject.SIGNAL_RUN_LAST,
-            gobject.TYPE_NONE, (gobject.TYPE_INT,)),
-    }
+    This class is not to be confused with project.py's
+    "timeline" instance of GESTimeline.
+    """
 
     def __init__(self, instance, ui_manager):
         gtk.Table.__init__(self, rows=2, columns=1, homogeneous=False)
@@ -577,11 +577,9 @@ class Timeline(gtk.Table, Loggable, Zoomable):
         self._position = 0
         self._state = gst.STATE_NULL
         self._createUI()
-        self._prev_duration = 0
         self.rate = gst.Fraction(1, 1)
         self._project = None
         self._timeline = None
-        self._duration = 0
         self._creating_tckobjs_sigid = {}
 
         #Ids of the tracks notify::duration signals
@@ -834,7 +832,7 @@ class Timeline(gtk.Table, Loggable, Zoomable):
             return True
 
         elif context.targets in DND_EFFECT_LIST:
-            if self._duration == 0:
+            if self.app.current.timeline.props.duration == 0:
                 return False
 
             factory = self._factories[0]
@@ -873,11 +871,6 @@ class Timeline(gtk.Table, Loggable, Zoomable):
 
         return False
 
-    def getDuration(self):
-        return self.timeline.props.duration
-
-    duration = property(getDuration, None, None, "The duration property")
-
     def _dragDataReceivedCb(self, unused_layout, context, x, y,
         selection, targetType, timestamp):
         self.app.projectManager.current.timeline.enable_update(False)
@@ -893,7 +886,7 @@ class Timeline(gtk.Table, Loggable, Zoomable):
             self._factories = \
                 [self._project.medialibrary.getInfoFromUri(uri) for uri in uris]
         else:
-            if not self._duration:
+            if not self.app.current.timeline.props.duration > 0:
                 return False
             self._factories = [self.app.effects.getFactoryFromName(selection.data)]
 
@@ -1199,7 +1192,7 @@ class Timeline(gtk.Table, Loggable, Zoomable):
 
     def updateScrollAdjustments(self):
         a = self.get_allocation()
-        size = Zoomable.nsToPixel(self.duration)
+        size = Zoomable.nsToPixel(self.app.current.timeline.props.duration)
         self.hadj.props.lower = 0
         self.hadj.props.upper = size + 200  # why is this necessary???
         self.hadj.props.page_size = a.width
diff --git a/pitivi/timeline/track.py b/pitivi/timeline/track.py
index e9d0ce7..01416ac 100644
--- a/pitivi/timeline/track.py
+++ b/pitivi/timeline/track.py
@@ -529,8 +529,8 @@ class TrackObject(View, goocanvas.Group, Zoomable):
                 self.namebg.props.visibility = goocanvas.ITEM_VISIBLE
             else:
                 self.namebg.props.visibility = goocanvas.ITEM_INVISIBLE
-        self.app.gui.timeline._canvas.regroupTracks()
-        self.app.gui.timeline.unsureVadjHeight()
+        self.app.gui.timeline_ui._canvas.regroupTracks()
+        self.app.gui.timeline_ui.unsureVadjHeight()
 
 TRACK_CONTROL_WIDTH = 75
 
diff --git a/pitivi/utils/timeline.py b/pitivi/utils/timeline.py
index 6964288..0cc3096 100644
--- a/pitivi/utils/timeline.py
+++ b/pitivi/utils/timeline.py
@@ -1093,8 +1093,8 @@ class Controller(Loggable):
         if not self._canvas:
             self._canvas = item.get_canvas()
             # might there be a better way to do this?
-            self._hadj = self._canvas.app.gui.timeline.hadj
-            self._vadj = self._canvas.app.gui.timeline.vadj
+            self._hadj = self._canvas.app.gui.timeline_ui.hadj
+            self._vadj = self._canvas.app.gui.timeline_ui.vadj
         self._last_event = event
         s = event.get_state()
         self._shift_down = s & gtk.gdk.SHIFT_MASK



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