1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17 from pgm.graph.group import Group
18 from pgm.graph.text import Text
19 from pgm.graph.image import Image
20 from pgm.timing import implicit
21 import gst
22 import os
23 import pgm
24 from twisted.internet import reactor
25
27
28 - def __init__(self, canvas, layer,
29 width, height,
30 background_image):
31
32 Group.__init__(self, canvas, layer)
33
34
35 self._background = Image()
36 self._background.set_from_file(background_image)
37 self._background.layout = pgm.IMAGE_FILLED
38 self._background.alignment = pgm.IMAGE_LEFT
39 self._background.opacity = 255
40 self._background.bg_color = (0, 0, 0, 0)
41 self.add(self._background)
42 self._background.position = (0.0, 0.0, 0.0)
43 self._background.size = (width, height)
44
45 self._background.visible = True
46
47 self._show = None
48
49 self._animated_group = implicit.AnimatedObject(self)
50 self._animated_group.mode = implicit.REPLACE
51 self._animated_group.setup_next_animations(duration = 500,
52 transformation = implicit.DECELERATE)
53
54 - def show(self, time_to_show=-1):
55 """
56 Show the player dock for the next seconds
57 @time_to_show: duration before the dock disappears (in seconds)
58 if set to -1 the dock will not disappear
59 """
60 if self._animated_group.opacity != 255:
61 self._animated_group.opacity = 255
62
63 if time_to_show > 0:
64 if self._show != None and self._show.active():
65 self._show.reset(time_to_show)
66 else:
67 self._show = reactor.callLater(time_to_show, self.hide)
68
70 if self._show != None and self._show.active():
71 self._show.cancel()
72
74 """
75 Hide the dock
76 """
77 self._cancel_timer()
78 if self._animated_group.opacity != 0:
79 self._animated_group.opacity = 0
80
82
83
84 return self._animated_group.opacity == 255
85
86
89
92
93
94
95
96
97
98
99 LEFT, RIGHT, TOP, BOTTOM = 0, 1, 2, 3
100 EXTENDED, FIXED, OPTIMISED = 0, 1, 2
101
103
105
106 Group.__init__(self, canvas, layer)
107 self._thickness = 0.25
108 self._stick = TOP
109 self._layout = EXTENDED
110 self._opened_value = 0.0
111
112 self._animated_group = implicit.AnimatedObject(self)
113 self._animated_group.setup_next_animations(duration = 500)
114
115
116
117 self._background = Image()
118
119 self._background.bg_color = (20, 20, 20, 255)
120 self.add(self._background)
121
122
123
124
125
126
127
128 self.stick = TOP
129 self.thickness = self._thickness
130 self.layout = self._layout
131
132
133 self.visible = False
134 self._background.visible = True
135
136
137
139 previous_position = self._stick
140 self._stick = position
141
142
143 if (previous_position in [TOP, BOTTOM]).__xor__ \
144 (position in [TOP, BOTTOM]):
145 for child in self.children:
146 if child != self._background:
147
148
149 child.x, child.y = child.y, child.x
150
151
152
153 if position == TOP:
154 self._coordinate = "y"
155 self._opened_value = 0.0
156 self._animated_group.x = 0.0
157 elif position == BOTTOM:
158 self._coordinate = "y"
159 self._opened_value = self._canvas.height - self.thickness
160 self._animated_group.x = 0.0
161
162 self._animated_group.y = self._opened_value
163
164
165 self.thickness = self._thickness
166 self.layout = self._layout
167
170
177
178
181
190
192 return self._thickness
193
195 value = self._opened_value
196 self._animated_group.y = value
197
199 value = self._opened_value - self._thickness
200 self._animated_group.y = value
201
202 - def add(self, item, setx=0.0, sety=0.0):
209
210
211 if __name__ == "__main__":
212 from pgm.graph.image import Image
213 from pgm.graph.text import Text
214 import pgm
215 import os, gobject, sys
216
269
270 factory = pgm.ViewportFactory('opengl')
271 gl = factory.create()
272 gl.title = 'Dock widget'
273
274 canvas = pgm.Canvas()
275
276 gl.set_canvas(canvas)
277
278
279 dock = Dock(canvas, pgm.DRAWABLE_MIDDLE)
280
281 label = Text()
282 label.label = "Dock"
283 label.fg_color = (220, 220, 220, 255)
284 label.bg_color = (0, 0, 0, 0)
285 label.visible = True
286
287 logo = Image()
288
289 logo.bg_color = (0, 0, 0, 0)
290 logo.opacity = 255
291 logo.visible = True
292
293 video = Image()
294 video.bg_a = 0
295 video.visible = True
296
297 if len(sys.argv) > 1:
298
299 pipeline = gst.element_factory_make('playbin')
300 sink = gst.element_factory_make('pgmimagesink')
301 pipeline.set_property('uri', sys.argv[1])
302 pipeline.set_property('video-sink', sink)
303 sink.set_property('image', video)
304 pipeline.set_state(gst.STATE_PLAYING)
305
306 dock.add(video, 1.0)
307 dock.add(label, 0.8,0.1)
308 dock.add(logo, 0.0)
309
310
311 animated_logo = implicit.AnimatedObject(logo)
312
313 animated_logo.setup_next_animations(duration=500,
314 repeat_behavior=implicit.REVERSE,
315 repeat_count=implicit.INFINITE)
316 animated_logo.opacity = 100
317
318
319 animated_video = implicit.AnimatedObject(video)
320 animated_video.setup_next_animations(duration=1000,
321 repeat_behavior=implicit.REVERSE,
322 repeat_count=implicit.INFINITE,
323 transformation=implicit.SMOOTH)
324 animated_video.x = 2.0
325
326
327 loop = gobject.MainLoop()
328 gobject.timeout_add(5, gl.update)
329 gobject.timeout_add(15, handle_events, dock, gl, loop)
330 loop.run()
331