[pitivi/1.0] project: Avoid propagating incorrect values



commit 5b959c63ed9b9b5b4b4eaf00d033c559936a08d9
Author: Alexandru Băluț <alexandru balut gmail com>
Date:   Sun Dec 31 02:29:44 2017 +0100

    project: Avoid propagating incorrect values
    
    Property setters such as videowidth.setter set `int(value)` and then
    they emit `value`, which can be different. Cleaned up the code a bit.
    
    Differential Revision: https://phabricator.freedesktop.org/D1931

 pitivi/mainwindow.py        |   20 ++++++++------------
 pitivi/project.py           |   23 +++++++++++------------
 pitivi/render.py            |   11 ++++++-----
 pitivi/timeline/timeline.py |   29 ++++++++++-------------------
 4 files changed, 35 insertions(+), 48 deletions(-)
---
diff --git a/pitivi/mainwindow.py b/pitivi/mainwindow.py
index 218e403..97f734b 100644
--- a/pitivi/mainwindow.py
+++ b/pitivi/mainwindow.py
@@ -1014,13 +1014,11 @@ class MainWindow(Gtk.ApplicationWindow, Loggable):
         # FIXME GES we should re-enable this when possible
         # medialibrary.connect("missing-plugins", self._sourceListMissingPluginsCb)
         project.connect("project-changed", self._projectChangedCb)
-        project.connect(
-            "rendering-settings-changed", self._renderingSettingsChangedCb)
+        project.connect("rendering-settings-changed",
+                        self._rendering_settings_changed_cb)
         project.ges_timeline.connect("notify::duration",
                                      self._timelineDurationChangedCb)
 
-# Missing Plugins Support
-
     def _sourceListMissingPluginsCb(
         self, unused_project, unused_uri, unused_factory,
             details, unused_descriptions, missingPluginsCallback):
@@ -1036,8 +1034,6 @@ class MainWindow(Gtk.ApplicationWindow, Loggable):
                                                missingPluginsCallback)
         return res
 
