[pitivi] timeline: Move the setBestZoom method to the timeline
- From: Thibault Saunier <tsaunier src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [pitivi] timeline: Move the setBestZoom method to the timeline
- Date: Sat, 19 May 2012 18:04:17 +0000 (UTC)
commit 1ebefb9c86178e4eafa133f47bf38edfa4e2f9a0
Author: Thibault Saunier <thibault saunier collabora com>
Date: Fri May 18 13:53:59 2012 -0400
timeline: Move the setBestZoom method to the timeline
Adapt the way we set best zoomm when moving objects
pitivi/mainwindow.py | 27 ----------------------
pitivi/timeline/ruler.py | 6 +---
pitivi/timeline/timeline.py | 51 ++++++++++++++++++++++++++++++++++++------
3 files changed, 45 insertions(+), 39 deletions(-)
---
diff --git a/pitivi/mainwindow.py b/pitivi/mainwindow.py
index 0ffc7cf..afe419c 100644
--- a/pitivi/mainwindow.py
+++ b/pitivi/mainwindow.py
@@ -193,7 +193,6 @@ class PitiviMainWindow(gtk.Window, Loggable):
self._createUi(instance, allow_full_screen)
self.recent_manager = RecentManager()
self._zoom_duration_changed = False
- self.zoomed_fitted = True
self._missingUriOnLoading = False
self.app.projectManager.connect("new-project-loading",
@@ -752,31 +751,6 @@ class PitiviMainWindow(gtk.Window, Loggable):
if self.app.current.timeline.props.duration != 0:
self.render_button.set_sensitive(True)
- def setBestZoomRatio(self):
- """
- Set the zoom level so that the entire timeline is in view.
- """
- 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.app.current.timeline.props.duration
- if duration == 0:
- self.debug("The timeline duration is 0, impossible to calculate zoom")
- return
- timeline_duration = duration + gst.SECOND - 1
- timeline_duration_s = int(timeline_duration / gst.SECOND)
-
- self.debug("duration: %s, timeline duration: %s" % (duration,
- gst.TIME_ARGS(timeline_duration)))
- ideal_zoom_ratio = float(ruler_width) / timeline_duration_s
- nearest_zoom_level = Zoomable.computeZoomLevel(ideal_zoom_ratio)
- Zoomable.setZoomLevel(nearest_zoom_level)
- self.app.current.timeline.props.snapping_distance = \
- Zoomable.pixelToNs(self.app.settings.edgeSnapDeadband)
- # Only do this at the very end, after updating the other widgets.
- self.log("Setting 'zoomed_fitted' to True")
- self.zoomed_fitted = True
-
def _projectManagerNewProjectLoadingCb(self, projectManager, uri):
if uri:
self.recent_manager.add_item(uri)
@@ -1059,7 +1033,6 @@ class PitiviMainWindow(gtk.Window, Loggable):
self._settingsChangedCb(self.app.current, None, self.app.current.settings)
if self.timeline_ui:
self.timeline_ui.setProject(self.app.current)
- self.setBestZoomRatio()
self.clipconfig.project = self.app.current
#FIXME GES port undo/redo
#self.app.timelineLogObserver.pipeline = self.app.current.pipeline
diff --git a/pitivi/timeline/ruler.py b/pitivi/timeline/ruler.py
index 1c20033..85a410d 100644
--- a/pitivi/timeline/ruler.py
+++ b/pitivi/timeline/ruler.py
@@ -149,12 +149,10 @@ class ScaleRuler(gtk.DrawingArea, Zoomable, Loggable):
# Control + scroll = zoom
if event.direction == gtk.gdk.SCROLL_UP:
Zoomable.zoomIn()
- self.log("Setting 'zoomed_fitted' to False")
- self.app.gui.zoomed_fitted = False
+ self.app.gui.timeline_ui.zoomed_fitted = False
elif event.direction == gtk.gdk.SCROLL_DOWN:
Zoomable.zoomOut()
- self.log("Setting 'zoomed_fitted' to False")
- self.app.gui.zoomed_fitted = False
+ self.app.gui.timeline_ui.zoomed_fitted = False
else:
# No modifier key held down, just scroll
if event.direction == gtk.gdk.SCROLL_UP or\
diff --git a/pitivi/timeline/timeline.py b/pitivi/timeline/timeline.py
index 1361c05..9054c9a 100644
--- a/pitivi/timeline/timeline.py
+++ b/pitivi/timeline/timeline.py
@@ -597,6 +597,8 @@ class Timeline(gtk.Table, Loggable, Zoomable):
self.rate = gst.Fraction(1, 1)
self._timeline = None
+ self.zoomed_fitted = True
+
# Timeline edition related fields
self._creating_tckobjs_sigid = {}
self._move_context = None
@@ -1075,12 +1077,12 @@ class Timeline(gtk.Table, Loggable, Zoomable):
if event.direction == gtk.gdk.SCROLL_UP:
Zoomable.zoomIn()
self.log("Setting 'zoomed_fitted' to False")
- self.app.gui.zoomed_fitted = False
+ self.zoomed_fitted = False
return True
elif event.direction == gtk.gdk.SCROLL_DOWN:
Zoomable.zoomOut()
self.log("Setting 'zoomed_fitted' to False")
- self.app.gui.zoomed_fitted = False
+ self.zoomed_fitted = False
return True
return False
else:
@@ -1119,7 +1121,7 @@ class Timeline(gtk.Table, Loggable, Zoomable):
self._updateZoomSlider = False
Zoomable.setZoomLevel(int(adjustment.get_value()))
self.log("Setting 'zoomed_fitted' to False")
- self.app.gui.zoomed_fitted = False
+ self.zoomed_fitted = False
self._updateZoomSlider = True
def _zoomSliderScrollCb(self, unused_widget, event):
@@ -1193,6 +1195,34 @@ class Timeline(gtk.Table, Loggable, Zoomable):
self._timeline.props.snapping_distance = \
Zoomable.pixelToNs(settings.edgeSnapDeadband)
+ def _setBestZoomRatio(self):
+ """
+ Set the zoom level so that the entire timeline is in view.
+ """
+ ruler_width = self.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.get_duration()
+ if duration == 0:
+ self.debug("The timeline duration is 0, impossible to calculate zoom")
+ return
+
+ timeline_duration = duration + gst.SECOND - 1
+ timeline_duration_s = int(timeline_duration / gst.SECOND)
+
+ self.debug("duration: %s, timeline duration: %s" % (duration,
+ gst.TIME_ARGS(timeline_duration)))
+
+ ideal_zoom_ratio = float(ruler_width) / timeline_duration_s
+ nearest_zoom_level = Zoomable.computeZoomLevel(ideal_zoom_ratio)
+ Zoomable.setZoomLevel(nearest_zoom_level)
+ self.timeline.props.snapping_distance = \
+ Zoomable.pixelToNs(self.app.settings.edgeSnapDeadband)
+
+ # Only do this at the very end, after updating the other widgets.
+ self.log("Setting 'zoomed_fitted' to True")
+ self.zoomed_fitted = True
+
## Project callbacks
def _projectChangedCb(self, app, project):
@@ -1223,6 +1253,7 @@ class Timeline(gtk.Table, Loggable, Zoomable):
self._pipeline = self._project.pipeline
self._pipeline.connect("position", self.positionChangedCb)
self._project.connect("settings-changed", self._settingsChangedCb)
+ self._setBestZoomRatio()
def setProjectManager(self, projectmanager):
if self._projectmanager is not None:
@@ -1253,7 +1284,7 @@ class Timeline(gtk.Table, Loggable, Zoomable):
self._layer_sig_ids.append(self._timeline.connect("layer-removed",
self._layerRemovedCb))
self._layer_sig_ids.append(timeline.connect("notify::update",
- self._zoomFitCb))
+ self._timelineUpdateChangedCb))
# Make sure to set the current layer in use
self._layerAddedCb(None, None)
@@ -1280,6 +1311,10 @@ class Timeline(gtk.Table, Loggable, Zoomable):
timeline = property(getTimeline, setTimeline, delTimeline, "The GESTimeline")
+ def _timelineUpdateChangedCb(self, unused, unsued2=None):
+ if self.zoomed_fitted is True:
+ self._setBestZoomRatio()
+
def _layerAddedCb(self, unused_layer, unused_user_data):
self.updateVScrollAdjustments()
@@ -1320,25 +1355,25 @@ class Timeline(gtk.Table, Loggable, Zoomable):
# We're zoomed out completely, re-enable automatic zoom fitting
# when adding new clips.
self.log("Setting 'zoomed_fitted' to True")
- self.app.gui.zoomed_fitted = True
+ self.zoomed_fitted = True
## ToolBar callbacks
def _zoomFitCb(self, unused, unsued2=None):
- self.app.gui.setBestZoomRatio()
+ self._setBestZoomRatio()
def _zoomInCb(self, unused_action):
# This only handles the button callbacks (from the menus),
# not keyboard shortcuts or the zoom slider!
Zoomable.zoomIn()
self.log("Setting 'zoomed_fitted' to False")
- self.app.gui.zoomed_fitted = False
+ self.zoomed_fitted = False
def _zoomOutCb(self, unused_action):
# This only handles the button callbacks (from the menus),
# not keyboard shortcuts or the zoom slider!
Zoomable.zoomOut()
self.log("Setting 'zoomed_fitted' to False")
- self.app.gui.zoomed_fitted = False
+ self.zoomed_fitted = False
def deleteSelected(self, unused_action):
if self.timeline:
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]