[pitivi] timeline: Fix traceback when opening project from the wizard



commit 817889761cf5f6f59571395b2ce5d6542aa2d628
Author: Alexandru Băluț <alexandru balut gmail com>
Date:   Wed Jun 22 23:55:24 2016 +0200

    timeline: Fix traceback when opening project from the wizard
    
    When the startup wizard is on top of the timeline and you double-click a
    project in the list to be loaded, the button-release-event is triggered
    for the timeline. It might be a bug in GTK, but in any case, we can
    solve this very nicely by connecting the timeline's button-release-event
    handler later, when the project is loaded. This required moving the
    logic from new-project-created handler to new-project-loaded which seems
    to work ok.
    
    I then had to replace some connect calls with connect_after so various
    initializations which depend on the timeline are done after the
    timeline's initialization.
    
    Fixes https://phabricator.freedesktop.org/T7471
    
    Differential Revision: https://phabricator.freedesktop.org/D1106

 pitivi/clipproperties.py    |    4 ++--
 pitivi/timeline/timeline.py |   41 ++++++++++++++++++++---------------------
 pitivi/titleeditor.py       |    2 +-
 3 files changed, 23 insertions(+), 24 deletions(-)
---
diff --git a/pitivi/clipproperties.py b/pitivi/clipproperties.py
index e63622d..fb62f6c 100644
--- a/pitivi/clipproperties.py
+++ b/pitivi/clipproperties.py
@@ -243,7 +243,7 @@ class EffectProperties(Gtk.Expander, Loggable):
         self.treeview.connect("drag-leave", self._dragLeaveCb)
         self.treeview.connect("drag-data-received", self._dragDataReceivedCb)
         self.treeview.connect("query-tooltip", self._treeViewQueryTooltipCb)
-        self.app.project_manager.connect(
+        self.app.project_manager.connect_after(
             "new-project-loaded", self._newProjectLoadedCb)
         self.connect('notify::expanded', self._expandedCb)
 
@@ -556,7 +556,7 @@ class TransformationProperties(Gtk.Expander, Loggable):
         self._initButtons()
         self.hide()
 
-        self.app.project_manager.connect(
+        self.app.project_manager.connect_after(
             "new-project-loaded", self._newProjectLoadedCb)
 
     def _newProjectLoadedCb(self, unused_app, project):
diff --git a/pitivi/timeline/timeline.py b/pitivi/timeline/timeline.py
index 6e1f821..65d8f18 100644
--- a/pitivi/timeline/timeline.py
+++ b/pitivi/timeline/timeline.py
@@ -250,9 +250,6 @@ class Timeline(Gtk.EventBox, Zoomable, Loggable):
 
         # A lot of operations go through these callbacks.
         self.add_events(Gdk.EventType.BUTTON_PRESS | Gdk.EventType.BUTTON_RELEASE)
-        self.connect("button-press-event", self._button_press_event_cb)
-        self.connect("button-release-event", self._button_release_event_cb)
-        self.connect("motion-notify-event", self._motion_notify_event_cb)
 
         self._layers = []
         # Whether the user is dragging a layer.
@@ -338,6 +335,10 @@ class Timeline(Gtk.EventBox, Zoomable, Loggable):
     def setProject(self, project):
         """Connects to the GES.Timeline holding the project."""
         if self.ges_timeline is not None:
+            self.disconnect_by_func(self._button_press_event_cb)
+            self.disconnect_by_func(self._button_release_event_cb)
+            self.disconnect_by_func(self._motion_notify_event_cb)
+
             self.ges_timeline.disconnect_by_func(self._durationChangedCb)
             self.ges_timeline.disconnect_by_func(self._layerAddedCb)
             self.ges_timeline.disconnect_by_func(self._layerRemovedCb)
@@ -368,6 +369,10 @@ class Timeline(Gtk.EventBox, Zoomable, Loggable):
         self.ges_timeline.connect("snapping-started", self._snapCb)
         self.ges_timeline.connect("snapping-ended", self._snapEndedCb)
 
+        self.connect("button-press-event", self._button_press_event_cb)
+        self.connect("button-release-event", self._button_release_event_cb)
+        self.connect("motion-notify-event", self._motion_notify_event_cb)
+
         self.queue_draw()
 
     def _durationChangedCb(self, ges_timeline, pspec):
@@ -1170,8 +1175,6 @@ class TimelineContainer(Gtk.Grid, Zoomable, Loggable):
         self._settings.connect("edgeSnapDeadbandChanged",
                                self._snapDistanceChangedCb)
 
-        self.app.project_manager.connect("new-project-created",
-                                         self._projectCreatedCb)
         self.app.project_manager.connect("new-project-loaded",
                                          self._projectLoadedCb)
 
@@ -1784,22 +1787,7 @@ class TimelineContainer(Gtk.Grid, Zoomable, Loggable):
                 Zoomable.pixelToNs(self._settings.edgeSnapDeadband))
 
     def _projectLoadedCb(self, unused_app, project):
-        """Connects to the project's pipeline."""
-        assert self._project is project
-        if self._project:
-            self.ruler.setPipeline(self._project.pipeline)
-
-            self.ruler.setProjectFrameRate(self._project.videorate)
-            self.ruler.zoomChanged()
-
-            self._renderingSettingsChangedCb(self._project, None, None)
-            self._setBestZoomRatio()
-            if self.ges_timeline:
-                self.ges_timeline.set_snapping_distance(
-                    Zoomable.pixelToNs(self._settings.edgeSnapDeadband))
-
-    def _projectCreatedCb(self, unused_app, project):
-        """Connects to the project's timeline."""
+        """Connects to the project's timeline and pipeline."""
         if self._project:
             self._project.disconnect_by_func(self._renderingSettingsChangedCb)
             try:
@@ -1813,6 +1801,17 @@ class TimelineContainer(Gtk.Grid, Zoomable, Loggable):
             self.timeline._pipeline = None
 
         self.setProject(project)
+        if project:
+            self.ruler.setPipeline(project.pipeline)
+
+            self.ruler.setProjectFrameRate(project.videorate)
+            self.ruler.zoomChanged()
+
+            self._renderingSettingsChangedCb(project, None, None)
+            self._setBestZoomRatio()
+            if self.ges_timeline:
+                self.ges_timeline.set_snapping_distance(
+                    Zoomable.pixelToNs(self._settings.edgeSnapDeadband))
 
     def _zoomInCb(self, unused_action, unused_parameter):
         Zoomable.zoomIn()
diff --git a/pitivi/titleeditor.py b/pitivi/titleeditor.py
index 82d9d87..03faeb8 100644
--- a/pitivi/titleeditor.py
+++ b/pitivi/titleeditor.py
@@ -62,7 +62,7 @@ class TitleEditor(Loggable):
         # Updates the UI.
         self.set_source(None)
 
-        self.app.project_manager.connect(
+        self.app.project_manager.connect_after(
             "new-project-loaded", self._newProjectLoadedCb)
 
     def _createUI(self):


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