Package AEOutput :: Module Braille
[hide private]
[frames] | no frames]

Source Code for Module AEOutput.Braille

  1  ''' 
  2  Defines the base class for all Braille output devices. 
  3   
  4  @author: Peter Parente 
  5  @organization: IBM Corporation 
  6  @copyright: Copyright (c) 2005, 2007 IBM Corporation 
  7  @license: The BSD License 
  8   
  9  All rights reserved. This program and the accompanying materials are made 
 10  available under the terms of the BSD license which accompanies 
 11  this distribution, and is available at 
 12  U{http://www.opensource.org/licenses/bsd-license.php} 
 13  ''' 
 14  import Base, AEConstants 
 15   
16 -class Braille(Base.AEOutput):
17 ''' 18 Defines the base class for all Braille output devices. Provides default 19 implementation of L{parseString} specific to Braille devices. 20 '''
21 - def getCapabilities(self):
22 ''' 23 @return: 'braille' as the only capability of this device. 24 @rtype: list of string 25 ''' 26 return ['braille']
27
28 - def getProxy(self):
29 ''' 30 Looks at the L{USE_THREAD} flag to see if the device implementing this 31 interface wants a thread proxy or not. 32 33 @return: self or L{ThreadProxy.BrailleThreadProxy} 34 @rtype: L{AEOutput} 35 ''' 36 if self.USE_THREAD == True: 37 raise NotImplementedError 38 elif self.USE_THREAD == False: 39 return self 40 else: 41 raise NotImplementedError('USE_THREAD not specified')
42
43 - def parseString(self, text, style, por, sem):
44 ''' 45 Dummy implementation returns the text as-is. 46 47 @param text: Text to be parsed 48 @type text: string 49 @param style: Style object defining how the text should be parsed 50 @type style: L{AEOutput.Style} 51 @param por: Point of regard for the first character in the text, or None if 52 the text is not associated with a POR 53 @type por: L{POR} 54 @param sem: Semantic tag for the text 55 @type sem: integer 56 @return: Parsed words 57 @rtype: 3-tuple of lists of string, L{POR}, L{AEOutput.Style} 58 ''' 59 return [(text, por, style)]
60
61 - def send(self, name, value, style=None):
62 ''' 63 Dispatches known commands to their appropriate handlers. 64 65 @param name: Descriptor of the data value sent 66 @type name: object 67 @param value: Content value 68 @type value: object 69 @param style: Style with which this value should be output 70 @type style: L{AEOutput.Style} 71 @return: Return value specific to the given command 72 @rtype: object 73 @raise NotImplementedError: When the handler for a common command is not 74 implemented by a subclass 75 ''' 76 if name == AEConstants.CMD_STOP: 77 self.sendStop(style) 78 elif name == AEConstants.CMD_TALK: 79 self.sendTalk(style) 80 elif name in (AEConstants.CMD_STRING, AEConstants.CMD_STRING_SYNC): 81 self.sendString(value, style) 82 elif name == AEConstants.CMD_FILENAME: 83 # may not be implemented 84 self.sendFilename(value, style) 85 elif name == AEConstants.CMD_CARET: 86 self.sendCaret(value, style) 87 elif name == AEConstants.CMD_TRUNCATE: 88 self.sendTruncate(value[0], value[1], style) 89 elif name == AEConstants.CMD_GET_ELLIPSIS_SIZE: 90 return self.sendGetEllipsisSizes(style) 91 elif name == AEConstants.CMD_GET_MISSINGCELL_COUNT: 92 return self.sendGetMissingCellCount()
93 94
95 - def sendCaret(self, pos, style):
96 ''' 97 Sends the current caret position relative to the first cell (zero-offset) 98 on the device. The style object is used by the device in deciding how the 99 caret should be presented. 100 101 @param pos: Zero-offset cell position of the caret, up to the device to 102 change to one-offset if need be 103 @type pos: string 104 @param style: Style with which the caret should be indicated 105 @type style: L{AEOutput.Style} 106 @raise NotImplementedError: When not overridden in a subclass 107 ''' 108 raise NotImplementedError
109
110 - def sendTruncate(self, left, right, style):
111 ''' 112 Sends indicators of whether text was truncated on either side of the 113 current line or not. The style object is used by the device in deciding how 114 the truncation should be presented. 115 116 @param left: Was text truncated to the left? 117 @type left: boolean 118 @param right: Was text truncated to the right? 119 @type right: boolean 120 @param style: Style with which the truncation should be indicated 121 @type style: L{AEOutput.Style} 122 @raise NotImplementedError: When not overridden in a subclass 123 ''' 124 raise NotImplementedError
125
126 - def sendGetEllipsisSizes(self, style):
127 ''' 128 @param style: Style with which the ellipsis are defined 129 @type style: L{AEOutput.Style} 130 @return: tuple containing length of left and right ellipsis 131 @rtype: tuple 132 @raise NotImplementedError: When not overridden in a subclass 133 ''' 134 raise NotImplementedError
135
136 - def sendGetEllipsisSizes(self, style):
137 ''' 138 @param style: Style with which the ellipsis are defined 139 @type style: L{AEOutput.Style} 140 @return: tuple containing length of left and right ellipsis 141 @rtype: tuple 142 @raise NotImplementedError: When not overridden in a subclass 143 ''' 144 raise NotImplementedError
145
146 - def sendGetEllipsisSizes(self, style):
147 ''' 148 @param style: Style with which the ellipsis are defined 149 @type style: L{AEOutput.Style} 150 @return: tuple containing length of left and right ellipsis 151 @rtype: tuple 152 @raise NotImplementedError: When not overridden in a subclass 153 ''' 154 raise NotImplementedError
155
156 - def sendGetMissingCellCount(self):
157 ''' 158 @return: integer containing missing cell count 159 @rtype: integer 160 @raise NotImplementedError: When not overridden in a subclass 161 ''' 162 raise NotImplementedError
163
164 - def sendString(self, text, style):
165 ''' 166 Sends a string of one or more characters to the device. The style object 167 is used by the device in deciding how the given text should be presented. 168 169 @param text: Text to send to the device 170 @type text: string 171 @param style: Style with which this text should be output 172 @type style: L{AEOutput.Style} 173 @raise NotImplementedError: When not overridden in a subclass 174 ''' 175 raise NotImplementedError
176
177 - def sendFilename(self, fn, style):
178 ''' 179 Sends a string filename to the device, the contents of which should be 180 output. The style object is used by the device in decided how the given 181 text should be presented. 182 183 Typically, this method should be implemented by an audio device that 184 supports playback of waveform or sequencer files. It might also be used 185 by devices as a way of synthesizing the entire contents of a file without 186 having to pass all of the contents through the rest of the system. 187 188 @param fn: Absolute filename 189 @type fn: string 190 @param style: Style with which this text should be output 191 @type style: L{AEOutput.Style} 192 @raise NotImplementedError: When not overridden in a subclass 193 ''' 194 raise NotImplementedError
195
196 - def sendStop(self, style=None):
197 ''' 198 Purges buffered text and styles, and interrupts on-going output. 199 200 @param style: Style indicating which channel on which the stop should be 201 performed; None indicates stop on all channels 202 @type style: L{AEOutput.Style} 203 @raise NotImplementedError: When not overridden in a subclass 204 ''' 205 raise NotImplementedError
206
207 - def sendTalk(self, style=None):
208 ''' 209 Indicates all text buffered by L{sendString} should now be output. 210 For devices that do the buffering in the driver, this action may mean 211 simply sending the command. For devices that do not buffer, this action 212 means sending text and styles buffered in the LSR device definition. 213 214 @param style: Style indicating which channel on which the talk should be 215 performed; None indicates talk on all channels 216 @type style: L{AEOutput.Style} 217 @raise NotImplementedError: When not overridden in a subclass 218 ''' 219 raise NotImplementedError
220