This repository has been archived by the owner on Apr 29, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathtimelineobject.py
147 lines (112 loc) · 4.19 KB
/
timelineobject.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
import goocanvas
import gobject
import gtk
import os.path
import pango
from urllib import unquote
from pitivi.receiver import receiver, handler
from view import View
import controller
from zoominterface import Zoomable
from preview import Preview
LEFT_SIDE = gtk.gdk.Cursor(gtk.gdk.LEFT_SIDE)
RIGHT_SIDE = gtk.gdk.Cursor(gtk.gdk.RIGHT_SIDE)
ARROW = gtk.gdk.Cursor(gtk.gdk.ARROW)
class TimelineController(controller.Controller):
_cursor = ARROW
def drag_start(self):
self._view.timeline.disableEdgeUpdates()
def drag_end(self):
self._view.timeline.enableEdgeUpdates()
def set_pos(self, item, pos):
self._view.element.snapStartDurationTime(max(
self._view.pixelToNs(pos[0]), 0))
class TrimHandle(View, goocanvas.Rect, Zoomable):
"""A component of a TimelineObject which manage's the source's edit
points"""
element = receiver()
def __init__(self, element, timeline, **kwargs):
self.element = element
self.timeline = timeline
goocanvas.Rect.__init__(self,
width=5,
fill_color_rgba=0x00000022,
line_width=0,
**kwargs
)
View.__init__(self)
Zoomable.__init__(self)
class StartHandle(TrimHandle):
"""Subclass of TrimHandle wich sets the object's start time"""
class Controller(TimelineController):
_cursor = LEFT_SIDE
def set_pos(self, obj, pos):
self._view.element.snapInTime(
self._view.pixelToNs(pos[0]))
class EndHandle(TrimHandle):
"""Subclass of TrimHandle which sets the objects's end time"""
class Controller(TimelineController):
_cursor = RIGHT_SIDE
def set_pos(self, obj, pos):
self._view.element.snapOutTime(
self._view.pixelToNs(pos[0]))
class TimelineObject(View, goocanvas.Group, Zoomable):
element = receiver()
__HEIGHT__ = 50
__NORMAL__ = 0x709fb899
__SELECTED__ = 0xa6cee3AA
class Controller(TimelineController):
def click(self, pos):
mode = 0
if self._last_event.get_state() & gtk.gdk.SHIFT_MASK:
mode = 1
elif self._last_event.get_state() & gtk.gdk.CONTROL_MASK:
mode = 2
self._view.timeline.setSelectionToObj(
self._view.element, mode)
def __init__(self, element, composition, timeline):
goocanvas.Group.__init__(self)
View.__init__(self)
Zoomable.__init__(self)
self.element = element
self.comp = composition
self.timeline = timeline
self.bg = goocanvas.Rect(
height=self.__HEIGHT__,
fill_color_rgba=self.__NORMAL__,
line_width=0)
self.content = Preview(self.element)
self.name = goocanvas.Text(
x=10,
text=os.path.basename(unquote(element.factory.name)),
font="Sans 9",
fill_color_rgba=0x000000FF,
alignment=pango.ALIGN_LEFT)
self.start_handle = StartHandle(element, timeline,
height=self.__HEIGHT__)
self.end_handle = EndHandle(element, timeline,
height=self.__HEIGHT__)
for thing in (self.bg, self.content, self.start_handle, self.end_handle, self.name):
self.add_child(thing)
if element:
self.zoomChanged()
self.normal()
def zoomChanged(self):
self._start_duration_cb(self.element, self.element.start,
self.element.duration)
@handler(element, "start-duration-changed")
def _start_duration_cb(self, obj, start, duration):
self.set_simple_transform(self.nsToPixel(start), 0, 1, 0)
width = self.nsToPixel(duration)
w = width - self.end_handle.props.width
self.name.props.clip_path = "M%g,%g h%g v%g h-%g z" % (
0, 0, w, self.__HEIGHT__, w)
self.bg.props.width = width
# place end handle at appropriate distance
self.end_handle.props.x = w
@handler(element, "selected-changed")
def _selected_changed(self, element):
if element.selected:
self.bg.props.fill_color_rgba = self.__SELECTED__
else:
self.bg.props.fill_color_rgba = self.__NORMAL__