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

« back to all changes in this revision

Viewing changes to pitivi/ui/complextimeline.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
 
# PiTiVi , Non-linear video editor
2
 
#
3
 
#       pitivi/ui/complextimeline.py
4
 
#
5
 
# Copyright (c) 2006, Edward Hervey <bilboed@bilboed.com>
6
 
#
7
 
# This program is free software; you can redistribute it and/or
8
 
# modify it under the terms of the GNU Lesser General Public
9
 
# License as published by the Free Software Foundation; either
10
 
# version 2.1 of the License, or (at your option) any later version.
11
 
#
12
 
# This program is distributed in the hope that it will be useful,
13
 
# but WITHOUT ANY WARRANTY; without even the implied warranty of
14
 
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
15
 
# Lesser General Public License for more details.
16
 
#
17
 
# You should have received a copy of the GNU Lesser General Public
18
 
# License along with this program; if not, write to the
19
 
# Free Software Foundation, Inc., 59 Temple Place - Suite 330,
20
 
# Boston, MA 02111-1307, USA.
21
 
 
22
 
"""
23
 
Timeline widgets for the complex view
24
 
"""
25
 
 
26
 
import gtk
27
 
import gst
28
 
 
29
 
import pitivi.instance as instance
30
 
 
31
 
from pitivi.bin import SmartTimelineBin
32
 
from complexlayer import LayerInfoList
33
 
from layerwidgets import TopLayer, CompositionLayer
34
 
from complexinterface import ZoomableWidgetInterface
35
 
 
36
 
class CompositionLayers(gtk.VBox, ZoomableWidgetInterface):
37
 
    """ Souped-up VBox that contains the timeline's CompositionLayer """
38
 
 
39
 
    def __init__(self, leftsizegroup, hadj, layerinfolist):
40
 
        gtk.VBox.__init__(self)
41
 
        self.modify_bg(gtk.STATE_NORMAL, gtk.gdk.Color(1,0,0))
42
 
        self.leftSizeGroup = leftsizegroup
43
 
        self.hadj = hadj
44
 
        self.layerInfoList = layerinfolist
45
 
        self.layerInfoList.connect('layer-added', self._layerAddedCb)
46
 
        self.layerInfoList.connect('layer-removed', self._layerRemovedCb)
47
 
        self._createUI()
48
 
 
49
 
    def _createUI(self):
50
 
        self.set_spacing(5)
51
 
        self.set_border_width(2)
52
 
        self.layers = []
53
 
        for layerinfo in self.layerInfoList:
54
 
            complayer = CompositionLayer(self.leftSizeGroup, self.hadj,
55
 
                                         layerinfo)
56
 
            self.layers.append(complayer)
57
 
            self.pack_start(complayer, expand=False)
58
 
 
59
 
 
60
 
    ## ZoomableWidgetInterface overrides
61
 
 
62
 
    def getDuration(self):
63
 
        return max([layer.getDuration() for layer in self.layers])
64
 
 
65
 
    def getStartTime(self):
66
 
        # the start time is always 0 (for display reason)
67
 
        return 0
68
 
 
69
 
    def zoomChanged(self):
70
 
        for layer in self.layers:
71
 
            layer.zoomChanged()
72
 
 
73
 
    ## LayerInfoList callbacks
74
 
 
75
 
    def _layerAddedCb(self, layerInfoList, position):
76
 
        complayer = CompositionLayer(self.leftSizeGroup, self.hadj,
77
 
                                     layerInfoList[position])
78
 
        self.layers.insert(position, complayer)
79
 
        self.pack_start(complayer, expand=False)
80
 
        self.reorder_child(complayer, position)
81
 
 
82
 
    def _layerRemovedCb(self, unused_layerInfoList, position):
83
 
        # find the proper child
84
 
        child = self.layers[position]
85
 
        # remove it
86
 
        self.remove(child)
87
 
 
88
 
#
89
 
# Complex Timeline Design v2 (08 Feb 2006)
90
 
#
91
 
#
92
 
# Tree of contents (ClassName(ParentClass))
93
 
# -----------------------------------------
94
 
#
95
 
# ComplexTimelineWidget(gtk.VBox)
96
 
# |  Top container
97
 
# |
98
 
