Package Task :: Package Tools :: Module Output
[hide private]
[frames] | no frames]

Source Code for Module Task.Tools.Output

   1  ''' 
   2  Defines L{Task.Tools} for doing output. 
   3   
   4  @author: Peter Parente 
   5  @author: Pete Brunet 
   6  @author: Brett Clippingdale 
   7  @organization: IBM Corporation 
   8  @copyright: Copyright (c) 2005, 2007 IBM Corporation 
   9  @license: The BSD License 
  10   
  11  All rights reserved. This program and the accompanying materials are made  
  12  available under the terms of the BSD license which accompanies 
  13  this distribution, and is available at 
  14  U{http://www.opensource.org/licenses/bsd-license.php} 
  15  ''' 
  16  import os 
  17  import AEConstants 
  18  import Base, View 
  19  import AEOutput 
  20  from i18n import _ 
  21  from Error import * 
  22   
23 -class Output(Base.TaskTools):
24 ''' 25 Provides methods for doing output on any L{AEOutput} device. 26 27 @cvar may_stop: Count of the number of calls to L{inhibitMayStop}. When 28 greater than zero, the next call to L{mayStop} will decrement the count. 29 When zero, L{mayStop} will send a stop to the output device. 30 @type may_stop: integer 31 ''' 32 may_stop = 0 33
34 - def setPerkIdealOutput(self, *capabilities):
35 ''' 36 Sets the ideal device capabilities to be used to locate a device for all 37 output methods invoked from the caller's L{Perk} module, including the 38 Perk class itself and all of its registered L{Task}s. The capabilities list 39 should include strings naming L{AEOutput} interfaces ("audio" and/or 40 "braille") at present. 41 42 @param capabilities: Names of capabilities required on the device 43 @type capabilities: list of string 44 ''' 45 self.perk.setIdealOutput(*capabilities) 46 self._changeDefaultOutput()
47
48 - def getPerkIdealOutput(self):
49 ''' 50 Gets the ideal device capabilities to locate a device to be used by all 51 output methods invoked from the caller's L{Perk} module, including the Perk 52 class itself and all of its registered L{Task}s. 53 54 @return: Names of capabilities set as ideal for a default output device 55 @rtype: list of string 56 ''' 57 return self.perk.getIdealOutput()
58
59 - def getOutputDevice(self, name=None, *capabilities):
60 ''' 61 Gets an L{AEOutput} device from the L{DeviceManager} given its name or 62 its capabilities. The capabilities list may include strings naming 63 L{AEOutput} interfaces ("audio" and/or "braille" at present). 64 65 If neither is specified, the first available output device in the 66 L{DeviceManager} is returned. 67 68 @param name: Class (UIE) name of the L{AEOutput} device to get 69 @type name: string 70 @param capabilities: Names of capabilities required on the device 71 @type capabilities: list of string 72 @return: The named output device 73 @rtype: L{AEOutput} 74 @raise InvalidDeviceError: When the specified L{AEInput} device is not 75 found 76 ''' 77 if name is not None: 78 device = self.device_man.getOutputByName(name) 79 elif len(capabilities): 80 device = self.device_man.getOutputByCaps(capabilities) 81 else: 82 device = self.device_man.getFirstOutput() 83 if device is None: 84 # let the system report the device isn't available 85 raise InvalidDeviceError 86 return device
87
88 - def stopNow(self, dev=None, sem=None, layer=None, reset=True):
89 ''' 90 Tells the referenced output device to interrupt current output and clear 91 buffered data. 92 93 @param dev: The device to send the stop to; defaults to None for the 94 default output device 95 @type dev: L{AEOutput.Base} 96 @param sem: The semantic information to stop; defaults to None for the 97 default semantic 98 @type sem: integer 99 @param layer: Layer on which the event occurred 100 @type layer: integer 101 @param reset: Reset the L{may_stop} count (True) or leave it as-is when 102 sending the stop? 103 @type reset: boolean 104 ''' 105 dev = dev or self.def_out 106 if reset: 107 Output.may_stop = 0 108 if not self.tier_man.getState().Stopping: 109 return 110 if layer is None: 111 layer = self.layer 112 self.device_man.sendStop(dev, sem, layer)
113
114 - def mayStop(self, dev=None, sem=None, layer=None):
115 ''' 116 Stops the device if L{may_stop} is zero. When non-zero, decrements the 117 count. 118 119 @param dev: The device to send the stop to; defaults to None for the 120 default output device 121 @type dev: L{AEOutput.Base} 122 @param sem: The semantic information to stop; defaults to None for the 123 default semantic 124 @type sem: integer 125 @param layer: Layer on which the event occurred 126 @type layer: integer 127 @return: Was the stop processed (True) or inhibited (False)? 128 @rtype: boolean 129 ''' 130 dev = dev or self.def_out 131 if layer is None: 132 layer = self.layer 133 if Output.may_stop == 0: 134 self.stopNow(dev, sem, layer) 135 return True 136 else: 137 Output.may_stop -= 1 138 if Output.may_stop < 0: 139 Output.may_stop = 0 140 return False
141
142 - def inhibitMayStop(self):
143 ''' 144 Prevents the next call to L{mayStop} from stopping the device provided to 145 that call. Adds one to the L{may_stop} flag. 146 ''' 147 Output.may_stop += 1
148
149 - def stopAll(self, dev=None):
150 ''' 151 Tells the referenced output device to interrupt current output and clear 152 buffered data. Unlike L{stopNow}, this ignores the layer on which the 153 method was called and any semantic information. Everything on the device 154 is stopped, even when L{TierManager.LSRState} stopping setting is False. 155 156 @param dev: The device to send the stop to; defaults to None for the 157 default output device 158 @type dev: L{AEOutput.Base} 159 ''' 160 dev = dev or self.def_out 161 self.device_man.sendStop(dev, None, None)
162
163 - def play(self, filename, sem=None, layer=None, dev=None, talk=True):
164 ''' 165 Outputs the contents of a file. The device used to do the output gets to 166 decide what to do with the file based on its contents and the semantic tag 167 and event layer information given. 168 169 @param filename: Name of the file to be output 170 @type filename: string 171 @param sem: The semantic stream on which to send output; defaults to None 172 for the default semantic. 173 @type sem: integer 174 @param layer: Layer on which the event occurred 175 @type layer: integer 176 @param dev: The device to send the filename to; defaults to None for the 177 default output device 178 @type dev: L{AEOutput.Base} 179 @param talk: Send a talk command immediately following the filename? 180 @type talk: boolean 181 ''' 182 dev = dev or self.def_out 183 if layer is None: 184 layer = self.layer 185 if not os.path.exists(filename): 186 filename = os.path.join(self.perk.getPath(), filename) 187 self.device_man.sendFilename(dev, filename, sem, layer) 188 if talk: 189 self.device_man.sendTalk(dev, sem, layer)
190
191 - def say(self, text, por=None, sem=None, layer=None, dev=None, talk=True):
192 ''' 193 Sends a string of text to a device that supports string display. If talk is 194 False, the device should buffer the text until another method call occurs 195 which sends a Talk to the device. 196 197 @param text: Text to output 198 @type text: string 199 @param por: The point of regard of the start of text, or None when the text 200 is not from the screen 201 @type por: L{POR} 202 @param sem: The semantic stream on which to send output; defaults to None 203 for the default semantic. 204 @type sem: integer 205 @param layer: Layer on which the event occurred 206 @type layer: integer 207 @param dev: The device to send the text to; defaults to None for the 208 default output device 209 @type dev: L{AEOutput.Base} 210 @param talk: Send a talk command immediately following the string? 211 @type talk: boolean 212 ''' 213 dev = dev or self.def_out 214 if layer is None: 215 layer = self.layer 216 self.device_man.sendString(dev, text, sem, layer, por) 217 if talk: 218 self.device_man.sendTalk(dev, sem, layer)
219
220 - def send(self, name, value, sem=None, layer=None, dev=None):
221 ''' 222 Sends arbitrary data to a device. The device must recognize the name in 223 order to decide what to do with the value data. 224 225 This is a generic method which receives all content and commands to be 226 rendered and executed on a device. Standard name identifiers should be used 227 whenever possible. For instance, L{AEConstants.Output.CMD_STOP} and 228 L{AEConstants.Output.CMD_TALK}. However, device specific names and values 229 are certainly possible. 230 231 Only use this method if no other output method is suitable for your 232 purposes. 233 234 @param name: Descriptor of the data value sent 235 @type name: object 236 @param value: Content value 237 @type value: object 238 @param sem: The semantic stream on which to send output; defaults to None 239 for the default semantic. 240 @type sem: integer 241 @param layer: Layer on which the event occurred 242 @type layer: integer 243 @param dev: Device that should receive the command 244 @type dev: L{AEOutput} 245 @return: Return value specific to the given command 246 @rtype: object 247 ''' 248 dev = dev or self.def_out 249 if layer is None: 250 layer = self.layer 251 rv = self.device_man.send(dev, name, value, sem, layer) 252 return rv
253
254 - def getStyle(self, dev=None, sem=None, layer=None):
255 ''' 256 Gets the L{AEOutput.Style} object for the given device, semantic tag, and 257 event layer. This is a low level method that allows direct access to 258 L{AEOutput.Style} style objects. 259 260 @see: L{getStyleSetting} 261 @param dev: The device on which to get the value; defaults to None for the 262 default output device. 263 @type dev: L{AEOutput.Base} 264 @param sem: The semantic on which to get the value. 265 @type sem: integer 266 @param layer: Layer on which to get the value, focus, tier, or background 267 @type layer: integer 268 @return: The style object or None if one does not exist 269 @rtype: L{AEOutput.Style} 270 ''' 271 dev = dev or self.def_out 272 layer = layer or self.layer 273 return self.device_man.getStyle(dev, sem, layer)
274
275 - def getStyleSetting(self, name, dev=None, sem=None, layer=None):
276 ''' 277 Gets the L{AEOutput.Style} object for the given device, semantic tag, and 278 event layer, then immediately fetches the L{AEState.Setting} object with 279 the given name. This is a low level method that allows direct access to 280 L{AEState.Setting}s on the style. It is permissible to read/write the value 281 property of settings fields and register for change notifications. 282 283 @attention: If a method attached to a L{Perk} or L{Task} is used as a 284 callback for a style value change notification, be aware that the L{Perk} 285 or L{Task} will NOT be pre-executed when the callback runs with all 286 references needed by the L{Task.Tools}. 287 288 @param name: Name of the setting object to fetch 289 @type name: string 290 @param dev: The device on which this setting should be changed. Defaults to 291 the default output device established by L{setPerkIdealOutput}. 292 @type dev: L{AEOutput.Base} 293 @param sem: The semantic on which to change the value. Defaults to None 294 meaning the default style 295 @type sem: integer 296 @param layer: Layer on which to set the value: focus, tier, or background. 297 Defaults to the event layer that triggered this L{Task}. 298 @type layer: integer 299 @return: The setting object 300 @rtype: L{AEState.Setting} 301 @raise InvalidStyleError: When the style or the setting name is not valid 302 ''' 303 s = self.getStyle(dev, sem, layer) 304 try: 305 return s.getSettingObj(name) 306 except (TypeError, KeyError): 307 raise InvalidStyleError
308
309 - def getStyleVal(self, name, dev=None, sem=None, layer=None):
310 ''' 311 Gets the L{AEOutput.Style} object for the given device, semantic tag, and 312 event layer, then immediately fetches the value of the L{AEState.Setting} 313 object with the given name. 314 315 @param name: Name of the setting value to fetch 316 @type name: string 317 @param dev: The device on which this setting should be changed. Defaults to 318 the default output device established by L{setPerkIdealOutput}. 319 @type dev: L{AEOutput.Base} 320 @param sem: The semantic on which to change the value. Defaults to None 321 meaning the default style 322 @type sem: integer 323 @param layer: Layer on which to set the value: focus, tier, or background. 324 Defaults to the event layer that triggered this L{Task}. 325 @type layer: integer 326 @return: The setting value 327 @rtype: object 328 @raise InvalidStyleError: When the style or the setting name is not valid 329 ''' 330 s = self.getStyle(dev, sem, layer) 331 try: 332 return s.getSettingVal(name) 333 except (TypeError, KeyError): 334 raise InvalidStyleError
335
336 - def setStyleVal(self, name, val, dev=None, sem=None, layer=None):
337 ''' 338 Gets the L{AEOutput.Style} object for the given device, semantic tag, and 339 event layer, then immediately sets the value of the L{AEState.Setting} 340 object with the given name. 341 342 @param name: Name of the setting value to fetch 343 @type name: string 344 @param val: The setting value 345 @type val: object 346 @param dev: The device on which this setting should be changed. Defaults to 347 the default output device established by L{setPerkIdealOutput}. 348 @type dev: L{AEOutput.Base} 349 @param sem: The semantic on which to change the value. Defaults to None 350 meaning the default style 351 @type sem: integer 352 @param layer: Layer on which to set the value: focus, tier, or background. 353 Defaults to the event layer that triggered this L{Task}. 354 @type layer: integer 355 @raise InvalidStyleError: When the style or the setting name is not valid 356 ''' 357 s = self.getStyle(dev, sem, layer) 358 try: 359 return s.setSettingVal(name,val ) 360 except (TypeError, KeyError): 361 raise InvalidStyleError
362 363 ############################################################################## 364 # The following say___() methods are autogenerated by EmitSay.py 365 # These are autogenerated in full (rather than with dynamic code generation or 366 # with other Python approaches, such as decorators) to allow epydoc to 367 # generate complete documentation for Perk writers 368 ##############################################################################
369 - def sayTextAttrs(self, por=None, text=None, template=u'%s', 370 dev=None, talk=True):
371 ''' 372 Calls L{Task.Tools.View.View.getAccAllTextAttrs} and outputs the result. 373 374 @param por: L{POR} pointing at an accessible whose value will be read or 375 None when the L{task_por} should be used. The value is read only if the 376 text parameter is None. 377 @type por: L{POR} 378 @param text: Manually provided text fetched from the L{POR} 379 @type text: string 380 @param template: Template for text to be spoken. Defaults to %s indicating 381 the text or value retrieved from the L{POR} is spoken by itself. 382 @type template: string 383 @param dev: The device to use for output. Defaults to the default output 384 device established by L{setPerkIdealOutput}. 385 @type dev: L{AEOutput.Base} 386 @param talk: Send a L{AEConstants.Output.CMD_TALK} immediately after this 387 string is sent? 388 @type talk: boolean 389 @return: Was anything sent for output (True) or was text None (False)? 390 @rtype: boolean 391 ''' 392 if text is None: 393 por = por or self.task_por 394 attrs = self.getAccAllTextAttrs(por) 395 if not attrs: 396 return False 397 text = ', '.join(attrs.items()) 398 if text is None: 399 return False 400 self.say(template % text, por, AEConstants.SEM_TEXT_ATTR, self.layer, dev, 401 talk) 402 return True
403
404 - def sayWord(self, por=None, text=None, template=u'%s', 405 dev=None, talk=True):
406 ''' 407 Calls L{Task.Tools.View.View.getWordText} and outputs the result. 408 409 @param por: L{POR} pointing at an accessible whose value will be read or 410 None when the L{task_por} should be used. The value is read only if the 411 text parameter is None. 412 @type por: L{POR} 413 @param text: Manually provided text fetched from the L{POR} 414 @type text: string 415 @param template: Template for text to be spoken. Defaults to %s indicating 416 the text or value retrieved from the L{POR} is spoken by itself. 417 @type template: string 418 @param dev: The device to use for output. Defaults to the default output 419 device established by L{setPerkIdealOutput}. 420 @type dev: L{AEOutput.Base} 421 @param talk: Send a L{AEConstants.Output.CMD_TALK} immediately after this 422 string is sent? 423 @type talk: boolean 424 @return: Was anything sent for output (True) or was text None (False)? 425 @rtype: boolean 426 ''' 427 if text is None: 428 por = por or self.task_por 429 text = self.getWordText(por) 430 if text is None: 431 return False 432 self.say(template % text, por, AEConstants.SEM_WORD, self.layer, dev, 433 talk) 434 return True
435
436 - def sayChar(self, por=None, text=None, template=u'%s', 437 dev=None, talk=True):
438 ''' 439 Calls L{Task.Tools.View.View.getCharText} and outputs the result. 440 441 @param por: L{POR} pointing at an accessible whose value will be read or 442 None when the L{task_por} should be used. The value is read only if the 443 text parameter is None. 444 @type por: L{POR} 445 @param text: Manually provided text fetched from the L{POR} 446 @type text: string 447 @param template: Template for text to be spoken. Defaults to %s indicating 448 the text or value retrieved from the L{POR} is spoken by itself. 449 @type template: string 450 @param dev: The device to use for output. Defaults to the default output 451 device established by L{setPerkIdealOutput}. 452 @type dev: L{AEOutput.Base} 453 @param talk: Send a L{AEConstants.Output.CMD_TALK} immediately after this 454 string is sent? 455 @type talk: boolean 456 @return: Was anything sent for output (True) or was text None (False)? 457 @rtype: boolean 458 ''' 459 if text is None: 460 por = por or self.task_por 461 text = self.getCharText(por) 462 if text is None: 463 return False 464 self.say(template % text, por, AEConstants.SEM_CHAR, self.layer, dev, 465 talk) 466 return True
467
468 - def sayName(self, por=None, text=None, template=u'%s', 469 dev=None, talk=True):
470 ''' 471 Calls L{Task.Tools.View.View.getAccName} and outputs the result. 472 473 @param por: L{POR} pointing at an accessible whose value will be read or 474 None when the L{task_por} should be used. The value is read only if the 475 text parameter is None. 476 @type por: L{POR} 477 @param text: Manually provided text fetched from the L{POR} 478 @type text: string 479 @param template: Template for text to be spoken. Defaults to %s indicating 480 the text or value retrieved from the L{POR} is spoken by itself. 481 @type template: string 482 @param dev: The device to use for output. Defaults to the default output 483 device established by L{setPerkIdealOutput}. 484 @type dev: L{AEOutput.Base} 485 @param talk: Send a L{AEConstants.Output.CMD_TALK} immediately after this 486 string is sent? 487 @type talk: boolean 488 @return: Was anything sent for output (True) or was text None (False)? 489 @rtype: boolean 490 ''' 491 if text is None: 492 por = por or self.task_por 493 text = self.getAccName(por) 494 if text is None: 495 return False 496 self.say(template % text, por, AEConstants.SEM_NAME, self.layer, dev, 497 talk) 498 return True
499
500 - def sayLabel(self, por=None, text=None, template=u'%s', 501 dev=None, talk=True):
502 ''' 503 Calls L{Task.Tools.View.View.getAccLabel} and outputs the result. 504 505 @param por: L{POR} pointing at an accessible whose value will be read or 506 None when the L{task_por} should be used. The value is read only if the 507 text parameter is None. 508 @type por: L{POR} 509 @param text: Manually provided text fetched from the L{POR} 510 @type text: string 511 @param template: Template for text to be spoken. Defaults to %s indicating 512 the text or value retrieved from the L{POR} is spoken by itself. 513 @type template: string 514 @param dev: The device to use for output. Defaults to the default output 515 device established by L{setPerkIdealOutput}. 516 @type dev: L{AEOutput.Base} 517 @param talk: Send a L{AEConstants.Output.CMD_TALK} immediately after this 518 string is sent? 519 @type talk: boolean 520 @return: Was anything sent for output (True) or was text None (False)? 521 @rtype: boolean 522 ''' 523 if text is None: 524 por = por or self.task_por 525 text = self.getAccLabel(por) 526 if text is None: 527 return False 528 self.say(template % text, por, AEConstants.SEM_LABEL, self.layer, dev, 529 talk) 530 return True
531
532 - def sayItem(self, por=None, text=None, template=u'%s', 533 dev=None, talk=True):
534 ''' 535 Calls L{Task.Tools.View.View.getItemText} and outputs the result. 536 537 @param por: L{POR} pointing at an accessible whose value will be read or 538 None when the L{task_por} should be used. The value is read only if the 539 text parameter is None. 540 @type por: L{POR} 541 @param text: Manually provided text fetched from the L{POR} 542 @type text: string 543 @param template: Template for text to be spoken. Defaults to %s indicating 544 the text or value retrieved from the L{POR} is spoken by itself. 545 @type template: string 546 @param dev: The device to use for output. Defaults to the default output 547 device established by L{setPerkIdealOutput}. 548 @type dev: L{AEOutput.Base} 549 @param talk: Send a L{AEConstants.Output.CMD_TALK} immediately after this 550 string is sent? 551 @type talk: boolean 552 @return: Was anything sent for output (True) or was text None (False)? 553 @rtype: boolean 554 ''' 555 if text is None: 556 por = por or self.task_por 557 text = self.getItemText(por) 558 if text is None: 559 return False 560 self.say(template % text, por, AEConstants.SEM_ITEM, self.layer, dev, 561 talk) 562 return True
563
564 - def sayWindow(self, por=None, text=None, template=u'%s', 565 dev=None, talk=True):
566 ''' 567 Calls L{Task.Tools.View.View.getWindowTitle} and outputs the result. 568 569 @param por: L{POR} pointing at an accessible whose value will be read or 570 None when the L{task_por} should be used. The value is read only if the 571 text parameter is None. 572 @type por: L{POR} 573 @param text: Manually provided text fetched from the L{POR} 574 @type text: string 575 @param template: Template for text to be spoken. Defaults to %s indicating 576 the text or value retrieved from the L{POR} is spoken by itself. 577 @type template: string 578 @param dev: The device to use for output. Defaults to the default output 579 device established by L{setPerkIdealOutput}. 580 @type dev: L{AEOutput.Base} 581 @param talk: Send a L{AEConstants.Output.CMD_TALK} immediately after this 582 string is sent? 583 @type talk: boolean 584 @return: Was anything sent for output (True) or was text None (False)? 585 @rtype: boolean 586 ''' 587 if text is None: 588 por = por or self.task_por 589 text = self.getWindowTitle(por) 590 if text is None: 591 return False 592 self.say(template % text, por, AEConstants.SEM_WINDOW, self.layer, dev, 593 talk) 594 return True
595
596 - def saySection(self, por=None, text=None, template=u'%s', 597 dev=None, talk=True):
598 ''' 599 Calls L{Task.Tools.View.View.getAccLabel} and outputs the result. 600 601 @param por: L{POR} pointing at an accessible whose value will be read or 602 None when the L{task_por} should be used. The value is read only if the 603 text parameter is None. 604 @type por: L{POR} 605 @param text: Manually provided text fetched from the L{POR} 606 @type text: string 607 @param template: Template for text to be spoken. Defaults to %s indicating 608 the text or value retrieved from the L{POR} is spoken by itself. 609 @type template: string 610 @param dev: The device to use for output. Defaults to the default output 611 device established by L{setPerkIdealOutput}. 612 @type dev: L{AEOutput.Base} 613 @param talk: Send a L{AEConstants.Output.CMD_TALK} immediately after this 614 string is sent? 615 @type talk: boolean 616 @return: Was anything sent for output (True) or was text None (False)? 617 @rtype: boolean 618 ''' 619 if text is None: 620 por = por or self.task_por 621 text = self.getAccLabel(por) 622 if text is None: 623 return False 624 self.say(template % text, por, AEConstants.SEM_SECTION, self.layer, dev, 625 talk) 626 return True
627
628 - def sayApp(self, por=None, text=None, template=u'%s', 629 dev=None, talk=True):
630 ''' 631 Calls L{Task.Tools.View.View.getAppName} and outputs the result. 632 633 @param por: L{POR} pointing at an accessible whose value will be read or 634 None when the L{task_por} should be used. The value is read only if the 635 text parameter is None. 636 @type por: L{POR} 637 @param text: Manually provided text fetched from the L{POR} 638 @type text: string 639 @param template: Template for text to be spoken. Defaults to %s indicating 640 the text or value retrieved from the L{POR} is spoken by itself. 641 @type template: string 642 @param dev: The device to use for output. Defaults to the default output 643 device established by L{setPerkIdealOutput}. 644 @type dev: L{AEOutput.Base} 645 @param talk: Send a L{AEConstants.Output.CMD_TALK} immediately after this 646 string is sent? 647 @type talk: boolean 648 @return: Was anything sent for output (True) or was text None (False)? 649 @rtype: boolean 650 ''' 651 if text is None: 652 por = por or self.task_por 653 text = self.getAppName(por) 654 if text is None: 655 return False 656 self.say(template % text, por, AEConstants.SEM_APP, self.layer, dev, 657 talk) 658 return True
659
660 - def sayFont(self, por=None, text=None, template=u'%s', 661 dev=None, talk=True):
662 ''' 663 Calls L{Task.Tools.View.View.getAccTextAttr} and outputs the value 664 associated with the "family-name" property. 665 666 @param por: L{POR} pointing at an accessible whose value will be read or 667 None when the L{task_por} should be used. The value is read only if the 668 text parameter is None. 669 @type por: L{POR} 670 @param text: Manually provided text fetched from the L{POR} 671 @type text: string 672 @param template: Template for text to be spoken. Defaults to %s indicating 673 the text or value retrieved from the L{POR} is spoken by itself. 674 @type template: string 675 @param dev: The device to use for output. Defaults to the default output 676 device established by L{setPerkIdealOutput}. 677 @type dev: L{AEOutput.Base} 678 @param talk: Send a L{AEConstants.Output.CMD_TALK} immediately after this 679 string is sent? 680 @type talk: boolean 681 @return: Was anything sent for output (True) or was text None (False)? 682 @rtype: boolean 683 ''' 684 if text is None: 685 por = por or self.task_por 686 687 text = self.getAccTextAttr('family-name', por) 688 if text is None: 689 return False 690 self.say(template % text, por, AEConstants.SEM_FONT, self.layer, dev, 691 talk) 692 return True
693
694 - def sayCount(self, por=None, text=None, template=u'%s', 695 dev=None, talk=True):
696 ''' 697 Calls L{Task.Tools.View.View.getAccCount} and outputs the result. 698 699 @param por: L{POR} pointing at an accessible whose value will be read or 700 None when the L{task_por} should be used. The value is read only if the 701 text parameter is None. 702 @type por: L{POR} 703 @param text: Manually provided text fetched from the L{POR} 704 @type text: string 705 @param template: Template for text to be spoken. Defaults to %s indicating 706 the text or value retrieved from the L{POR} is spoken by itself. 707 @type template: string 708 @param dev: The device to use for output. Defaults to the default output 709 device established by L{setPerkIdealOutput}. 710 @type dev: L{AEOutput.Base} 711 @param talk: Send a L{AEConstants.Output.CMD_TALK} immediately after this 712 string is sent? 713 @type talk: boolean 714 @return: Was anything sent for output (True) or was text None (False)? 715 @rtype: boolean 716 ''' 717 if text is None: 718 por = por or self.task_por 719 text = self.getAccCount(por) 720 if text is None: 721 return False 722 self.say(template % text, por, AEConstants.SEM_COUNT, self.layer, dev, 723 talk) 724 return True
725
726 - def sayIndex(self, por=None, text=None, template=u'%s', 727 dev=None, talk=True):
728 ''' 729 Calls L{Task.Tools.View.View.getAccIndex} and outputs the result. 730 731 @param por: L{POR} pointing at an accessible whose value will be read or 732 None when the L{task_por} should be used. The value is read only if the 733 text parameter is None. 734 @type por: L{POR} 735 @param text: Manually provided text fetched from the L{POR} 736 @type text: string 737 @param template: Template for text to be spoken. Defaults to %s indicating 738 the text or value retrieved from the L{POR} is spoken by itself. 739 @type template: string 740 @param dev: The device to use for output. Defaults to the default output 741 device established by L{setPerkIdealOutput}. 742 @type dev: L{AEOutput.Base} 743 @param talk: Send a L{AEConstants.Output.CMD_TALK} immediately after this 744 string is sent? 745 @type talk: boolean 746 @return: Was anything sent for output (True) or was text None (False)? 747 @rtype: boolean 748 ''' 749 if text is None: 750 por = por or self.task_por 751 text = self.getAccIndex(por) 752 if text is None: 753 return False 754 self.say(template % text, por, AEConstants.SEM_INDEX, self.layer, dev, 755 talk) 756 return True
757
758 - def sayColor(self, por=None, text=None, template=u'%s', 759 dev=None, talk=True):
760 ''' 761 Calls L{Task.Tools.View.View.getAccTextAttr} and outputs the value 762 associated with the "fg-color" property. 763 764 @param por: L{POR} pointing at an accessible whose value will be read or 765 None when the L{task_por} should be used. The value is read only if the 766 text parameter is None. 767 @type por: L{POR} 768 @param text: Manually provided text fetched from the L{POR} 769 @type text: string 770 @param template: Template for text to be spoken. Defaults to %s indicating 771 the text or value retrieved from the L{POR} is spoken by itself. 772 @type template: string 773 @param dev: The device to use for output. Defaults to the default output 774 device established by L{setPerkIdealOutput}. 775 @type dev: L{AEOutput.Base} 776 @param talk: Send a L{AEConstants.Output.CMD_TALK} immediately after this 777 string is sent? 778 @type talk: boolean 779 @return: Was anything sent for output (True) or was text None (False)? 780 @rtype: boolean 781 ''' 782 if text is None: 783 por = por or self.task_por 784 785 text = self.getAccTextAttr('fg-color', por) 786 if text is None: 787 return False 788 self.say(template % text, por, AEConstants.SEM_COLOR, self.layer, dev, 789 talk) 790 return True
791
792 - def sayRole(self, por=None, text=None, template=u'%s', 793 dev=None, talk=True):
794 ''' 795 Calls L{Task.Tools.View.View.getAccRoleName} and outputs the result. 796 797 @param por: L{POR} pointing at an accessible whose value will be read or 798 None when the L{task_por} should be used. The value is read only if the 799 text parameter is None. 800 @type por: L{POR} 801 @param text: Manually provided text fetched from the L{POR} 802 @type text: string 803 @param template: Template for text to be spoken. Defaults to %s indicating 804 the text or value retrieved from the L{POR} is spoken by itself. 805 @type template: string 806 @param dev: The device to use for output. Defaults to the default output 807 device established by L{setPerkIdealOutput}. 808 @type dev: L{AEOutput.Base} 809 @param talk: Send a L{AEConstants.Output.CMD_TALK} immediately after this 810 string is sent? 811 @type talk: boolean 812 @return: Was anything sent for output (True) or was text None (False)? 813 @rtype: boolean 814 ''' 815 if text is None: 816 por = por or self.task_por 817 text = self.getAccRoleName(por) 818 if text is None: 819 return False 820 self.say(template % text, por, AEConstants.SEM_ROLE, self.layer, dev, 821 talk) 822 return True
823
824 - def sayLevel(self, por=None, text=None, template=u'%s', 825 dev=None, talk=True):
826 ''' 827 Calls L{Task.Tools.View.View.getAccLevel} and outputs the result. 828 829 @param por: L{POR} pointing at an accessible whose value will be read or 830 None when the L{task_por} should be used. The value is read only if the 831 text parameter is None. 832 @type por: L{POR} 833 @param text: Manually provided text fetched from the L{POR} 834 @type text: string 835 @param template: Template for text to be spoken. Defaults to %s indicating 836 the text or value retrieved from the L{POR} is spoken by itself. 837 @type template: string 838 @param dev: The device to use for output. Defaults to the default output 839 device established by L{setPerkIdealOutput}. 840 @type dev: L{AEOutput.Base} 841 @param talk: Send a L{AEConstants.Output.CMD_TALK} immediately after this 842 string is sent? 843 @type talk: boolean 844 @return: Was anything sent for output (True) or was text None (False)? 845 @rtype: boolean 846 ''' 847 if text is None: 848 por = por or self.task_por 849 text = self.getAccLevel(por) 850 if text is None: 851 return False 852 self.say(template % text, por, AEConstants.SEM_LEVEL, self.layer, dev, 853 talk) 854 return True
855
856 - def sayStatus(self, por=None, text=None, template=u'%s', 857 dev=None, talk=True):
858 ''' 859 Calls L{Task.Tools.View.View.getItemText} and outputs the result. 860 861 @param por: L{POR} pointing at an accessible whose value will be read or 862 None when the L{task_por} should be used. The value is read only if the 863 text parameter is None. 864 @type por: L{POR} 865 @param text: Manually provided text fetched from the L{POR} 866 @type text: string 867 @param template: Template for text to be spoken. Defaults to %s indicating 868 the text or value retrieved from the L{POR} is spoken by itself. 869 @type template: string 870 @param dev: The device to use for output. Defaults to the default output 871 device established by L{setPerkIdealOutput}. 872 @type dev: L{AEOutput.Base} 873 @param talk: Send a L{AEConstants.Output.CMD_TALK} immediately after this 874 string is sent? 875 @type talk: boolean 876 @return: Was anything sent for output (True) or was text None (False)? 877 @rtype: boolean 878 ''' 879 if text is None: 880 por = por or self.task_por 881 text = self.getItemText(por) 882 if text is None: 883 return False 884 self.say(template % text, por, AEConstants.SEM_STATUS, self.layer, dev, 885 talk) 886 return True
887
888 - def sayState(self, por=None, text=None, template=u'%s', 889 dev=None, talk=True):
890 ''' 891 Calls L{Task.Tools.View.View.getStateText} and outputs the result. 892 893 @param por: L{POR} pointing at an accessible whose value will be read or 894 None when the L{task_por} should be used. The value is read only if the 895 text parameter is None. 896 @type por: L{POR} 897 @param text: Manually provided text fetched from the L{POR} 898 @type text: string 899 @param template: Template for text to be spoken. Defaults to %s indicating 900 the text or value retrieved from the L{POR} is spoken by itself. 901 @type template: string 902 @param dev: The device to use for output. Defaults to the default output 903 device established by L{setPerkIdealOutput}. 904 @type dev: L{AEOutput.Base} 905 @param talk: Send a L{AEConstants.Output.CMD_TALK} immediately after this 906 string is sent? 907 @type talk: boolean 908 @return: Was anything sent for output (True) or was text None (False)? 909 @rtype: boolean 910 ''' 911 if text is None: 912 por = por or self.task_por 913 text = self.getStateText(por) 914 if text is None: 915 return False 916 self.say(template % text, por, AEConstants.SEM_STATE, self.layer, dev, 917 talk) 918 return True
919
920 - def sayDesc(self, por=None, text=None, template=u'%s', 921 dev=None, talk=True):
922 ''' 923 Calls L{Task.Tools.View.View.getAccDesc} and outputs the result. 924 925 @param por: L{POR} pointing at an accessible whose value will be read or 926 None when the L{task_por} should be used. The value is read only if the 927 text parameter is None. 928 @type por: L{POR} 929 @param text: Manually provided text fetched from the L{POR} 930 @type text: string 931 @param template: Template for text to be spoken. Defaults to %s indicating 932 the text or value retrieved from the L{POR} is spoken by itself. 933 @type template: string 934 @param dev: The device to use for output. Defaults to the default output 935 device established by L{setPerkIdealOutput}. 936 @type dev: L{AEOutput.Base} 937 @param talk: Send a L{AEConstants.Output.CMD_TALK} immediately after this 938 string is sent? 939 @type talk: boolean 940 @return: Was anything sent for output (True) or was text None (False)? 941 @rtype: boolean 942 ''' 943 if text is None: 944 por = por or self.task_por 945 text = self.getAccDesc(por) 946 if text is None: 947 return False 948 self.say(template % text, por, AEConstants.SEM_DESC, self.layer, dev, 949 talk) 950 return True
951
952 - def sayHotkey(self, por=None, text=None, template=u'%s', 953 dev=None, talk=True):
954 ''' 955 Calls L{Task.Tools.View.View.getAccClickKey} and outputs the 956 result after replacing <> characters. 957 958 @param por: L{POR} pointing at an accessible whose value will be read or 959 None when the L{task_por} should be used. The value is read only if the 960 text parameter is None. 961 @type por: L{POR} 962 @param text: Manually provided text fetched from the L{POR} 963 @type text: string 964 @param template: Template for text to be spoken. Defaults to %s indicating 965 the text or value retrieved from the L{POR} is spoken by itself. 966 @type template: string 967 @param dev: The device to use for output. Defaults to the default output 968 device established by L{setPerkIdealOutput}. 969 @type dev: L{AEOutput.Base} 970 @param talk: Send a L{AEConstants.Output.CMD_TALK} immediately after this 971 string is sent? 972 @type talk: boolean 973 @return: Was anything sent for output (True) or was text None (False)? 974 @rtype: boolean 975 ''' 976 if text is None: 977 por = por or self.task_por 978 text = self.getAccClickKey(por) 979 # remove extra characters from the text; this will probably break hotkeys 980 # that use < and >; can fix with a regex 981 try: 982 text = text.replace('<', '') 983 text = text.replace('>', ', ') 984 except AttributeError: 985 pass 986 if text is None: 987 return False 988 self.say(template % text, por, AEConstants.SEM_HOTKEY, self.layer, dev, 989 talk) 990 return True
991
992 - def sayError(self, por=None, text=None, template=u'%s', 993 dev=None, talk=True):
994 ''' 995 Outputs an LSR system error message. L{POR} ignored. 996 997 @param por: L{POR} pointing at an accessible whose value will be read or 998 None when the L{task_por} should be used. The value is read only if the 999 text parameter is None. 1000 @type por: L{POR} 1001 @param text: Manually provided text fetched from the L{POR} 1002 @type text: string 1003 @param template: Template for text to be spoken. Defaults to %s indicating 1004 the text or value retrieved from the L{POR} is spoken by itself. 1005 @type template: string 1006 @param dev: The device to use for output. Defaults to the default output 1007 device established by L{setPerkIdealOutput}. 1008 @type dev: L{AEOutput.Base} 1009 @param talk: Send a L{AEConstants.Output.CMD_TALK} immediately after this 1010 string is sent? 1011 @type talk: boolean 1012 @return: Was anything sent for output (True) or was text None (False)? 1013 @rtype: boolean 1014 ''' 1015 if text is None: 1016 por = por or self.task_por 1017 1018 if text is None: 1019 return False 1020 self.say(template % text, por, AEConstants.SEM_ERROR, self.layer, dev, 1021 talk) 1022 return True
1023
1024 - def sayInfo(self, por=None, text=None, template=u'%s', 1025 dev=None, talk=True):
1026 ''' 1027 Outputs an informational LSR system message. L{POR} ignored. 1028 1029 @param por: L{POR} pointing at an accessible whose value will be read or 1030 None when the L{task_por} should be used. The value is read only if the 1031 text parameter is None. 1032 @type por: L{POR} 1033 @param text: Manually provided text fetched from the L{POR} 1034 @type text: string 1035 @param template: Template for text to be spoken. Defaults to %s indicating 1036 the text or value retrieved from the L{POR} is spoken by itself. 1037 @type template: string 1038 @param dev: The device to use for output. Defaults to the default output 1039 device established by L{setPerkIdealOutput}. 1040 @type dev: L{AEOutput.Base} 1041 @param talk: Send a L{AEConstants.Output.CMD_TALK} immediately after this 1042 string is sent? 1043 @type talk: boolean 1044 @return: Was anything sent for output (True) or was text None (False)? 1045 @rtype: boolean 1046 ''' 1047 if text is None: 1048 por = por or self.task_por 1049 1050 if text is None: 1051 return False 1052 self.say(template % text, por, AEConstants.SEM_INFO, self.layer, dev, 1053 talk) 1054 return True
1055
1056 - def sayConfirm(self, por=None, text=None, template=u'%s', 1057 dev=None, talk=True):
1058 ''' 1059 Outputs a confirmation message for a user action. L{POR} ignored. 1060 1061 @param por: L{POR} pointing at an accessible whose value will be read or 1062 None when the L{task_por} should be used. The value is read only if the 1063 text parameter is None. 1064 @type por: L{POR} 1065 @param text: Manually provided text fetched from the L{POR} 1066 @type text: string 1067 @param template: Template for text to be spoken. Defaults to %s indicating 1068 the text or value retrieved from the L{POR} is spoken by itself. 1069 @type template: string 1070 @param dev: The device to use for output. Defaults to the default output 1071 device established by L{setPerkIdealOutput}. 1072 @type dev: L{AEOutput.Base} 1073 @param talk: Send a L{AEConstants.Output.CMD_TALK} immediately after this 1074 string is sent? 1075 @type talk: boolean 1076 @return: Was anything sent for output (True) or was text None (False)? 1077 @rtype: boolean 1078 ''' 1079 if text is None: 1080 por = por or self.task_por 1081 1082 if text is None: 1083 return False 1084 self.say(template % text, por, AEConstants.SEM_CONFIRM, self.layer, dev, 1085 talk) 1086 return True
1087
1088 - def sayValue(self, por=None, text=None, template=u'%s', 1089 dev=None, talk=True):
1090 ''' 1091 Calls L{Task.Tools.View.View.getAccFloatValue} and outputs the result. 1092 1093 @param por: L{POR} pointing at an accessible whose value will be read or 1094 None when the L{task_por} should be used. The value is read only if the 1095 text parameter is None. 1096 @type por: L{POR} 1097 @param text: Manually provided text fetched from the L{POR} 1098 @type text: string 1099 @param template: Template for text to be spoken. Defaults to %s indicating 1100 the text or value retrieved from the L{POR} is spoken by itself. 1101 @type template: string 1102 @param dev: The device to use for output. Defaults to the default output 1103 device established by L{setPerkIdealOutput}. 1104 @type dev: L{AEOutput.Base} 1105 @param talk: Send a L{AEConstants.Output.CMD_TALK} immediately after this 1106 string is sent? 1107 @type talk: boolean 1108 @return: Was anything sent for output (True) or was text None (False)? 1109 @rtype: boolean 1110 ''' 1111 if text is None: 1112 por = por or self.task_por 1113 text = self.getAccFloatValue(por) 1114 if text is None: 1115 return False 1116 self.say(template % text, por, AEConstants.SEM_VALUE, self.layer, dev, 1117 talk) 1118 return True
1119
1120 - def sayValueExtents(self, por=None, text=None, template=u'%s', 1121 dev=None, talk=True):
1122 ''' 1123 Calls L{Task.Tools.View.View.getAccFloatValueExtents} and outputs the 1124 result. 1125 1126 @param por: L{POR} pointing at an accessible whose value will be read or 1127 None when the L{task_por} should be used. The value is read only if the 1128 text parameter is None. 1129 @type por: L{POR} 1130 @param text: Manually provided text fetched from the L{POR} 1131 @type text: string 1132 @param template: Template for text to be spoken. Defaults to %s indicating 1133 the text or value retrieved from the L{POR} is spoken by itself. 1134 @type template: string 1135 @param dev: The device to use for output. Defaults to the default output 1136 device established by L{setPerkIdealOutput}. 1137 @type dev: L{AEOutput.Base} 1138 @param talk: Send a L{AEConstants.Output.CMD_TALK} immediately after this 1139 string is sent? 1140 @type talk: boolean 1141 @return: Was anything sent for output (True) or was text None (False)? 1142 @rtype: boolean 1143 ''' 1144 if text is None: 1145 por = por or self.task_por 1146 text = self.getAccFloatValueExtents(por) 1147 if text is None: 1148 return False 1149 self.say(template % text, por, AEConstants.SEM_EXTENTS, self.layer, dev, 1150 talk) 1151 return True
1152
1153 - def setBrlCaretPosition(self, value, sem=None, layer=None, dev=None):
1154 ''' 1155 Sets caret location on the device. 1156 1157 @param value: Caret position 1158 @type value: integer 1159 @param sem: The semantic stream on which to send output; defaults to None 1160 for the default semantic. 1161 @type sem: integer 1162 @param layer: Layer on which the event occurred 1163 @type layer: integer 1164 @param dev: Device that should receive the command 1165 @type dev: L{AEOutput} 1166 ''' 1167 self.send(AEConstants.CMD_CARET, value, sem=sem, \ 1168 layer=layer, dev=dev)
1169
1170 - def setBrlTruncate(self, value, sem=None, layer=None, dev=None):
1171 ''' 1172 Sets a two-item tuple (left, right) to the device indicating if a line of 1173 text has been truncated either on the left or right side. 1174 1175 @param value: Two-item tuple of booleans (left, right) indicating trucation 1176 @type value: tuple 1177 @param sem: The semantic stream on which to send output; defaults to None 1178 for the default semantic. 1179 @type sem: integer 1180 @param layer: Layer on which the event occurred 1181 @type layer: integer 1182 @param dev: Device that should receive the command 1183 @type dev: L{AEOutput} 1184 @return: Return value specific to the given command 1185 @rtype: object 1186 ''' 1187 self.send(AEConstants.CMD_TRUNCATE, value, sem=sem, \ 1188 layer=layer, dev=dev)
1189
1190 - def getBrlEllipsisSizes(self, sem=None, layer=None, dev=None):
1191 ''' 1192 Gets a two-item tuple (left and right) containing the ellipsis length. 1193 1194 @param sem: The semantic stream on which to send output; defaults to None 1195 for the default semantic. 1196 @type sem: integer 1197 @param layer: Layer on which the event occurred 1198 @type layer: integer 1199 @param dev: Device that should receive the command 1200 @type dev: L{AEOutput} 1201 @return: (left, right) ellipsis length 1202 @rtype: tuple 1203 ''' 1204 return self.send(AEConstants.CMD_GET_ELLIPSIS_SIZE, None, sem=sem, \ 1205 layer=layer, dev=dev)
1206
1207 - def getBrlMissingCellCount(self, sem=None, layer=None, dev=None):
1208 ''' 1209 Gets the number of missing/broken cells defined by the 1210 "missing cell string" user setting. 1211 1212 @param sem: The semantic stream on which to send output; defaults to None 1213 for the default semantic. 1214 @type sem: integer 1215 @param layer: Layer on which the event occurred 1216 @type layer: integer 1217 @param dev: Device that should receive the command 1218 @type dev: L{AEOutput} 1219 @return: Number of missing/broken cells 1220 @rtype: integer 1221 ''' 1222 return self.send(AEConstants.CMD_GET_MISSINGCELL_COUNT, None, sem=sem, \ 1223 layer=layer, dev=dev)
1224
1225 - def setMagGoto(self, value, sem=None, layer=None, dev=None):
1226 ''' 1227 Sets the viewport of the magnifier 1228 1229 @param value: viewport settings in the form (x1, y1, x2, y2) 1230 @type value: tuple 1231 @param sem: The semantic stream on which to send output; defaults to None 1232 for the default semantic. 1233 @type sem: integer 1234 @param layer: Layer on which the event occurred 1235 @type layer: integer 1236 @param dev: Device that should receive the command 1237 @type dev: L{AEOutput} 1238 ''' 1239 self.send(AEConstants.CMD_GOTO, value, sem=sem, layer=layer, dev=dev)
1240
1241 - def getMagROI(self, sem=None, layer=None, dev=None):
1242 ''' 1243 Get the region of interest from magnifier device 1244 1245 @param sem: The semantic stream on which to send output; defaults to None 1246 for the default semantic. 1247 @type sem: integer 1248 @param layer: Layer on which the event occurred 1249 @type layer: integer 1250 @param dev: Device that should receive the command 1251 @type dev: L{AEOutput} 1252 @return: ROI as a four-item tuple in the form (x1, y1, x2, y2) 1253 @rtype: tuple 1254 ''' 1255 return self.send(AEConstants.CMD_GET_ROI, None, sem=sem, \ 1256 layer=layer, dev=dev)
1257
1258 - def getClosestLang(self, tag, sem=None, layer=None, dev=None):
1259 ''' 1260 Get the closest language supported by the device to the one given by the 1261 IANA tag. See the L{AEOutput.Style.AudioStyle} comment about languages 1262 for help on formatting a proper IANA tag. 1263 1264 @param tag: IANA tag name 1265 @type tag: string 1266 @param sem: Semantic tag indicating the kind of output; defaults to None 1267 for the default semantic. 1268 @type sem: integer 1269 @param layer: Layer on which the event occurred 1270 @type layer: integer 1271 @param dev: Device that should receive the command 1272 @type dev: L{AEOutput} 1273 @return: IANA tag name closest to the one given or None meaning no 1274 supported language makes sense 1275 @rtype: string 1276 ''' 1277 return self.send(AEConstants.CMD_GET_CLOSEST_LANG, tag, sem=sem, \ 1278 layer=layer, dev=dev)
1279