~timo-jyrinki/ubuntu/trusty/pitivi/backport_utopic_fixes

« back to all changes in this revision

Viewing changes to pitivi/utils/timeline.py

  • Committer: Package Import Robot
  • Author(s): Sebastian Dröge
  • Date: 2014-03-29 15:22:50 UTC
  • mto: (3.1.23 experimental)
  • mto: This revision was merged to the branch mainline in revision 44.
  • Revision ID: package-import@ubuntu.com-20140329152250-flg9onx416bqf3e3
Tags: upstream-0.93
Import upstream version 0.93

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
# Pitivi video editor
2
2
#
3
 
#       pitivi/timeline/timeline.py
 
3
#       pitivi/utils/timeline.py
4
4
#
5
5
# Copyright (c) 2005, Edward Hervey <bilboed@bilboed.com>
6
6
# Copyright (c) 2009, Alessandro Decina <alessandro.decina@collabora.co.uk>
24
24
from gi.repository import Gdk
25
25
from gi.repository import Gst
26
26
 
27
 
from pitivi.utils.loggable import Loggable
 
27
from pitivi.undo.undo import UndoableAction
28
28
from pitivi.utils.signal import Signallable
29
 
from pitivi.utils.receiver import receiver, handler
30
 
from pitivi.utils.ui import Point
31
 
 
32
 
from pitivi.undo.undo import UndoableAction
33
 
 
34
 
#from pitivi.utils.align import AutoAligner
 
29
 
35
30
 
36
31
# Selection modes
 
32
# Set the selection to the given set.
37
33
SELECT = 0
38
 
"""Set the selection to the given set."""
 
34
# Remove the given set from the selection.
39
35
UNSELECT = 1
40
 
"""Remove the given set from the selection."""
 
36
# Extend the selection with the given set.
41
37
SELECT_ADD = 2
42
 
"""Extend the selection with the given set"""
43
 
SELECT_BETWEEN = 3
44
 
"""Select a range of clips"""
45
38
 
46
39
 
47
40
#------------------------------------------------------------------------------#
83
76
 
84
77
    def __init__(self):
85
78
        self._selected = False
86
 
        self.movable = True
87
79
 
88
80
    def __nonzero__(self):
89
81
        """
117
109
        "selection-changed": []}
118
110
 
119
111
    def __init__(self):
120
 
        self.selected = set([])
121
 
        self.last_single_obj = None
 
112
        self.selected = set()
122
113
 
123
114
    def setToObj(self, obj, mode):
124
115
        """
128
119
        """
129
120
        self.setSelection(set([obj]), mode)
130
121
 
131
 
    def addClip(self, clip):
132
 
        """
133
 
        Add the given clip to the selection.
134
 
 
135
 
        @param clip: The object to add
136
 
        @type clip: L{GES.Clip}
137
 
        @raises TimelineError: If the object is already controlled by this
138
 
        Selection.
139
 
        """
140
 
        if clip in self.clips:
141
 
            raise TimelineError("TrackElement already in this selection")
142
 
 
143
122
    def setSelection(self, objs, mode):
144
123
        """
145
124
        Update the current selection.
149
128
         - L{UNSELECT} : the same minus the provided selection.
150
129
         - L{SELECT_ADD} : extended with the provided selection.
151
130
 
152
 
        @param selection: The list of timeline objects to update the selection with.
153
 
        @param mode: The type of update to apply. Can be C{SELECT},C{UNSELECT} or C{SELECT_ADD}
 
131
        @param objs: Timeline objects to update the selection with.
 
132
        @param mode: The type of update to apply. Can be C{SELECT}, C{UNSELECT} or C{SELECT_ADD}
154
133
 
155
134
        @see: L{setToObj}
156
135
        """
157
 
        # get a list of timeline objects
158
136
        selection = set()
159
137
        for obj in objs:
160
138
            # FIXME GES break, handle the fact that we have unlinked objects in GES
162
140
                selection.add(obj.get_parent())
163
141
            else:
164
142
                selection.add(obj)
165
 
 
166
 
        old_selection = self.selected
167
143
        if mode == SELECT_ADD:
168
144
            selection = self.selected | selection
169
145
        elif mode == UNSELECT:
170
146
            selection = self.selected - selection
171
147
 
 
148
        old_selection = self.selected
172
149
        if selection == old_selection:
173
 
            # The user clicked on the same clip
 
150
            # Nothing changed. This can happen for example when the user clicks
 
151
            # the selected clip, then the clip remains selected.
174
152
            return
175
153
        self.selected = selection
176
154
 
177
 
        if len(self.selected) == 1:
178
 
            self.last_single_obj = iter(selection).next()
179
 
 
180
155
        for obj in old_selection - self.selected:
181
156
            for element in obj.get_children(False):
182
157
                if not isinstance(element, GES.BaseEffect) and not isinstance(element, GES.TextOverlay):
183
158
                    element.selected.selected = False
184
 
 
185
159
        for obj in self.selected - old_selection:
186
160
            for element in obj.get_children(False):
187
161
                if not isinstance(element, GES.BaseEffect) and not isinstance(element, GES.TextOverlay):
208
182
            for element in clip.get_children(False):
209
183
                if isinstance(element, GES.BaseEffect):
210
184
                    effects.append(element)
211
 
 
212
185
        return effects
213
186
 
214
187
    def __len__(self):
232
205
        "clip-trim-finished": [],
233
206
    }
234
207
 
235
 
    def __init__(self, focus, timeline, mode, edge, settings, action_log):
 
208
    def __init__(self, focus, timeline, mode, edge, unused_settings, action_log):
236
209
        """
237
210
        @param focus: the Clip or TrackElement which is to be the
238
211
        main target of interactive editing, such as the object directly under the
267
240
            self.old_position += self.focus.get_duration()
268
241
 
269
242
        self.old_priority = self.focus.get_priority()
 
243
        self.new_position = None
270
244
 
271
245
        self.timeline = timeline
272
246
        self.action_log = action_log
278
252
 
279
253
    def finish(self):
280
254
        """Clean up timeline for normal editing"""
281
 
 
282
 
        action = ClipEdited(self.focus, self.old_priority, self.new_priority, self.mode, self.edge,
283
 
                            self.old_position, self.new_position)
284
 
 
285
 
        self.action_log.push(action)
286
 
        self.action_log.commit()
287
 
        self.timeline.commit()
 
255
        if self.new_position is not None and self.new_priority is not None:
 
256
            # The mouse cursor did move.
 
257
            action = ClipEdited(self.focus, self.old_priority, self.new_priority, self.mode, self.edge,
 
258
                                self.old_position, self.new_position)
 
259
            self.action_log.push(action)
 
260
            self.action_log.commit()
 
261
            self.timeline.commit()
288
262
        self.emit("clip-trim-finished")
289
263
 
290
264
    def setMode(self, mode):
313
287
 
314
288
#-------------------------- Interfaces ----------------------------------------#
315
289
 
316
 
ARROW = Gdk.Cursor.new(Gdk.CursorType.ARROW)
317
 
 
318
290
 
319
291
class Zoomable(object):
320
292
    """
376
348
 
377
349
    @classmethod
378
350
    def setZoomLevel(cls, level):
379
 
        level = min(cls.zoom_steps, max(0, level))
 
351
        level = int(max(0, min(level, cls.zoom_steps)))
380
352
        if level != cls._cur_zoom:
381
353
            cls._cur_zoom = level
382
354
            cls.setZoomRatio(cls.computeZoomRatio(level))