[pitivi] timeline: Call setProject only from EditorPerspective



commit f218843f5d1fb5964e51affb94de98ee51bda7c2
Author: Alexandru Băluț <alexandru balut gmail com>
Date:   Thu Aug 29 23:28:50 2019 +0200

    timeline: Call setProject only from EditorPerspective
    
    setProject(None) was being called by EditorPerspective when the project
    was being closed. For consistency, now the EditorPerspective is also
    responsible for calling it when a new project has been loaded, instead
    of detecting that on its own.

 pitivi/editorperspective.py | 29 +++++++++---------------
 pitivi/timeline/timeline.py | 55 +++++++++++++++++++++------------------------
 2 files changed, 36 insertions(+), 48 deletions(-)
---
diff --git a/pitivi/editorperspective.py b/pitivi/editorperspective.py
index 0ff72c30..da4d3f45 100644
--- a/pitivi/editorperspective.py
+++ b/pitivi/editorperspective.py
@@ -438,7 +438,7 @@ class EditorPerspective(Perspective, Loggable):
 # Project management callbacks
 
     def _projectManagerNewProjectLoadedCb(self, project_manager, project):
-        """Starts connecting the UI to the specified project.
+        """Connects the UI to the specified project.
 
         Args:
             project_manager (ProjectManager): The project manager.
@@ -448,7 +448,15 @@ class EditorPerspective(Perspective, Loggable):
 
         self._connectToProject(project)
         project.pipeline.activatePositionListener()
-        self._setProject(project)
+
+        self.clipconfig.project = project
+
+        self.timeline_ui.setProject(project)
+
+        # When creating a blank project there's no project URI yet.
+        if project.uri:
+            folder_path = os.path.dirname(path_from_uri(project.uri))
+            self.settings.lastProjectFolder = folder_path
 
         self.updateTitle()
 
@@ -619,23 +627,6 @@ class EditorPerspective(Perspective, Loggable):
         project.ges_timeline.connect("notify::duration",
                                      self._timelineDurationChangedCb)
 
-    def _setProject(self, project):
-        """Disconnects and then reconnects callbacks to the specified project.
-
-        Args:
-            project (Project): The new current project.
-        """
-        if not project:
-            self.warning("Current project instance does not exist")
-            return False
-
-        self.clipconfig.project = project
-
-        # When creating a blank project there's no project URI yet.
-        if project.uri:
-            folder_path = os.path.dirname(path_from_uri(project.uri))
-            self.settings.lastProjectFolder = folder_path
-
     def _disconnectFromProject(self, project):
         project.disconnect_by_func(self._projectChangedCb)
         project.ges_timeline.disconnect_by_func(self._timelineDurationChangedCb)
diff --git a/pitivi/timeline/timeline.py b/pitivi/timeline/timeline.py
index 1f37fe07..7ee765c5 100644
--- a/pitivi/timeline/timeline.py
+++ b/pitivi/timeline/timeline.py
@@ -1416,8 +1416,6 @@ class TimelineContainer(Gtk.Grid, Zoomable, Loggable):
         self._createUi()
         self._createActions()
 
-        self.app.project_manager.connect("new-project-loaded",
-                                         self._projectLoadedCb)
         self.timeline.connect("size-allocate", self.__timeline_size_allocate_cb)
 
     # Public API
@@ -1529,15 +1527,37 @@ class TimelineContainer(Gtk.Grid, Zoomable, Loggable):
             self._scrollToPixel(x)
 
     def setProject(self, project):
-        self._project = project
+        """Connects to the project's timeline and pipeline."""
         if self._project:
-            self._project.connect("rendering-settings-changed",
-                                  self._rendering_settings_changed_cb)
+            self._project.disconnect_by_func(self._rendering_settings_changed_cb)
+            try:
+                self.timeline._pipeline.disconnect_by_func(
+                    self.timeline.positionCb)
+            except AttributeError:
+                pass
+            except TypeError:
+                pass  # We were not connected no problem
+
+            self.timeline._pipeline = None
+
+        self._project = project
+
+        if project:
+            project.connect("rendering-settings-changed",
+                            self._rendering_settings_changed_cb)
             self.ges_timeline = project.ges_timeline
         else:
             self.ges_timeline = None
 
-        self.timeline.setProject(self._project)
+        self.timeline.setProject(project)
+
+        if project:
+            self.ruler.setPipeline(project.pipeline)
+            self.ruler.zoomChanged()
+            self._update_ruler(project.videorate)
+
+            self.timeline.set_best_zoom_ratio(allow_zoom_in=True)
+            self.timeline.update_snapping_distance()
 
     def updateActions(self):
         selection = self.timeline.selection
@@ -2022,29 +2042,6 @@ class TimelineContainer(Gtk.Grid, Zoomable, Loggable):
         fits = self.timeline.layout.props.height <= allocation.height
         self.vscrollbar.set_opacity(0 if fits else 1)
 
-    def _projectLoadedCb(self, unused_project_manager, project):
-        """Connects to the project's timeline and pipeline."""
-        if self._project:
-            self._project.disconnect_by_func(self._rendering_settings_changed_cb)
-            try:
-                self.timeline._pipeline.disconnect_by_func(
-                    self.timeline.positionCb)
-            except AttributeError:
-                pass
-            except TypeError:
-                pass  # We were not connected no problem
-
-            self.timeline._pipeline = None
-
-        self.setProject(project)
-        if project:
-            self.ruler.setPipeline(project.pipeline)
-            self.ruler.zoomChanged()
-            self._update_ruler(project.videorate)
-
-            self.timeline.set_best_zoom_ratio(allow_zoom_in=True)
-            self.timeline.update_snapping_distance()
-
     def _zoom_in_cb(self, unused_action, unused_parameter):
         Zoomable.zoomIn()
 


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