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

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

  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 elisa.core.utils import signal 
 18   
 19  import pgm 
 20  from pgm.graph.group import Group 
 21  from pgm.graph.image import Image 
 22  from pgm.graph.text import Text 
 23   
24 -class ContectButton(Group):
25
26 - def __init__(self):
27 Group.__init__(self) 28 29 self._image = Image() 30 self._image.bg_color = (0, 0, 0, 0) 31 self._image.layout = pgm.IMAGE_SCALED 32 self._image.visible = True 33 self.add(self._image)
34
35 - def set_from_file(self, img_path, size=None):
36 if img_path: 37 self._image.set_from_file(img_path, size)
38
39 - def image__get(self):
40 return self._image
41
42 -class ButtonPanel(Group):
43 44 index_changed = signal.Signal('index_changed', int) 45 46 #in percent 47 icon_margin = 0.15 48 right_margin = 0.50 49 unselected_opacity = 80 50 51 _current_index = -1 52
53 - def __init__(self):
54 Group.__init__(self) 55 self.active = True
56
57 - def _get_index_from_drawable(self, drawable):
58 i = 0 59 for button in self.children: 60 if drawable == button.image: 61 return i 62 i +=1 63 64 return -1
65
66 - def add_button(self, image_path, size=None):
67 b = ContectButton() 68 if image_path is not None: 69 b.set_from_file(image_path, size) 70 b.image.connect('clicked', self._button_clicked_callback) 71 Group.add(self, b) 72 b.visible = True
73
74 - def _button_clicked_callback(self, drawable, x, y, z, button, time):
75 if not self.active: 76 return False 77 index = self._get_index_from_drawable(drawable) 78 self.index_changed.emit(index) 79 return True
80
81 - def compute_layout(self):
82 if not self.parent: 83 return 84 p = 1 85 margin = self.icon_margin * self.parent.height 86 right_margin = self.right_margin * self.parent.height 87 index = 0 88 for i in reversed(self.children): 89 i.size = (self.parent.height - margin*2, self.parent.height - margin * 2) 90 x = self.parent.width - i.width * p - margin * (p-1) - right_margin 91 i.x = x 92 i.y += margin 93 p += 1 94 if self._current_index > -1 and index == self._current_index: 95 i.opacity = 255 96 else: 97 i.opacity = self.unselected_opacity 98 index += 1
99 100
101 - def current_index__set(self, value):
102 if len(self.children) == 0: 103 return 104 105 if self._current_index > -1: 106 previous_widget = self.children[self._current_index] 107 previous_widget.opacity = self.unselected_opacity 108 109 if value > -1: 110 current_widget = self.children[value] 111 current_widget.opacity = 255 112 113 self._current_index = value
114
115 - def current_index__get(self):
116 return self._current_index
117 118 119
120 -class ContextBar(Group):
121
122 - def __init__(self):
123 Group.__init__(self) 124 125 self._button_panel = ButtonPanel() 126 self._button_panel.visible = True 127 self.add(self._button_panel) 128 #FIXME : find a better way to have this widget on top 129 self._button_panel.z = 0.05 130 131 self.background = Image() 132 self.background.bg_color = (0, 0, 0, 0) 133 self.background.layout = pgm.IMAGE_FILLED 134 self.background.interp = pgm.IMAGE_NEAREST 135 self.background.visible = True 136 self.add(self.background) 137 138 self.icon = Image() 139 self.icon.bg_color = (0, 0, 0, 0) 140 self.icon.layout = pgm.IMAGE_SCALED 141 self.icon.size = (self.width*0.08, self.height*0.8) 142 self.icon.position = (0.0, (self.height-self.icon.height)/2.0, 0.0) 143 self.icon.visible = True 144 self.add(self.icon) 145 146 self._label = Text() 147 self._label.bg_color = (0, 0, 0, 0) 148 self._label.font_family = "Bitstream DejaVu" 149 self._label.weight = pgm.TEXT_WEIGHT_BOLD 150 self._label.font_height = 0.10 151 self._label.position = (self.icon.width, self.height*0.17, 0.0) 152 self._label.size = (self.width-self._label.x, self.height-self._label.y) 153 self._label.visible = True 154 self.add(self._label)
155
156 - def compute_layout(self):
157 self._button_panel.compute_layout()
158
159 - def label__set(self, label):
160 self._label.label = label
161
162 - def label__get(self):
163 return self._label
164
165 - def button_panel__get(self):
166 return self._button_panel
167 168 if __name__ == "__main__":
169 - def on_key_press(viewport, event, widget):
170 if event.type == pgm.KEY_PRESS: 171 # quit on q or ESC 172 if event.keyval in (pgm.keysyms.q, pgm.keysyms.Escape): 173 pgm.main_quit()
174
175 - def on_delete(viewport, event):
176 pgm.main_quit()
177 178 # OpenGL viewport creation 179 factory = pgm.ViewportFactory('opengl') 180 gl = factory.create() 181 gl.title = 'Context bar widget' 182 183 # Canvas and image drawable creation 184 canvas = pgm.Canvas() 185 186 # Bind the canvas to the OpenGL viewport 187 gl.set_canvas(canvas) 188 gl.show() 189 190 context = ContextBar() 191 context.background.set_from_file("theme/context_bar_bg.png") 192 context.label = "Music" 193 context.icon.set_from_file("../poblenou_frontend/tango_theme/music.png") 194 195 context.canvas = canvas 196 context.position = (0.0, 0.0, 0.0) 197 context.width = canvas.width 198 context.height = 0.2 199 context.visible = True 200 201 # Let's start a mainloop 202 gl.connect('key-press-event', on_key_press, context) 203 gl.connect('delete-event', on_delete) 204 pgm.main() 205