Package elisa :: Package plugins :: Package good :: Package testing :: Module automated_input
[hide private]
[frames] | no frames]

Source Code for Module elisa.plugins.good.testing.automated_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 reactor 
25   
26   
27 -class AutomatedInput(PushInputProvider):
28 """ 29 DOCME 30 """ 31
32 - def __init__(self):
33 PushInputProvider.__init__(self) 34 self.orders1 = "RDDD" 35 self.orders2 = "" \ 36 "RRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRR" \ 37 "LLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLL" \ 38 "RRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRR" \ 39 "LLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLL" \ 40 "RRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRR" \ 41 "LLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLL" \ 42 "RRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRR" \ 43 "LLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLL" \ 44 "RRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRR" \ 45 "LLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLL" 46 47 self.delay = None 48 self.tempo = 0.05
49
50 - def bind(self):
51 reactor.callLater(5.0, self._execute_orders, self.orders1) 52 reactor.callLater(15.0, self._execute_orders, self.orders2)
53
54 - def unbind(self):
55 if self.delay != None and self.delay.active(): 56 self.delay.cancel()
57
58 - def _translate_to_action(self, letter):
59 if letter == 'D': 60 return EventAction.GO_DOWN 61 if letter == 'U': 62 return EventAction.GO_UP 63 if letter == 'L': 64 return EventAction.GO_LEFT 65 if letter == 'R': 66 return EventAction.GO_RIGHT
67
68 - def _execute_orders(self, orders):
69 time = 0 70 for order in orders: 71 action = self._translate_to_action(order) 72 reactor.callLater(time, self._execute_action, action) 73 time += self.tempo
74
75 - def _execute_action(self, action):
76 self.debug("executing action %s" % action) 77 event = self._generate_keyboard_event(action) 78 self.input_manager.process_event(event, self.path)
79
80 - def _generate_keyboard_event(self, action):
81 event = InputEvent(EventSource.KEYBOARD, EventType.KEY_DOWN, action) 82 return event
83