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

Source Code for Module elisa.plugins.bad.raval_frontend.context_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.graph.group import Group 
 21  from pgm.graph.image import Image 
 22  from pgm.timing import implicit 
 23  from pgm.widgets import const 
 24   
 25  from raval_widgets.context_bar import ContextBar 
 26  import constants 
 27   
 28  plugin_registry = common.application.plugin_registry 
 29  PigmentView = plugin_registry.get_component_class('pigment:pigment_view') 
 30   
 31  from elisa.core.observers.list import ListObserver 
32 -class ContextView(PigmentView, ListObserver):
33 34 supported_controllers = ('raval:context_controller',) 35 bindings = {'current_index': 'current_index', 36 'icon': 'icon', 'text':'text'} 37
38 - def clean(self):
39 super(ContextView, self).clean() 40 self._context_bar.context = None
41
42 - def current_index__set(self, value):
43 #if ask to unselect all the buttion 44 if value == -1: 45 self._context_bar.button_panel.current_index = value 46 else: 47 #looking for the next (or previous) buttion with an valid action 48 if (value - self._context_bar.button_panel.current_index) > 0: 49 next_action_index = self._get_next_action_index(value) 50 else: 51 next_action_index = self._get_previous_action_index(value) 52 53 54 if next_action_index == -1: 55 next_action_index = self._context_bar.button_panel.current_index 56 57 if self.controller.current_index != next_action_index: 58 self.controller.current_index = next_action_index 59 else: 60 self._context_bar.button_panel.current_index = next_action_index
61 62
63 - def _get_next_action_index(self, current_index):
64 65 if current_index >= len(self.controller.model): 66 current_index = len(self.controller.model) -1 67 #return the next model with an activate action defined 68 for i in range(current_index, len(self.controller.model)): 69 next_model = self.controller.model[i] 70 if next_model.activate_action: 71 return i 72 73 return -1
74
75 - def _get_previous_action_index(self, current_index):
76 #return the next model with an activate action defined 77 78 if current_index < 0: 79 current_index = 0 80 81 for i in reversed( range(0, current_index+1) ): 82 next_model = self.controller.model[i] 83 if next_model.activate_action: 84 return i 85 86 return -1
87 88
89 - def create_widgets(self):
90 canvas = self.frontend.context.viewport_handle.get_canvas() 91 theme = self.frontend.theme 92 self._context_bar = ContextBar() 93 self.load_from_theme("context_bg", self._context_bar.background) 94 self.context_handle.add(self._context_bar) 95 96 # Animation support for both context and status bar 97 self._animated_context_bar = implicit.AnimatedObject(self._context_bar) 98 settings = {'duration': 1000, 99 'transformation': implicit.DECELERATE} 100 self._animated_context_bar.setup_next_animations(**settings) 101 self._animated_context_bar.mode = implicit.REPLACE
102 103
104 - def controller_changed(self, old_controller, new_controller):
105 if new_controller == None: 106 return 107 108 for model in new_controller.model: 109 if model.theme_icon: 110 img_path = self.frontend.theme.get_media(model.theme_icon) 111 else: 112 img_path = None 113 self._context_bar.button_panel.add_button(img_path, 128) 114 115 self._context_bar.button_panel.index_changed.connect( 116 self._widget_index_clicked_cb) 117 118 self.compute_layout()
119
120 - def _widget_index_clicked_cb(self, index):
121 #self.controller.current_index = index 122 self.controller.fire_activate_action(index, self.frontend)
123
124 - def compute_layout(self):
125 canvas = self.frontend.context.viewport_handle.get_canvas() 126 self._context_bar.size = (canvas.width, canvas.height * 127 (constants.context_bar_height/100) ) 128 self._context_bar.y = -self._context_bar.height * 2.0 129 self._context_bar.compute_layout()
130 131
132 - def inserted(self, elements, position):
133 #FIXME : not implemented 134 pass
135
136 - def active__set(self, value):
137 self._context_bar.button_panel.active = value
138
139 - def icon__set(self, icon):
140 if icon: 141 icon_file = self.frontend.theme.get_media(icon) 142 self._context_bar.icon.set_from_file(icon_file, 64) 143 self.show() 144 else: 145 self.hide()
146
147 - def text__set(self, text):
148 if text: 149 frontend = self.frontend 150 self._context_bar.label = frontend.translate_text(text) 151 self.show() 152 else: 153 self._context_bar.label = "" 154 self.hide()
155
156 - def show(self):
157 self.debug("Showing context bar") 158 self._context_bar.visible = True 159 self._animated_context_bar.y = 0.0
160
161 - def hide(self):
162 self.debug("Hiding context bar") 163 self._animated_context_bar.y = -self._context_bar.height*2.0
164