Package brailleDisplayDrivers :: Module lilli
[hide private]
[frames] | no frames]

Source Code for Module brailleDisplayDrivers.lilli

  1  #brailleDisplayDrivers/lilli.py 
  2  #A part of NonVisual Desktop Access (NVDA) 
  3  #This file is covered by the GNU General Public License. 
  4  #See the file COPYING for more details. 
  5  #Copyright (C) 2008-2011 Gianluca Casalino <gianluca@spazioausili.net>, Alberto Benassati <benassati@cavazza.it> 
  6   
  7  from logHandler import log 
  8  from ctypes import * 
  9  import inputCore 
 10  import wx 
 11  import braille 
 12   
 13  try: 
 14          lilliDll=windll.LoadLibrary("brailleDisplayDrivers\\lilli.dll") 
 15  except: 
 16          lilliDll=None 
 17   
 18  lilliCellsMap=[] 
 19  KEY_CHECK_INTERVAL = 50 
 20   
 21  LILLI_KEYS = [ 
 22          "", "F1", "F2", "F3", "F4",  "F5", "F6", "F7", "F8", "F9", "F10", "LF", "UP", "RG", "DN", "",  
 23          "", "SF1", "SF2", "SF3", "SF4",  "SF5", "SF6", "SF7", "SF8", "SF9", "SF10", "SLF", "SUP", "SRG", "SDN", "",  
 24          "", "LF1", "LF2", "LF3", "LF4",  "LF5", "LF6", "LF7", "LF8", "LF9", "LF10", "LLF", "LUP", "LRG", "LDN", "",  
 25          "", "SLF1", "SLF2", "SLF3", "SLF4",  "SLF5", "SLF6", "SLF7", "SLF8", "SLF9", "SLF10", "SLLF", "SLUP", "SLRG", "SLDN", "SFDN", "SFUP", 
 26          "route" 
 27  ] 
28 29 30 -def convertLilliCells(cell):
31 newCell = ((1<<6 if cell & 1<<4 else 0) | 32 (1<<5 if cell & 1<<5 else 0) | 33 (1<<0 if cell & 1<<6 else 0) | 34 (1<<3 if cell & 1<<0 else 0) | 35 (1<<2 if cell & 1<<1 else 0) | 36 (1<<1 if cell & 1<<2 else 0) | 37 (1<<7 if cell & 1<<3 else 0) | 38 (1<<4 if cell & 1<<7 else 0)) 39 return newCell
40
41 -class BrailleDisplayDriver(braille.BrailleDisplayDriver):
42 name = "lilli" 43 description = _("MDV Lilli") 44 45 @classmethod
46 - def check(cls):
47 return bool(lilliDll)
48
49 - def __init__(self):
50 global lilliCellsMap 51 super(BrailleDisplayDriver, self).__init__() 52 lilliCellsMap=[convertLilliCells(x) for x in range(256)] 53 if (lilliDll.Init408USB()): 54 self._keyCheckTimer = wx.PyTimer(self._handleKeyPresses) 55 self._keyCheckTimer.Start(KEY_CHECK_INTERVAL) 56 else: 57 raise RuntimeError("No display found")
58
59 - def terminate(self):
60 super(BrailleDisplayDriver, self).terminate() 61 try: 62 self._keyCheckTimer.Stop() 63 self._keyCheckTimer = None 64 except: 65 pass 66 lilliDll.Close408USB()
67
68 - def _get_numCells(self):
69 return 40
70
71 - def _handleKeyPresses(self):
72 while True: 73 try: 74 key=lilliDll.ReadBuf() 75 except: 76 pass 77 if not key: break 78 if (key <= 64) or ((key >= 257) and (key <= 296)): 79 self._onKeyPress(key)
80
81 - def _onKeyPress(self, key):
82 try: 83 if (key >= 257) and (key <= 296): 84 inputCore.manager.executeGesture(InputGesture(LILLI_KEYS[65],key-256)) 85 elif (key <= 64): 86 inputCore.manager.executeGesture(InputGesture(LILLI_KEYS[key],0)) 87 except inputCore.NoInputGestureAction: 88 pass
89
90 - def display(self, cells):
91 cells="".join(chr(lilliCellsMap[x]) for x in cells) 92 lilliDll.WriteBuf(cells)
93 94 gestureMap = inputCore.GlobalGestureMap({ 95 "globalCommands.GlobalCommands": { 96 "braille_routeTo": ("br(lilli):route",), 97 "braille_scrollBack": ("br(lilli):LF",), 98 "braille_previousLine": ("br(lilli):UP",), 99 "braille_nextLine": ("br(lilli):DN",), 100 "braille_scrollForward": ("br(lilli):RG",), 101 "kb:shift+tab": ("br(lilli):SLF",), 102 "kb:tab": ("br(lilli):SRG",), 103 "kb:alt+tab": ("br(lilli):SDN",), 104 "kb:alt+shift+tab": ("br(lilli):SUP",), 105 } 106 })
107
108 -class InputGesture(braille.BrailleDisplayGesture):
109 110 source = BrailleDisplayDriver.name 111
112 - def __init__(self, command, argument):
113 super(InputGesture, self).__init__() 114 self.id = command 115 if (command == LILLI_KEYS[65]): 116 self.routingIndex = argument
117