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

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

  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   
 18  __maintainer__ = 'Florian Boucault <florian@fluendo.com>' 
 19   
 20  from elisa.base_components.controller import Controller 
 21  from elisa.core.observers.list import ListObserver 
 22  from elisa.core.input_event import * 
 23   
 24  from twisted.internet import reactor 
 25   
26 -class ListController(Controller, ListObserver):
27 """ 28 DOCME 29 30 @ivar current_index: index of the currently selected item in the list 31 @type current_index: int 32 """ 33 34 supported_models = ('base:list_model',) 35 36 action_called = False 37
38 - def __init__(self):
39 super(ListController, self).__init__() 40 self.current_index = 0 41 self._moves = 0 42 self._set_current_index_call = None
43
44 - def __repr__(self):
45 return "<%s current_index=%r %s items>" % (self.__class__.__name__, 46 self.current_index, 47 len(self.model))
48
49 - def activate_item(self, origin):
50 model = self.model[int(self.current_index)] 51 if callable(model.activate_action): 52 # Hack to look, if we are going to do something with media 53 if hasattr(model.activate_action, 'player_model') or \ 54 hasattr(model.activate_action, 'uri'): 55 56 self.action_called = True 57 model.activate_action(self, origin) 58 self.action_called = False 59 else: 60 self.parent.enter_node(model)
61 62 # compress the number of next_item and previous_items so that we don't 63 # destroy the cpu
64 - def next_item(self, step=1):
65 result = self.current_index + self._moves + step 66 if result >= len(self.model): 67 return 68 69 self._moves += step 70 71 if self._set_current_index_call is None: 72 self._set_current_index_call = \ 73 reactor.callLater(0.05, self.set_current_index)
74
75 - def previous_item(self, step=1):
76 result = self.current_index + self._moves - step 77 if result < 0: 78 return 79 80 self._moves -= step 81 if self._set_current_index_call is None: 82 self._set_current_index_call = \ 83 reactor.callLater(0.05, self.set_current_index)
84
85 - def set_current_index(self):
86 self._set_current_index_call = None 87 moves = self._moves 88 self._moves = 0 89 self.current_index = self.current_index + moves
90
91 - def handle_input(self, input_event):
92 if input_event.action == EventAction.GO_UP: 93 self.previous_item() 94 return True 95 96 elif input_event.action == EventAction.GO_DOWN: 97 self.next_item() 98 return True 99 100 elif input_event.action == EventAction.GO_LEFT: 101 # We don't want, that the parent is doing something 102 return True 103 104 elif input_event.action == EventAction.OK: 105 self.activate_item(input_event.origin) 106 return True 107 108 return False
109 110 # FIXME: should be abstracted away
111 - def inserted(self, elements, position):
112 for weak_view in self._observers: 113 view = weak_view() 114 if view == None: 115 continue 116 else: 117 view.inserted(elements, position)
118
119 - def removed(self, elements, position):
120 for weak_view in self._observers: 121 view = weak_view() 122 if view == None: 123 continue 124 else: 125 view.removed(elements, position)
126
127 - def modified(self, position, value):
128 for weak_view in self._observers: 129 view = weak_view() 130 if view == None: 131 continue 132 else: 133 view.modified(position, value)
134
135 - def dirtied(self):
136 for weak_view in self._observers: 137 view = weak_view() 138 if view == None: 139 continue 140 else: 141 view.dirtied()
142
143 - def element_attribute_set(self, position, key, old_value, new_value):
144 for weak_view in self._observers: 145 view = weak_view() 146 if view == None: 147 continue 148 else: 149 view.element_attribute_set(position, key, old_value, new_value)
150