Package elisa :: Package plugins :: Package bad :: Package raval_frontend :: Package raval_widgets :: Module selector
[hide private]
[frames] | no frames]

Source Code for Module elisa.plugins.bad.raval_frontend.raval_widgets.selector

  1  # -*- coding: utf-8 -*- 
  2  # Elisa - Home multimedia server 
  3  # Copyright (C) 2006-2008 Fluendo Embedded S.L. (www.fluendo.com). 
  4  # All rights reserved. 
  5  # 
  6  # This file is available under one of two license agreements. 
  7  # 
  8  # This file is licensed under the GPL version 3. 
  9  # See "LICENSE.GPL" in the root of this distribution including a special 
 10  # exception to use Elisa with Fluendo's plugins. 
 11  # 
 12  # The GPL part of Elisa is also available under a commercial licensing 
 13  # agreement from Fluendo. 
 14  # See "LICENSE.Elisa" in the root directory of this distribution package 
 15  # for details on that license. 
 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 # animation support 64 self.animated = implicit.AnimatedObject(self._outside, ('opacity','position')) 65 # make the cursor glow/unglow via its opacity property 66 67 self.top_file = top 68 self.body_file = middle 69 self.bottom_file = bottom 70 71 self.start_animation()
72
73 - def start_animation(self):
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
81 - def stop_animation(self):
82 self.animated.stop_animations()
83
84 - def action_done_image_path__set(self, path):
85 self._action_image.set_from_file(path, 64)
86
87 - def size__set(self, size):
88 self._outside.size = size 89 super(Selector, self).size__set(size)
90
91 - def width__set(self, width):
92 self._outside.width = width 93 super(Selector, self).width__set(width)
94
95 - def height__set(self, width):
96 self._outside.height = height 97 super(Selector, self).height__set(heigth)
98
99 - def action_done__set(self, new_value):
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
107 - def loading_image_path__set(self, path):
108 self._loading_image.set_from_file(path, 64)
109
110 - def _create_action_icon(self):
111 #Loading icon is created on demand 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
117 - def _create_loading_icon(self):
118 #Loading icon is created on demand 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
129 - def loading__set(self, loading):
130 self._loading = loading 131 reactor.callLater(self.time_before_loading, 132 self._start_loading_animation)
133
134 - def loading__get(self):
135 return self._loading
136
137 - def _start_loading_animation(self):
138 if self._loading == True and self._loading_image: 139 self._loading_image.visible = self.loading 140 reactor.callLater(0.017, self._transform_mapping_matrix_cb)
141
143 if self._loading_image: 144 self._loading_image.mapping_matrix *= self._rotation_matrix 145 self._loading_image.visible = self.loading 146 if self._loading == True: 147 reactor.callLater(0.017, self._transform_mapping_matrix_cb)
148
149 - def _compute_layout(self):
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
171 - def on_key_pressed(port, event, selector, loop):
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