~ubuntu-branches/ubuntu/lucid/pitivi/lucid

« back to all changes in this revision

Viewing changes to pitivi/ui/zoominterface.py

  • Committer: Bazaar Package Importer
  • Author(s): Sebastian Dröge
  • Date: 2009-05-27 14:22:49 UTC
  • mfrom: (1.2.1 upstream) (3.1.13 experimental)
  • Revision ID: james.westby@ubuntu.com-20090527142249-tj0qnkc37320ylml
New upstream release.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
#!/usr/bin/python
 
2
# PiTiVi , Non-linear video editor
 
3
#
 
4
#       pitivi/ui/complexlayer.py
 
5
#
 
6
# Copyright (c) 2006, Edward Hervey <bilboed@bilboed.com>
 
7
#
 
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.
 
12
#
 
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.
 
17
#
 
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.
 
22
 
 
23
"""
 
24
Interface for managing tranformation between timeline timestamps and UI
 
25
pixels.
 
26
"""
 
27
 
 
28
import gst
 
29
 
 
30
#
 
31
# Complex Timeline interfaces v2 (01 Jul 2008)
 
32
#
 
33
# Zoomable
 
34
# -----------------------
 
35
# Interface for the Complex Timeline widgets for setting, getting,
 
36
# distributing and modifying the zoom ratio and the size of the widget.
 
37
#
 
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
 
42
#
 
43
# Class Methods
 
44
# . pixelToNs(pixels)
 
45
# . nsToPixels(time)
 
46
# . setZoomRatio
 
47
# Instance Methods
 
48
# . zoomChanged()
 
49
 
 
50
class Zoomable(object):
 
51
 
 
52
    sigid = None
 
53
    _instances = []
 
54
    zoom_levels = [1, 1.5, 2, 2.5, 3, 3.5, 4, 4.5] + range(5, 10, 1) + \
 
55
        range(10, 150, 10)
 
56
    _cur_zoom = 2
 
57
    zoomratio = zoom_levels[_cur_zoom]
 
58
 
 
59
 
 
60
    def __init__(self):
 
61
        # FIXME: ideally we should deprecate this
 
62
        Zoomable.addInstance(self)
 
63
 
 
64
    def __del__(self):
 
65
        if self in Zoomable._instances:
 
66
            # FIXME: ideally we should deprecate this and spit a warning here
 
67
            self._instances.remove(self)
 
68
 
 
69
    @classmethod
 
70
    def addInstance(cls, instance):
 
71
        cls._instances.append(instance)
 
72
 
 
73
    @classmethod
 
74
    def removeInstance(cls, instance):
 
75
        cls._instances.remove(instance)
 
76
 
 
77
    @classmethod
 
78
    def setZoomRatio(cls, ratio):
 
79
        cls.zoomratio = ratio
 
80
        cls._zoomChanged()
 
81
 
 
82
    @classmethod
 
83
    def zoomIn(cls):
 
84
        cls._cur_zoom = min(len(cls.zoom_levels) - 1, cls._cur_zoom + 1)
 
85
        cls.setZoomRatio(cls._computeZoomRatio(cls._cur_zoom))
 
86
 
 
87
    @classmethod
 
88
    def zoomOut(cls):
 
89
        cls._cur_zoom = max(0, cls._cur_zoom - 1)
 
90
        cls.setZoomRatio(cls._computeZoomRatio(cls._cur_zoom))
 
91
 
 
92
    @classmethod
 
93
    def _computeZoomRatio(cls, index):
 
94
        return cls.zoom_levels[index]
 
95
 
 
96
    @classmethod
 
97
    def pixelToNs(cls, pixel):
 
98
        """
 
99
        Returns the pixel equivalent in nanoseconds according to the zoomratio
 
100
        """
 
101
        return long(pixel * gst.SECOND / cls.zoomratio)
 
102
 
 
103
    @classmethod
 
104
    def nsToPixel(cls, duration):
 
105
        """
 
106
        Returns the pixel equivalent of the given duration, according to the
 
107
        set zoom ratio
 
108
        """
 
109
        if long(duration) == long(gst.CLOCK_TIME_NONE):
 
110
            return 0
 
111
        return int((float(duration) / gst.SECOND) * cls.zoomratio)
 
112
 
 
113
    @classmethod
 
114
    def _zoomChanged(cls):
 
115
        for inst in cls._instances:
 
116
            inst.zoomChanged()
 
117
 
 
118
    def zoomChanged(self):
 
119
        pass