# +--TopLayer (TimelineLayer (gtk.HBox))
99
 
# |   |
100
 
# |   +--TopLeftTimelineWidget(?)
101
 
# |   |
102
 
# |   +--ScaleRuler(gtk.Layout)
103
 
# |
104
 
# +--gtk.ScrolledWindow
105
 
#    |
106
 
#    +--CompositionsLayer(gtk.VBox)
107
 
#       |
108
 
#       +--CompositionLayer(TimelineLayer(gtk.HBox))
109
 
#          |
110
 
#          +--InfoLayer(gtk.Expander)
111
 
#          |
112
 
#          +--TrackLayer(gtk.Layout)
113
 
 
114
 
class ComplexTimelineWidget(gtk.VBox, ZoomableWidgetInterface):
115
 
 
116
 
    def __init__(self, topwidget):
117
 
        gst.log("Creating ComplexTimelineWidget")
118
 
        gtk.VBox.__init__(self)
119
 
 
120
 
        self.zoomratio = 10.0
121
 
 
122
 
        self.hadj = topwidget.hadjustment
123
 
        self.vadj = topwidget.vadjustment
124
 
 
125
 
        # common LayerInfoList
126
 
        self.layerInfoList = LayerInfoList(instance.PiTiVi.current.timeline)
127
 
        instance.PiTiVi.playground.connect('position', self._playgroundPositionCb)
128
 
        for layer in self.layerInfoList:
129
 
            layer.composition.connect('start-duration-changed',
130
 
                                      self._layerStartDurationChangedCb)
131
 
 
132
 
        self._createUI()
133
 
 
134
 
    def _createUI(self):
135
 
        self.set_border_width(4)
136
 
        self.leftSizeGroup = gtk.SizeGroup(gtk.SIZE_GROUP_HORIZONTAL)
137
 
 
138
 
        # top layer (TopLayer)
139
 
        self.topLayer = TopLayer(self.leftSizeGroup, self.hadj)
140
 
        # overriding topLayer's ZoomableWidgetInterface methods
141
 
        self.topLayer.getDuration = self.getDuration
142
 
        self.topLayer.getStartTime = self.getStartTime
143
 
        self.topLayer.overrideZoomableWidgetInterfaceMethods()
144
 
        self.pack_start(self.topLayer, expand=False)
145
 
 
146
 
        # List of CompositionLayers
147
 
        self.compositionLayers = CompositionLayers(self.leftSizeGroup,
148
 
                                                   self.hadj, self.layerInfoList)
149
 
 
150
 
        # ... in a scrolled window
151
 
        self.scrolledWindow = gtk.ScrolledWindow()
152
 
        self.scrolledWindow.set_policy(gtk.POLICY_NEVER, gtk.POLICY_AUTOMATIC)
153
 
        self.scrolledWindow.add_with_viewport(self.compositionLayers)
154
 
        self.pack_start(self.scrolledWindow, expand=True)
155
 
 
156
 
    def _layerStartDurationChangedCb(self, unused_composition, unused_start,
157
 
                                     unused_duration):
158
 
        # Force resize of ruler
159
 
        self.topLayer.startDurationChanged()
160
 
 
161
 
    ## ZoomableWidgetInterface overrides
162
 
    ## * we send everything to self.compositionLayers
163
 
    ## * topLayer's function calls will also go there
164
 
 
165
 
    def getDuration(self):
166
 
        return self.compositionLayers.getDuration()
167
 
 
168
 
    def getStartTime(self):
169
 
        return self.compositionLayers.getStartTime()
170
 
 
171
 
    def zoomChanged(self):
172
 
        self.topLayer.rightWidget.zoomChanged()
173
 
        self.compositionLayers.zoomChanged()
174
 
 
175
 
 
176
 
    ## ToolBar callbacks
177
 
 
178
 
    def toolBarZoomChangedCb(self, unused_toolbar, zoomratio):
179
 
        self.setZoomRatio(zoomratio)
180
 
 
181
 
    ## PlayGround timeline position callback
182
 
 
183
 
    def _playgroundPositionCb(self, unused_playground, smartbin, value):
184
 
        if isinstance(smartbin, SmartTimelineBin):
185
 
            # for the time being we only inform the ruler
186
 
            self.topLayer.timelinePositionChanged(value, 0)