Package elisa :: Package plugins :: Package base :: Package input_providers :: Module raw_input
[hide private]
[frames] | no frames]

Source Code for Module elisa.plugins.base.input_providers.raw_input

  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   
 21  from elisa.base_components.input_provider import PushInputProvider 
 22  from elisa.core.input_event import * 
 23   
 24  from twisted.internet import stdio, protocol 
 25   
 26  import string 
 27   
 28   
29 -class RawInput(PushInputProvider, protocol.Protocol):
30 """ 31 This class implements raw input support 32 """ 33
34 - def _display_help(self):
35 # FIXME: this is a hack: non View classes are not allowed to output 36 # things 37 print "*** Actions ***" 38 print "z : Go Up" 39 print "s : Go Down" 40 print "q : Go Left" 41 print "d : Go Right" 42 print "o : Play" 43 print "p : Pause" 44 print "0..9 : Select Item" 45 print "w : Exit" 46 print "? : Help"
47
48 - def create_input_event(self, data):
49 self.debug("input data=%r", data) 50 51 # considering only the first character 52 data = data[0] 53 54 event = InputEvent(EventSource.KEYBOARD, 55 EventType.KEY_DOWN, 56 EventAction.NONE) 57 event.origin = self.origin 58 59 if data == '\n': 60 event.value = EventValue.KEY_RETURN 61 return event 62 elif data in string.ascii_letters + string.digits: 63 event.value = eval("EventValue.KEY_%s" % data) 64 65 if data == 'z': 66 event.action = EventAction.GO_UP 67 elif data == 'q': 68 event.action = EventAction.GO_LEFT 69 elif data == 's': 70 event.action = EventAction.GO_DOWN 71 elif data == 'd': 72 event.action = EventAction.GO_RIGHT 73 elif data == 'o': 74 event.action = EventAction.PLAY 75 elif data == 'p': 76 event.action = EventAction.PAUSE 77 elif data == 'w': 78 event.action = EventAction.EXIT 79 elif data == '?': 80 self._display_help() 81 82 return event
83 84
85 - def dataReceived(self, data):
86 e = self.create_input_event(data) 87 if (e and self.input_manager): 88 self.input_manager.process_event(e, self.path)
89
90 - def bind(self):
91 stdio.StandardIO(self)
92
93 - def unbind(self):
94 pass
95 96 if __name__ == "__main__": 97 98 try: 99 from twisted.internet import glib2reactor 100 glib2reactor.install() 101 except AssertionError: 102 # already installed... 103 pass 104 105 from twisted.internet import reactor 106
107 - class FakeManager:
108 109 up_ok = False 110 down_ok = False 111
112 - def process_event(self, event, input_provider_path):
113 print event
114 115 r = RawInput() 116 m = FakeManager() 117 r.input_manager = m 118 r.bind() 119 reactor.run() 120 r.unbind() 121