[pitivi] timeline: Avoid zooming in when setting the best zoom ratio



commit 3d19f44f6a30633d98591bef547a26a0f838266c
Author: Alexandru Băluț <alexandru balut gmail com>
Date:   Tue Dec 17 17:35:58 2013 +0100

    timeline: Avoid zooming in when setting the best zoom ratio

 pitivi/timeline/timeline.py               |   16 ++++++++++++----
 tests/dogtail_scripts/helper_functions.py |    1 +
 tests/dogtail_scripts/test_base.py        |    1 +
 3 files changed, 14 insertions(+), 4 deletions(-)
---
diff --git a/pitivi/timeline/timeline.py b/pitivi/timeline/timeline.py
index 38f1206..2e61d38 100644
--- a/pitivi/timeline/timeline.py
+++ b/pitivi/timeline/timeline.py
@@ -830,7 +830,7 @@ class Timeline(Gtk.VBox, Zoomable, Loggable):
 
     def zoomFit(self):
         self._hscrollBar.set_value(0)
-        self._setBestZoomRatio()
+        self._setBestZoomRatio(allow_zoom_in=True)
 
     def scrollToPixel(self, x):
         if x > self.hadj.props.upper:
@@ -1081,7 +1081,7 @@ class Timeline(Gtk.VBox, Zoomable, Loggable):
         point.x = 0
         self.controls.scroll_to_point(point)
 
-    def _setBestZoomRatio(self):
+    def _setBestZoomRatio(self, allow_zoom_in=False):
         """
         Set the zoom level so that the entire timeline is in view.
         """
@@ -1094,10 +1094,18 @@ class Timeline(Gtk.VBox, Zoomable, Loggable):
         # last second of the timeline will be in view.
         timeline_duration = duration + Gst.SECOND - 1
         timeline_duration_s = int(timeline_duration / Gst.SECOND)
-        self.debug("Adjusting zoom to a timeline duration of %s secs", timeline_duration_s)
+        self.debug("Adjusting zoom for a timeline duration of %s secs", timeline_duration_s)
 
         ideal_zoom_ratio = float(ruler_width) / timeline_duration_s
         nearest_zoom_level = Zoomable.computeZoomLevel(ideal_zoom_ratio)
+        if nearest_zoom_level >= Zoomable.getCurrentZoomLevel():
+            # This means if we continue we'll zoom in.
+            if not allow_zoom_in:
+                # For example when the user zoomed out and is adding clips
+                # to the timeline, zooming in would be confusing.
+                self.log("Zoom not changed because the entire timeline is already visible")
+                return
+
         Zoomable.setZoomLevel(nearest_zoom_level)
         self.bTimeline.set_snapping_distance(Zoomable.pixelToNs(self._settings.edgeSnapDeadband))
 
@@ -1457,7 +1465,7 @@ class Timeline(Gtk.VBox, Zoomable, Loggable):
         self.zoomed_fitted = False
 
     def _zoomFitCb(self, unused, unsued2=None):
-        self._setBestZoomRatio()
+        self._setBestZoomRatio(allow_zoom_in=True)
 
     def _screenshotCb(self, unused_action):
         """
diff --git a/tests/dogtail_scripts/helper_functions.py b/tests/dogtail_scripts/helper_functions.py
index 5b66cf8..bce3e79 100644
--- a/tests/dogtail_scripts/helper_functions.py
+++ b/tests/dogtail_scripts/helper_functions.py
@@ -114,6 +114,7 @@ class HelpFunc(BaseDogTail):
             self.insert_button.click()
         sleep(n / 2.0)  # Inserting clips takes time!
         icon.deselect()
+        self.zoom_best_fit_button.click()
 
     def import_media(self, filename="tears of steel.webm"):
         dogtail.rawinput.pressKey("Esc")  # Ensure the welcome dialog is closed
diff --git a/tests/dogtail_scripts/test_base.py b/tests/dogtail_scripts/test_base.py
index cfeee5f..4dc1836 100644
--- a/tests/dogtail_scripts/test_base.py
+++ b/tests/dogtail_scripts/test_base.py
@@ -49,6 +49,7 @@ class BaseDogTail(unittest.TestCase):
         self.transitions = secondary_tabs.children[0]
         self.titles = secondary_tabs.children[0]
         self.viewer = mainwindow_upper.child(name="viewer", recursive=False)
+        self.zoom_best_fit_button = mainwindow_lower.children[0].children[0].button("Zoom")
         self.timeline = mainwindow_lower.children[0].children[1].child(name="timeline canvas", 
recursive=False)
         self.timeline_toolbar = mainwindow_lower.child(name="timeline toolbar", recursive=False)
         # Used to speed up helper_functions in particular:


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