2
# PiTiVi , Non-linear video editor
4
# pitivi/ui/complexlayer.py
6
# Copyright (c) 2006, Edward Hervey <bilboed@bilboed.com>
8
# This program is free software; you can redistribute it and/or
9
# modify it under the terms of the GNU Lesser General Public
10
# License as published by the Free Software Foundation; either
11
# version 2.1 of the License, or (at your option) any later version.
13
# This program is distributed in the hope that it will be useful,
14
# but WITHOUT ANY WARRANTY; without even the implied warranty of
15
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16
# Lesser General Public License for more details.
18
# You should have received a copy of the GNU Lesser General Public
19
# License along with this program; if not, write to the
20
# Free Software Foundation, Inc., 59 Temple Place - Suite 330,
21
# Boston, MA 02111-1307, USA.
24
Interface for managing tranformation between timeline timestamps and UI
31
# Complex Timeline interfaces v2 (01 Jul 2008)
34
# -----------------------
35
# Interface for the Complex Timeline widgets for setting, getting,
36
# distributing and modifying the zoom ratio and the size of the widget.
38
# A zoomratio is the number of pixels per second
39
# ex : 10.0 = 10 pixels for a second
40
# ex : 0.1 = 1 pixel for 10 seconds
41
# ex : 1.0 = 1 pixel for a second
50
class Zoomable(object):
54
zoom_levels = [1, 1.5, 2, 2.5, 3, 3.5, 4, 4.5] + range(5, 10, 1) + \
57
zoomratio = zoom_levels[_cur_zoom]
61
# FIXME: ideally we should deprecate this
62
Zoomable.addInstance(self)
65
if self in Zoomable._instances:
66
# FIXME: ideally we should deprecate this and spit a warning here
67
self._instances.remove(self)
70
def addInstance(cls, instance):
71
cls._instances.append(instance)
74
def removeInstance(cls, instance):
75
cls._instances.remove(instance)
78
def setZoomRatio(cls, ratio):
84
cls._cur_zoom = min(len(cls.zoom_levels) - 1, cls._cur_zoom + 1)
85
cls.setZoomRatio(cls._computeZoomRatio(cls._cur_zoom))
89
cls._cur_zoom = max(0, cls._cur_zoom - 1)
90
cls.setZoomRatio(cls._computeZoomRatio(cls._cur_zoom))
93
def _computeZoomRatio(cls, index):
94
return cls.zoom_levels[index]
97
def pixelToNs(cls, pixel):
99
Returns the pixel equivalent in nanoseconds according to the zoomratio
101
return long(pixel * gst.SECOND / cls.zoomratio)
104
def nsToPixel(cls, duration):
106
Returns the pixel equivalent of the given duration, according to the
109
if long(duration) == long(gst.CLOCK_TIME_NONE):
111
return int((float(duration) / gst.SECOND) * cls.zoomratio)
114
def _zoomChanged(cls):
115
for inst in cls._instances:
118
def zoomChanged(self):