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
8 @license: I{The BSD License}
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 from AccessEngine.AEDevice.AEOutput import AEOutput, Style
15 from AccessEngine import AEConstants
16 from AccessEngine.AEConstants import *
17 from Tools.i18n import _
18
20 '''
21 Defines the basic style attributes for all L{AEOutput.Braille} devices.
22
23 DisplayColumns (integer) Number of cells in each display row.
24
25 DisplayRows (integer) Number of row in display.
26
27 TotalCells (integer) Total cells in display.
28
29 CaretStyle (enum): Current caret style
30
31 EllipsisRight (bool): Does user want right ellipsis shown?
32
33 EllipsisLeft (bool): Does user want left ellipsis shown?
34
35 EllipsisStyle (enum): Current ellipsis style
36
37 CellMask (string): Missing cell string. 0=bad cell; 1=good cell.
38
39 @cvar missingcellcnt: Count of missing cells in CellMask. Initialized as a
40 class variable for convienced, but used as an instance variable.
41 @type missingcellcnt: integer
42 '''
43 missingcellcnt = 0
44
46 '''
47 Called automatically by the L{Style} base class when this style is a
48 default. Initializes all default braille options. If you want these
49 settings created, be sure to call this base class implementation if you
50 override in a subclass.
51 '''
52
53 self.newNumeric('DisplayColumns', 40, _('Columns in display'), 0, 80, 0)
54 self.newNumeric('DisplayRows', 1, _('Rows in display'), 0, 10, 0)
55 self.newNumeric('TotalCells', 40, _('Total cells in display'), 0, 800, 0)
56 self.newEnum('CaretStyle', CARET_TWO_BOTTOM, _('Caret Display Style'),
57 {_('No Caret') : CARET_NONE,
58 _('Two Bottom Pins') : CARET_TWO_BOTTOM,
59 _('Bottom Right Pins') : CARET_BOTTOM_RIGHT,
60 _('All Pins') : CARET_ALL},
61 _('Defines the caret representation.'))
62
63 self.newBool('EllipsisRight', False, _('Ellipsis right?'),
64 _('When set, ellipsis will appear when additional text is to '
65 'the right of the viewport.'))
66 self.newBool('EllipsisLeft', False, _('Ellipsis left?'),
67 _('When set, ellipsis will appear when additional text is to '
68 'the left of the viewport.'))
69 self.newEnum('EllipsisStyle', ELLIPSIS_ELLIPSIS,
70 _('Ellipsis Display Style'),
71 {_('Pin 3 in 3 cells') : ELLIPSIS_ELLIPSIS,
72 _('Continuation symbol') : ELLIPSIS_CONTINUATION},
73 _('Defines the ellipsis representation.'))
74
75 cm = self.newString('CellMask', '', _('Broken Cell String'),
76 _('String of zeros and ones indicating the functionality of '
77 'each cell'))
78
79 cm.addObserver(self._setMissingCells)
80
82 '''
83 Updates the missing cell count instance variable whenever the CellMask
84 setting changes value.
85
86 @param style: This style object
87 @type style: L{BrailleStyle}
88 @param setting: Setting that change value, namely CellMask
89 @type setting: L{AEState.Setting}
90 '''
91 self.missingcellcnt = self.CellMask.count('0')
92
94 '''
95 Builds groups of standard Braille settings that should be available for all
96 Braille devices. The groups are added directly to the root group provided.
97
98 @param root: Parent group for the word settings group
99 @type root: L{AEState.Setting.Group}
100 @return: The root group again
101 @rtype: L{AEState.Setting.Group}
102 '''
103 c = root.newGroup(_('Caret'))
104 c.append('CaretStyle')
105 d = root.newGroup(_('Ellipsis'))
106 d.append('EllipsisRight')
107 d.append('EllipsisLeft')
108 d.append('EllipsisStyle')
109 e = root.newGroup(_('Broken Cells'))
110 e.append('CellMask')
111 return root
112
114 '''
115 Defines the base class for all Braille output devices. Provides default
116 implementation of L{parseString} specific to Braille devices.
117 '''
119 '''
120 @return: 'braille' as the only capability of this device.
121 @rtype: list of string
122 '''
123 return ['braille']
124
126 '''
127 Looks at the L{AEOutput.USE_THREAD
128 <AccessEngine.AEDevice.AEOutput.Base.AEOutput.USE_THREAD>} flag to see if
129 the device implementing this interface wants a thread proxy or not.
130
131 @return: self
132 @rtype: L{AEOutput}
133 @raise NotImplementedError: When the interface wants a thread proxy.
134 '''
135 if self.USE_THREAD == True:
136 raise NotImplementedError
137 elif self.USE_THREAD == False:
138 return self
139 else:
140 raise NotImplementedError('USE_THREAD not specified')
141
143 '''
144 Dummy implementation returns the text as-is.
145
146 @param text: Text to be parsed
147 @type text: string
148 @param style: Style object defining how the text should be parsed
149 @type style: L{AEOutput.Style}
150 @param por: Point of regard for the first character in the text, or None if
151 the text is not associated with a POR
152 @type por: L{AEPor}
153 @param sem: Semantic tag for the text
154 @type sem: integer
155 @return: Parsed words
156 @rtype: 3-tuple of lists of string, L{AEPor}, L{AEOutput.Style}
157 '''
158 return [(text, por, style)]
159
160 - def send(self, name, value, style=None):
192
193
195 '''
196 Sends the current caret position relative to the first cell (zero-offset)
197 on the device. The style object is used by the device in deciding how the
198 caret should be presented.
199
200 @param pos: Zero-offset cell position of the caret, up to the device to
201 change to one-offset if need be
202 @type pos: string
203 @param style: Style with which the caret should be indicated
204 @type style: L{AEOutput.Style}
205 @raise NotImplementedError: When not overridden in a subclass
206 '''
207 raise NotImplementedError
208
210 '''
211 Sends indicators of whether text was truncated on either side of the
212 current line or not. The style object is used by the device in deciding how
213 the truncation should be presented.
214
215 @param left: Was text truncated to the left?
216 @type left: boolean
217 @param right: Was text truncated to the right?
218 @type right: boolean
219 @param style: Style with which the truncation should be indicated
220 @type style: L{AEOutput.Style}
221 @raise NotImplementedError: When not overridden in a subclass
222 '''
223 raise NotImplementedError
224
226 '''
227 @param style: Style with which the ellipsis are defined
228 @type style: L{AEOutput.Style}
229 @return: tuple containing length of left and right ellipsis
230 @rtype: tuple
231 @raise NotImplementedError: When not overridden in a subclass
232 '''
233 raise NotImplementedError
234
236 '''
237 @param style: Style with which the ellipsis are defined
238 @type style: L{AEOutput.Style}
239 @return: tuple containing length of left and right ellipsis
240 @rtype: tuple
241 @raise NotImplementedError: When not overridden in a subclass
242 '''
243 raise NotImplementedError
244
246 '''
247 @param style: Style with which the ellipsis are defined
248 @type style: L{AEOutput.Style}
249 @return: tuple containing length of left and right ellipsis
250 @rtype: tuple
251 @raise NotImplementedError: When not overridden in a subclass
252 '''
253 raise NotImplementedError
254
256 '''
257 @return: integer containing missing cell count
258 @rtype: integer
259 @raise NotImplementedError: When not overridden in a subclass
260 '''
261 raise NotImplementedError
262
264 '''
265 Sends a string of one or more characters to the device. The style object
266 is used by the device in deciding how the given text should be presented.
267
268 @param text: Text to send to the device
269 @type text: string
270 @param style: Style with which this text should be output
271 @type style: L{AEOutput.Style}
272 @raise NotImplementedError: When not overridden in a subclass
273 '''
274 raise NotImplementedError
275
277 '''
278 Sends a string filename to the device, the contents of which should be
279 output. The style object is used by the device in decided how the given
280 text should be presented.
281
282 Typically, this method should be implemented by an audio device that
283 supports playback of waveform or sequencer files. It might also be used
284 by devices as a way of synthesizing the entire contents of a file without
285 having to pass all of the contents through the rest of the system.
286
287 @param fn: Absolute filename
288 @type fn: string
289 @param style: Style with which this text should be output
290 @type style: L{AEOutput.Style}
291 @raise NotImplementedError: When not overridden in a subclass
292 '''
293 raise NotImplementedError
294
296 '''
297 Purges buffered text and styles, and interrupts on-going output.
298
299 @param style: Style indicating which channel on which the stop should be
300 performed; None indicates stop on all channels
301 @type style: L{AEOutput.Style}
302 @raise NotImplementedError: When not overridden in a subclass
303 '''
304 raise NotImplementedError
305
307 '''
308 Indicates all text buffered by L{sendString} should now be output.
309 For devices that do the buffering in the driver, this action may mean
310 simply sending the command. For devices that do not buffer, this action
311 means sending text and styles buffered in the SUE device definition.
312
313 @param style: Style indicating which channel on which the talk should be
314 performed; None indicates talk on all channels
315 @type style: L{AEOutput.Style}
316 @raise NotImplementedError: When not overridden in a subclass
317 '''
318 raise NotImplementedError
319