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

Source Code for Module elisa.plugins.bad.raval_frontend.shaded_list_view

  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 import common 
 18   
 19  import pgm 
 20  from pgm.widgets import sliced_image, scrollbar, const 
 21   
 22  from raval_widgets.scrolled_list import ScrolledList 
 23  from raval_widgets.selector import Selector 
 24  import constants 
 25   
 26  from pgm.graph.group import Group 
 27  from pgm.graph.image import Image 
 28  from pgm.graph.text import Text 
 29   
30 -class ListItem(Group):
31
32 - def load(self):
33 vspacing = 0.15 34 35 thumbnail_width = 0.3 36 thumbnail_height = 0.4 37 thumbnail_x = 0.05 38 thumbnail_y = 0.055 39 40 self.thumbnail = Image() 41 self.add(self.thumbnail) 42 self.thumbnail.position = (thumbnail_x, thumbnail_y, 0) 43 self.thumbnail.size = (thumbnail_width, thumbnail_height) 44 self.thumbnail.bg_color = (0, 0, 0, 0) 45 self.thumbnail.layout = pgm.IMAGE_SCALED 46 self.thumbnail.visible = True 47 48 text_x = thumbnail_width + vspacing 49 text_y = 0.06 50 text_width = 2.35 51 text_height = 0.5 52 53 self._description = self._create_text() 54 self.add(self._description) 55 self._description.visible = True 56 # FIXME: harcoded absolute value 57 self._description.font_height = 0.13 58 self._description.position = (text_x, text_y, 0) 59 self._description.size = (text_width, text_height)
60
61 - def _create_text(self):
62 txt = Text() 63 txt.font_family = "Nimbus Sans L" 64 txt.weight = pgm.TEXT_WEIGHT_BOLD 65 txt.bg_color = (0, 0, 0, 0) 66 txt.alignment = pgm.TEXT_ALIGN_LEFT 67 txt.ellipsize = pgm.TEXT_ELLIPSIZE_MIDDLE 68 txt.opacity = 255 69 return txt
70
71 - def unload(self):
72 self.remove(self._description) 73 self.remove(self.thumbnail)
74
75 - def description__set(self, text):
76 self._description.label = text
77
78 - def description__get(self):
79 return self._description
80 81 plugin_registry = common.application.plugin_registry 82 BaseListView = plugin_registry.get_component_class('raval:list_view') 83
84 -class ShadedListView(BaseListView, ScrolledList):
85
86 - def __init__(self):
87 super(ShadedListView, self).__init__() 88 super(ScrolledList, self).__init__() 89 self._index_set_before = False
90
91 - def update_details(self):
92 self._update_preview()
93
94 - def selector_visible__set(self, visible):
95 self.debug("Selector should become visible: %s" % visible) 96 self._list_selector.visible = visible
97
98 - def _update_preview(self):
99 self.debug("updating the preview") 100 if not hasattr(self, 'preview'): 101 self._create_child_view('preview', 'raval:preview') 102 103 canvas = self.frontend.context.viewport_handle.get_canvas() 104 self.preview.width = canvas.width * 0.37 105 self.preview.height = canvas.height * 0.7 106 x = canvas.width*0.95 - self.preview.width 107 y = (self.height - self.preview.height) / 2.0 + \ 108 self.preview.height/7.0 109 self.preview.position = (x, y, 0.0) 110 self.preview.visible = True 111 112 if self.selected_item >= 0 and len(self.controller.model): 113 self.preview.update()
114
115 - def frontend_changed(self, previous_frontend, new_frontend):
116 super(ShadedListView, self).frontend_changed(previous_frontend, 117 new_frontend) 118 119 if self.frontend: 120 self._list_selector.loading_image_path = self.frontend.theme.get_media('small_waiting_icon') 121 self._list_selector.action_done_image_path = self.frontend.theme.get_media('action_done_icon') 122 123 #FIXME find a way to remove this 124 if hasattr(self, 'preview'): 125 self.preview.frontend_changed(previous_frontend, new_frontend)
126
127 - def clean(self):
128 BaseListView.clean(self) 129 self.selector.stop_animation() 130 self.canvas = None 131 self.preview.canvas = None
132
133 - def create_widgets(self):
134 super(ShadedListView, self).create_widgets() 135 136 canvas = self.frontend.context.viewport_handle.get_canvas() 137 theme = self.frontend.theme 138 139 gradient_top = theme.get_media("list_mode_gradient_top") 140 gradient_bottom = theme.get_media("list_mode_gradient_bottom") 141 142 self.top_shade = gradient_top 143 self.bottom_shade = gradient_bottom 144 145 list_x = canvas.width / 100. 146 self.visible_range_size = 9 147 148 top_bar_height_px = canvas.height * (constants.status_bar_height + constants.context_bar_height) / 100. 149 margin_px = canvas.height * constants.list_menu_height_margin / 100. 150 back_button_px = canvas.height * constants.back_button_height / 100. 151 top_bar_height_px = canvas.height * (constants.status_bar_height + constants.context_bar_height) / 100. 152 153 self.position = (list_x, top_bar_height_px + margin_px, 0) 154 self.width = canvas.width * 0.45 155 self.height = canvas.height * 0.7 156 self.height = canvas.height - top_bar_height_px - margin_px * 2.0 - back_button_px 157 158 bar_bg = sliced_image.SlicedImage() 159 bar_bg.top_file = theme.get_media("scrollbar_top") 160 bar_bg.bottom_file = theme.get_media("scrollbar_bottom") 161 bar_bg.body_file = theme.get_media("scrollbar_body") 162 163 cursor = sliced_image.SlicedImage() 164 cursor.top_file = theme.get_media("cursor_top") 165 cursor.bottom_file = theme.get_media("cursor_bottom") 166 cursor.body_file = theme.get_media("cursor_body") 167 168 # Vertical scrollbar on the left side of the list 169 bar = scrollbar.Scrollbar(items_number=9, background=bar_bg, 170 cursor=cursor, spacing=0.01, thickness=0.07) 171 self.set_vertical_scrollbar(bar, const.LEFT, spacing=0.05) 172 173 sel_left = theme.get_media("selector_left") 174 sel_right = theme.get_media("selector_right") 175 sel_body = theme.get_media("selector_body") 176 back_sel_left = theme.get_media("back_selector_left") 177 back_sel_right = theme.get_media("back_selector_right") 178 back_sel_body = theme.get_media("back_selector_body") 179 #arrow = theme.get_media("selector_arrow") 180 181 # TODO: make Selector parameters optional 182 sel_pictos = (sel_left, sel_right, sel_body, 183 back_sel_left, back_sel_right, back_sel_body) 184 185 self._list_selector = Selector(orientation=const.HORIZONTAL, *sel_pictos) 186 187 # back button at bottom left corner of the list 188 self._back_img = Image() 189 self._back_img.connect("clicked", self._back_button_clicked) 190 self._back_img.layout = pgm.IMAGE_SCALED 191 self._back_img.set_from_file(theme.get_media('list_mode_back_button')) 192 self._back_img.bg_color = (0, 0, 0, 0) 193 self._back_img.visible = True 194 195 height = canvas.height * constants.back_button_height / 100. 196 width = canvas.width / 8.0 197 y = canvas.height - self.y - height 198 x = -self.x 199 self._back_img.alignment = pgm.IMAGE_BOTTOM_LEFT 200 self._back_img.position = (x, y, 0) 201 self._back_img.size = (width, height) 202 self.add(self._back_img)
203
204 - def _back_button_clicked(self, drawable, x, y, z, button, time):
205 canvas = self.frontend.context.viewport_handle.get_canvas() 206 canvas.remove(self._back_img) 207 self.controller.parent.exit_node() 208 return True
209
210 - def selected_item__set(self, index):
211 if not self._index_set_before: 212 self._index_set_before = True 213 self.selector_visible = False 214 self.set_selector(self._list_selector) 215 super(ShadedListView, self).selected_item__set(index)
216
217 - def create_item(self, model):
218 widget = ListItem() 219 return widget
220
221 - def load_item(self, index):
222 model = self.controller.model[index] 223 widget = self[index] 224 225 widget.load() 226 227 self.load_from_theme(model.theme_icon, widget.thumbnail) 228 229 text = self.frontend.translate_text(model.text) 230 widget.description = text 231 232 uri = model.thumbnail_source 233 if uri != None: 234 self._thumbnail_source_to_image(uri, widget.thumbnail)
235
236 - def unload_item(self, widget):
237 widget.unload()
238
239 - def do_clicked(self, x, y, z, button, time):
240 # The controller could already have been removed, when we get the 241 # events 242 if self.controller is None or not self.controller.focused: 243 return False 244 245 return super(ShadedListView, self).do_clicked(x, y, z, button, time)
246
247 - def do_child_clicked(self, index):
248 old_selected = self.selected_item 249 super(ShadedListView, self).do_child_clicked(index) 250 251 if index == old_selected: 252 # click while selected, activate 253 self.controller.activate_item(self.frontend)
254
255 - def do_drag_begin(self, x, y, z, button, time):
256 if self.controller is None or not self.controller.focused: 257 return False 258 259 return super(ShadedListView, self).do_drag_begin(x, y, z, button, time)
260
261 - def do_drag_motion(self, x, y, z, button, time):
262 if self.controller is None or not self.controller.focused: 263 return False 264 265 return super(ShadedListView, self).do_drag_motion(x, y, z, button, time)
266
267 - def do_drag_end(self, x, y, z, button, time):
268 if self.controller is None or not self.controller.focused: 269 return False 270 271 return super(ShadedListView, self).do_drag_end(x, y, z, button, time)
272
273 - def do_selected_item_changed(self, index):
274 self.controller.current_index = index
275
276 - def element_attribute_set(self, position, key, old_value, new_value):
277 super(ShadedListView, self).element_attribute_set(position, key, 278 old_value, 279 new_value) 280 if key == "text": 281 text = self.frontend.translate_text(new_value) 282 self[position].description = text 283 elif key == "thumbnail_source": 284 if self.is_widget_visible(position): 285 self._thumbnail_source_to_image(new_value, 286 self[position].thumbnail) 287 elif key == "loading": 288 self.selector.loading = new_value
289
290 - def action_called__set(self, new_value):
291 if new_value: 292 self.selector.action_done = new_value
293