1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17 from pgm.timing import implicit, controller
18 from pgm.graph.image import Image
19 from pgm.widgets import sliced_image, const
20 from pgm.utils import image as image_utils
21 import pgm
22
23 from twisted.internet import reactor
24 import math
25
26 -class Selector(sliced_image.SlicedImage):
27
28 time_before_loading = 0.250
29
30 - def __init__(self, top, bottom, middle,
31 border_top, border_bottom, border_middle,
32 orientation=const.VERTICAL):
33
34 sliced_image.SlicedImage.__init__(self, orientation=orientation)
35
36 self._loading = False
37 self._loading_image = None
38 self._action_image = None
39 self._rotation_matrix = None
40
41 self._create_action_icon()
42 self._create_loading_icon()
43
44 self._animated_action = implicit.AnimatedObject(self._action_image)
45 self._animated_action.setup_next_animations( duration=800,
46 repeat_behavior=implicit.REVERSE,
47 end_behavior=controller.BEGIN,
48 repeat_count=2)
49
50 self._outside = sliced_image.SlicedImage(orientation=orientation)
51 self._outside.top_file = border_top
52 self._outside.body_file = border_middle
53 self._outside.bottom_file = border_bottom
54
55 self._outside.size = self.size
56 self.add(self._outside)
57 self._outside.z -= 1
58 self._outside.visible = True
59
60 self.add(self._loading_image)
61 self.add(self._action_image)
62
63
64 self.animated = implicit.AnimatedObject(self._outside, ('opacity','position'))
65
66
67 self.top_file = top
68 self.body_file = middle
69 self.bottom_file = bottom
70
71 self.start_animation()
72
74 self.animated.setup_next_animations(duration=850,
75 transformation=implicit.DECELERATE,
76 repeat_behavior=implicit.REVERSE,
77 repeat_count=implicit.INFINITE)
78 self.animated.mode = implicit.REPLACE
79 self.animated.opacity = 200
80
82 self.animated.stop_animations()
83
86
90
94
98
100 if self._action_image:
101 self._action_image.visible = new_value
102 self._action_image.opacity = 0
103
104 if new_value:
105 self._animated_action.opacity = 255
106
109
111
112 self._action_image = Image()
113 self._action_image.bg_color = (0, 0, 0, 0)
114 self._action_image.layout = pgm.IMAGE_SCALED
115 self._action_image.visible = False
116
118
119 self._loading_image = Image()
120 self._loading_image.bg_color = (0, 0, 0, 0)
121 self._loading_image.layout = pgm.IMAGE_SCALED
122 self._loading_image.visible = False
123
124 self._rotation_matrix = pgm.mat4x4_new_identity()
125 self._rotation_matrix.translate(0.5, 0.5, 0.0)
126 self._rotation_matrix.rotate_z(math.pi / 30.0)
127 self._rotation_matrix.translate(-0.5, -0.5, 0.0)
128
133
136
141
148
150 super(Selector, self)._compute_layout()
151 if self._loading_image:
152 h = self.height * 0.40
153 x = self.width - (2.0 * h)
154 y = (self.height - h) / 2.0
155 self._loading_image.size = (h, h)
156 self._loading_image.position = (x ,y , 0)
157 if self._action_image:
158 h = self.height * 0.75
159 x = self.width * 0.97 - h
160 y = (self.height - h) / 2.0
161 self._action_image.size = (h, h)
162 self._action_image.position = (x ,y , 0)
163
164
165 if __name__ == "__main__":
166 from pgm.graph.image import Image
167 from pgm.graph.text import Text
168 import pgm
169 import os, gobject, sys
170
172 if event.keyval in (pgm.keysyms.Escape, pgm.keysyms.q):
173 loop.quit()
174 if event.keyval == pgm.keysyms.a:
175 max_opacity = 255
176 min_opacity = 200
177 if selector.animated.opacity == min_opacity:
178 selector.animated.opacity = max_opacity
179 elif selector.animated.opacity == max_opacity:
180 selector.animated.opacity = min_opacity
181
182 factory = pgm.ViewportFactory('opengl')
183 gl = factory.create()
184 gl.title = 'bar widget'
185
186 canvas = pgm.Canvas()
187 gl.set_canvas(canvas)
188 gl.show()
189
190 pictos = ("theme/selector-left.png",
191 "theme/selector-right.png",
192 "theme/selector-body.png",
193 "theme/back-selector-left.png",
194 "theme/back-selector-right.png",
195 "theme/back-selector-body.png",
196 "theme/arrow.png",
197 )
198 selector = Selector(orientation=const.HORIZONTAL,
199 *pictos)
200 selector.canvas = canvas
201 selector.position = (0.5, 1, 0)
202 selector.size = (canvas.width * 0.5, canvas.height * 0.1)
203 selector.visible = True
204
205 loop = gobject.MainLoop()
206 gl.connect('key-press-event', on_key_pressed, selector, loop)
207 loop.run()
208