-# Pitivi current project callbacks
-
     def _setProject(self, project):
         """Disconnects and then reconnects callbacks to the specified project.
 
@@ -1049,7 +1045,7 @@ class MainWindow(Gtk.ApplicationWindow, Loggable):
             return False
 
         self.viewer.setPipeline(project.pipeline)
-        self._renderingSettingsChangedCb(project)
+        self._reset_viewer_aspect_ratio(project)
         self.clipconfig.project = project
 
         # When creating a blank project there's no project URI yet.
@@ -1059,12 +1055,14 @@ class MainWindow(Gtk.ApplicationWindow, Loggable):
 
     def _disconnectFromProject(self, project):
         project.disconnect_by_func(self._projectChangedCb)
-        project.disconnect_by_func(self._renderingSettingsChangedCb)
+        project.disconnect_by_func(self._rendering_settings_changed_cb)
         project.ges_timeline.disconnect_by_func(self._timelineDurationChangedCb)
 
-# Pitivi current project callbacks
+    def _rendering_settings_changed_cb(self, project, unused_item):
+        """Handles Project metadata changes."""
+        self._reset_viewer_aspect_ratio(project)
 
-    def _renderingSettingsChangedCb(self, project, unused_item=None, unused_value=None):
+    def _reset_viewer_aspect_ratio(self, project):
         """Resets the viewer aspect ratio."""
         self.viewer.setDisplayAspectRatio(project.getDAR())
         self.viewer.timecode_entry.setFramerate(project.videorate)
@@ -1079,8 +1077,6 @@ class MainWindow(Gtk.ApplicationWindow, Loggable):
         self.debug("Timeline duration changed to %s", duration)
         self.render_button.set_sensitive(duration > 0)
 
-# other
-
     def _showExportDialog(self, project):
         self.log("Export requested")
         chooser = Gtk.FileChooserDialog(title=_("Export To..."),
diff --git a/pitivi/project.py b/pitivi/project.py
index c7a7627..6713f17 100644
--- a/pitivi/project.py
+++ b/pitivi/project.py
@@ -659,8 +659,7 @@ class Project(Loggable, GES.Project):
         "start-importing": (GObject.SignalFlags.RUN_LAST, None, ()),
         "project-changed": (GObject.SignalFlags.RUN_LAST, None, ()),
         "rendering-settings-changed": (GObject.SignalFlags.RUN_LAST, None,
-                                       (GObject.TYPE_PYOBJECT,
-                                        GObject.TYPE_PYOBJECT,)),
+                                       (GObject.TYPE_PYOBJECT,)),
         "settings-set-from-imported-asset": (GObject.SignalFlags.RUN_LAST, None,
                                              (GES.Asset,)),
         "video-size-changed": (GObject.SignalFlags.RUN_LAST, None, ()),
@@ -866,7 +865,7 @@ class Project(Loggable, GES.Project):
     @videowidth.setter
     def videowidth(self, value):
         if self.setVideoRestriction("width", int(value)):
-            self._emitChange("rendering-settings-changed", "width", value)
+            self._emit_change("width")
 
     @property
     def videoheight(self):
@@ -875,7 +874,7 @@ class Project(Loggable, GES.Project):
     @videoheight.setter
     def videoheight(self, value):
         if self.setVideoRestriction("height", int(value)):
-            self._emitChange("rendering-settings-changed", "height", value)
+            self._emit_change("height")
 
     @property
     def videorate(self):
@@ -884,7 +883,7 @@ class Project(Loggable, GES.Project):
     @videorate.setter
     def videorate(self, value):
         if self.setVideoRestriction("framerate", value):
-            self._emitChange("rendering-settings-changed", "videorate", value)
+            self._emit_change("videorate")
 
     @property
     def audiochannels(self):
@@ -893,7 +892,7 @@ class Project(Loggable, GES.Project):
     @audiochannels.setter
     def audiochannels(self, value):
         if self.__setAudioRestriction("channels", int(value)):
-            self._emitChange("rendering-settings-changed", "channels", value)
+            self._emit_change("channels")
 
     @property
     def audiorate(self):
@@ -905,7 +904,7 @@ class Project(Loggable, GES.Project):
     @audiorate.setter
     def audiorate(self, value):
         if self.__setAudioRestriction("rate", int(value)):
-            self._emitChange("rendering-settings-changed", "rate", value)
+            self._emit_change("rate")
 
     @property
     def aencoder(self):
@@ -920,7 +919,7 @@ class Project(Loggable, GES.Project):
             self.audio_profile.set_preset_name(value)
             # Gst.Preset can be set exclusively through EncodingTagets for now.
             self.audio_profile.set_preset(None)
-            self._emitChange("rendering-settings-changed", "aencoder", value)
+            self._emit_change("aencoder")
 
     def _enforce_video_encoder_restrictions(self, encoder, profile=None):
         """Enforces @encoder specific restrictions."""
@@ -944,7 +943,7 @@ class Project(Loggable, GES.Project):
             # Gst.Preset can be set exclusively through EncodingTagets for now.
             self.video_profile.set_preset(None)
             self._enforce_video_encoder_restrictions(value)
-            self._emitChange("rendering-settings-changed", "vencoder", value)
+            self._emit_change("vencoder")
 
     @property
     def muxer(self):
@@ -957,7 +956,7 @@ class Project(Loggable, GES.Project):
             if caps:
                 self.container_profile.set_format(caps)
             self.container_profile.set_preset_name(value)
-            self._emitChange("rendering-settings-changed", "muxer", value)
+            self._emit_change("muxer")
 
     def _get_caps_from_feature(self, name):
         """Gets the caps for the source static pad template of a feature."""
@@ -1783,8 +1782,8 @@ class Project(Loggable, GES.Project):
         if emit:
             self.emit("settings-set-from-imported-asset", asset)
 
-    def _emitChange(self, signal, key, value):
-        self.emit(signal, key, value)
+    def _emit_change(self, key):
+        self.emit("rendering-settings-changed", key)
         # TODO: Remove this when it's possible to undo/redo these changes.
         self.setModificationState(True)
 
diff --git a/pitivi/render.py b/pitivi/render.py
index 4a56f55..d74f00f 100644
--- a/pitivi/render.py
+++ b/pitivi/render.py
@@ -438,8 +438,8 @@ class RenderDialog(Loggable):
         self._displayRenderSettings()
 
         self.window.connect("delete-event", self._deleteEventCb)
-        self.project.connect(
-            "rendering-settings-changed", self._settings_changed_cb)
+        self.project.connect("rendering-settings-changed",
+                             self._rendering_settings_changed_cb)
 
         # Monitor changes
 
@@ -601,7 +601,8 @@ class RenderDialog(Loggable):
         self.window.set_icon_name("system-run-symbolic")
         self.window.set_transient_for(self.app.gui)
 
-    def _settings_changed_cb(self, unused_project, key, value):
+    def _rendering_settings_changed_cb(self, unused_project, unused_item):
+        """Handles Project metadata changes."""
         self.updateResolution()
 
     def __initialize_muxers_model(self):
@@ -996,7 +997,7 @@ class RenderDialog(Loggable):
 
     def _closeButtonClickedCb(self, unused_button):
         self.debug("Render dialog's Close button clicked")
-        self.project.disconnect_by_func(self._settings_changed_cb)
+        self.project.disconnect_by_func(self._rendering_settings_changed_cb)
         self.destroy()
 
     def _deleteEventCb(self, unused_window, unused_event):
@@ -1126,7 +1127,7 @@ class RenderDialog(Loggable):
         self.updateResolution()
 
     def updateResolution(self):
-        width, height = self.project.getVideoWidthAndHeight(True)
+        width, height = self.project.getVideoWidthAndHeight(render=True)
         self.resolution_label.set_text("%d×%d" % (width, height))
 
     def _projectSettingsButtonClickedCb(self, unused_button):
diff --git a/pitivi/timeline/timeline.py b/pitivi/timeline/timeline.py
index f4c98f1..a219658 100644
--- a/pitivi/timeline/timeline.py
+++ b/pitivi/timeline/timeline.py
@@ -1394,7 +1394,7 @@ class TimelineContainer(Gtk.Grid, Zoomable, Loggable):
         self._project = project
         if self._project:
             self._project.connect("rendering-settings-changed",
-                                  self._renderingSettingsChangedCb)
+                                  self._rendering_settings_changed_cb)
             self.ges_timeline = project.ges_timeline
         else:
             self.ges_timeline = None
@@ -1803,29 +1803,22 @@ class TimelineContainer(Gtk.Grid, Zoomable, Loggable):
         self.log("Timeline has lost focus")
         self.updateActions()
 
-    # Callbacks
-    def _renderingSettingsChangedCb(self, project, item, value):
-        """Handles Project metadata changes.
-
-        We filter out the one we are not interested in.
-
-        If `item` is None, it means we called it ourself, and want to force
-        getting the project videorate value
-        """
+    def _rendering_settings_changed_cb(self, project, item):
+        """Handles Project metadata changes."""
         if item == "videorate" or item is None:
-            if value is None:
-                value = project.videorate
-            self._framerate = value
-
-            self.ruler.setProjectFrameRate(self._framerate)
+            self._update_ruler(project.videorate)
 
         if item in ["width", "height", "videorate", "rate", "channels"]:
             project.update_restriction_caps()
 
+    def _update_ruler(self, videorate):
+        self._framerate = videorate
+        self.ruler.setProjectFrameRate(self._framerate)
+
     def _projectLoadedCb(self, unused_project_manager, project):
         """Connects to the project's timeline and pipeline."""
         if self._project:
-            self._project.disconnect_by_func(self._renderingSettingsChangedCb)
+            self._project.disconnect_by_func(self._rendering_settings_changed_cb)
             try:
                 self.timeline._pipeline.disconnect_by_func(
                     self.timeline.positionCb)
@@ -1839,11 +1832,9 @@ class TimelineContainer(Gtk.Grid, Zoomable, Loggable):
         self.setProject(project)
         if project:
             self.ruler.setPipeline(project.pipeline)
-
-            self.ruler.setProjectFrameRate(project.videorate)
             self.ruler.zoomChanged()
+            self._update_ruler(project.videorate)
 
-            self._renderingSettingsChangedCb(project, None, None)
             self.timeline.set_best_zoom_ratio(allow_zoom_in=True)
             self.timeline.update_snapping_distance()
 


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