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

Source Code for Module elisa.plugins.bad.raval_frontend.grid_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  import math 
 18   
 19  from elisa.core import common 
 20   
 21  import pgm 
 22  from pgm.widgets import const 
 23  from pgm.graph.image import Image 
 24   
 25  from raval_widgets import grid_bar 
 26  from raval_widgets.grid_with_selector import GridWithSelector 
 27  from raval_widgets.long_loading_image import LongLoadingImage 
 28  import constants 
 29   
 30  plugin_registry = common.application.plugin_registry 
 31  BaseListView = plugin_registry.get_component_class('raval:list_view') 
 32   
33 -class GridView(BaseListView, GridWithSelector):
34 supported_controllers = ('raval:grid_controller',) 35 36 bindings = {"current_index": "selected_item", 37 "focused": "selector_visible", 38 "ratio" : "ratio", 39 "lines": "edge_length", 40 "grid_bar_index": "grid_bar_index"} 41
42 - def clean(self):
43 BaseListView.clean(self) 44 self.canvas = None 45 if self._grid_bar is not None: 46 self._grid_bar.canvas = None
47
48 - def edge_length__set(self, length):
49 self._animated.lines = length 50 new_range = int(length * self.ratio) 51 self._animated.visible_range_size = new_range 52 53 # experimental code to keep the selected item at the same place on the 54 # canvas whatever the cost. 55 # FIXME: this code is copied from Grid.selected_item__set; very ugly. 56 half_size = (new_range-1.0)/2.0 57 column = int(self.selected_item/length) 58 total_columns = math.ceil(float(len(self.widgets))/length) 59 60 if column <= half_size or \ 61 len(self.widgets) <= new_range*self.lines: 62 self._animated.visible_range_start = 0.0 63 elif column >= total_columns-half_size: 64 start = total_columns-new_range 65 self._animated.visible_range_start = start 66 else: 67 self._animated.visible_range_start = column-half_size
68
69 - def grid_bar_index__set(self, index):
70 self.selector.visible = index == grid_bar.NONE_FOCUSED 71 self._grid_bar.focused_button = index
72
73 - def update_details(self):
74 if len(self.controller.model) > 0: 75 current_model = self.controller.model[int(self.selected_item)] 76 77 txt = self.frontend.translate_text(current_model.text) 78 sub_text = self.frontend.translate_text(current_model.sub_text) 79 80 self._grid_bar.main_text = txt 81 self._grid_bar.sub_text = sub_text
82
83 - def selector_visible__set(self, visible):
84 self.selector.visible = visible
85
86 - def create_widgets(self):
87 BaseListView.create_widgets(self) 88 89 canvas = self.frontend.context.viewport_handle.get_canvas() 90 theme = self.frontend.theme 91 92 top_bar_height_px = canvas.height * (constants.status_bar_height + constants.context_bar_height) / 100. 93 margin_px = canvas.height * constants.list_menu_height_margin / 100. 94 top_bar_height_px = canvas.height * (constants.status_bar_height + constants.context_bar_height) / 100. 95 96 y = top_bar_height_px + margin_px 97 # positioning and scaling the grid 98 self.orientation = const.HORIZONTAL 99 self.width = canvas.width 100 self._visible_range_size = 7 101 102 bar_height = canvas.height * constants.grid_bottom_bar / 100. 103 104 self.height = canvas.height - y - margin_px - bar_height 105 self.position = (0.0, y, 0.0) 106 107 bar = grid_bar.GridBar() 108 bar.visible = True 109 self.add(bar) 110 bar.position = (0.0, self.height + margin_px, 0.0) 111 bar.size = (canvas.width, bar_height) 112 bar.connect('focus-changed', self._bar_focus_changed) 113 114 bar.background = theme.get_media('grid_bottom_bar_bg') 115 bar.zoom_in_button = theme.get_media('grid_zoom_in_button') 116 bar.zoom_out_button = theme.get_media('grid_zoom_out_button') 117 bar.back_button = theme.get_media('grid_back_button') 118 bar.zoom_in_button_focused = theme.get_media('grid_zoom_in_button_focused') 119 bar.zoom_out_button_focused = theme.get_media('grid_zoom_out_button_focused') 120 bar.back_button_focused = theme.get_media('grid_back_button_focused') 121 122 self._grid_bar = bar 123 124 # selector 125 selector = Image() 126 selector.set_from_file(theme.get_media('grid_selector')) 127 selector.layout = pgm.IMAGE_FILLED 128 #selector.size = (200., 200.) 129 selector.interp = pgm.IMAGE_BILINEAR 130 selector.bg_color = (0, 0, 0, 0) 131 selector.visible = True 132 self.selector = selector 133 selector.position = (0.0, 0.0, 1.0)
134
135 - def _bar_focus_changed(self, bar, value):
136 if self.controller.focused: 137 self.controller.grid_bar_index = value 138 # FIXME: origin of this code was unknown therefore it was removed 139 # in changeset 4648; it turns out that it is needed for the click 140 # to work: extremely ugly. 141 self.controller.activate_item(self.frontend) 142 else: 143 self.controller.grid_bar_index = grid_bar.NONE_FOCUSED
144
145 - def create_item(self, model):
146 widget = LongLoadingImage() 147 widget.time_before_quick = 0 148 widget.image.layout = pgm.IMAGE_ZOOMED 149 150 # white borders 151 widget.image.bg_color = (255, 255, 255, 0) 152 widget.image.border_width = self._widget_width*0.014 153 154 # FIXME: cannot use cloning here: texture animation have trouble with it 155 loading_icon = self.frontend.theme.get_media('waiting_icon') 156 widget.loading_image_path = loading_icon 157 158 return widget
159
160 - def load_item(self, index):
161 model = self.controller.model[index] 162 widget = self[index] 163 164 self.load_from_theme(model.theme_icon, widget.quick_image) 165 166 uri = model.thumbnail_source 167 if uri != None: 168 self._thumbnail_source_to_image(uri, widget.image) 169 else: 170 self._create_image_stack(model, widget.quick_image)
171
172 - def unload_item(self, widget):
173 widget.image.clear()
174
175 - def element_attribute_set(self, position, key, old_value, new_value):
176 super(GridView, self).element_attribute_set(position, key, old_value, 177 new_value) 178 if key == "thumbnail_source": 179 if self.is_widget_visible(position): 180 self._thumbnail_source_to_image(new_value, self[position].image) 181 182 elif key == "loading": 183 self[position].loading = new_value
184
185 - def do_selected_item_changed(self, index):
187
188 - def do_drag_begin(self, x, y, z, button, time):
189 # We can get clicked events after the controller is already moved 190 if self.controller is None or not self.controller.focused: 191 return False 192 193 if self.controller.grid_bar_index != grid_bar.NONE_FOCUSED: 194 self.controller.grid_bar_index = grid_bar.NONE_FOCUSED 195 196 return super(GridView, self).do_drag_begin(x, y, z, button, time)
197
198 - def do_drag_motion(self, x, y, z, button, time):
199 if self.controller is None or not self.controller.focused: 200 return False 201 202 return super(GridView, self).do_drag_motion(x, y, z, button, time)
203
204 - def do_drag_end(self, x, y, z, button, time):
205 if self.controller is None or not self.controller.focused: 206 return False 207 208 return super(GridView, self).do_drag_end(x, y, z, button, time)
209
210 - def do_clicked(self, x, y, z, button, time):
211 if self.controller is None or not self.controller.focused: 212 return False 213 214 self.controller.grid_bar_index = grid_bar.NONE_FOCUSED 215 216 currently_selected_item = self.selected_item 217 218 if not super(GridView, self).do_clicked(x, y, z, button, time): 219 # The parent class returns False when there's no widget in the 220 # clicked position. In this case we don't do anything but we still 221 # want to stop the clicking event to propagate so we return True 222 # here. 223 return True 224 225 if currently_selected_item == self.selected_item: 226 self.controller.activate_item(self.frontend) 227 228 return True
229