Module Perk :: Class Perk
[hide private]
[frames] | no frames]

Class Perk

source code

               object --+            
                        |            
Task.Tools.Base.TaskTools --+        
                            |        
     Task.Tools.Output.Output --+    
                                |    
               object --+       |    
                        |       |    
Task.Tools.Base.TaskTools --+   |    
                            |   |    
       Task.Tools.Input.Input --+    
                                |    
               object --+       |    
                        |       |    
Task.Tools.Base.TaskTools --+   |    
                            |   |    
         Task.Tools.View.View --+    
                                |    
               object --+       |    
                        |       |    
Task.Tools.Base.TaskTools --+   |    
                            |   |    
       Task.Tools.Utils.Utils --+    
                                |    
               object --+       |    
                        |       |    
Task.Tools.Base.TaskTools --+   |    
                            |   |    
     Task.Tools.System.System --+    
                                |    
                   Task.Tools.All --+
                                    |
                       object --+   |
                                |   |
                    UIElement.UIE --+
                                    |
                                   Perk

Registers and maintains a collection of Tasks that will execute in response to AccessEngine events and commands (AEEvents and AEInput.Gestures.). This class should be sublclassed by Perk developers who wish to define, modify, or extend the LSR user interface. This class derives from Task.Tools.All to allow the use of the convenience methods defined in that class during Perk intialization.

Instance Methods [hide private]
 
__init__(self, *args, **kwargs)
Creates empty dictionaries for named, event, command, and chooser Tasks.
source code
boolean
preInit(self, ae, *args, **kwargs)
Overrides pre-initialization to load persisted state from disk.
source code
 
postClose(self)
Frees all Tasks managed by this Perk.
source code
 
setIdealOutput(self, *capabilities)
Sets the ideal device capabilities to be used to locate a device for all output methods invoked from the caller's Perk module, including the Perk class itself and all of its registered Tasks.
source code
list of string
getIdealOutput(self)
Gets the ideal device capabilities to locate a device to be used by all output methods invoked from the caller's Perk module, including the Perk class itself and all of its registered Tasks.
source code
AEState.AEState
getState(self)
Returns: Returns the settings for this Perk or a dummy object that can be used to store state information that is neither user configurable or persistable
source code
 
_initTask(self, task)
Initializes a Task by calling Task.Base.Task.preInit and Task.Base.Task.init if it has not already been initialized.
source code
 
registerTimerTask(self, task, interval)
Registers a Task to be called on a set interval.
source code
 
registerCommandTask(self, device, codes, name, propagate=False)
Registers a Task in this Tier to be executed in response to an AEEvent indicating that the given action codes were input on the given AEInput device.
source code
 
registerChooserTask(self, chooser, task)
Registers a Task with the given name to be executed in response to a change in the given AEChooser.
source code
 
registerNamedTask(self, task, name)
Registers a new Task under the given name if no Task is already registered with that name in this Tier.
source code
 
registerEventTask(self, task, focus=False, tier=False, background=False)
Registers a new Task in this Perk under the Task type.
source code
 
unregisterTimerTask(self, task)
Unregisters a Task from being called on a set interval.
source code
 
unregisterCommandTask(self, device, codes)
Unregisters a Task set to execute in response to the given action codes on the given device from this Perk only.
source code
 
unregisterChooserTask(self, chooser)
Unregisters a Task so it is no longer executed in response to a change in the given AEChooser.
source code
 
unregisterNamedTask(self, name)
Unregisters a named Task from this Perk only.
source code
 
unregisterEventTask(self, task, focus=False, tier=False, background=False)
Unregisters the given Task instance from this Perk only.
source code
string
getCommandTask(self, gesture_list)
Gets the Task registered in this Perk only to execute in response to the given AEInput.GestureList.
source code
Task.ChooserTask.ChooserTask
getKeyedTask(self, key)
Gets a Task registered under a particular key set to execute in response to events.
source code
Task.Base.Task
getNamedTask(self, name)
Gets the Task with the given name if it is registered in this Perk only.
source code
list of Task.Base.Task
getEventTasks(self, event_type, task_layer)
Get all registered Tasks registered to handle the given AEEvent type in this Perk only.
source code
list of string
getChainSegment(self, target, link)
Gets a copy of the segment of the Task chain for target specified by the link type.
source code
string
mergeChain(self, target, before, after)
Adds the before and after segments of the chain for the target specified.
source code
 
linkTaskToChain(self, name, link, target)
Links a Task to the one named in target.
source code
 
unlinkTaskFromChain(self, name, link, target)
Unlinks a Task from the one named in target.
source code
list of string
getTaskNames(self)
Gets the names of all Tasks registered in this Perk.
source code
 
unregisterModifiers(self, dev, modifiers)
Unregisters a list of input modifiers.
source code
 
registerModifiers(self, dev, modifiers)
Registers a list of input modifiers.
source code

Inherited from Task.Tools.Output.Output: getBrlEllipsisSizes, getBrlMissingCellCount, getClosestLang, getMagROI, getOutputDevice, getPerkIdealOutput, getStyle, getStyleSetting, getStyleVal, inhibitMayStop, mayStop, play, say, sayApp, sayChar, sayColor, sayConfirm, sayCount, sayDesc, sayError, sayFont, sayHotkey, sayIndex, sayInfo, sayItem, sayLabel, sayLevel, sayName, sayRole, saySection, sayState, sayStatus, sayTextAttrs, sayValue, sayValueExtents, sayWindow, sayWord, send, setBrlCaretPosition, setBrlTruncate, setMagGoto, setPerkIdealOutput, setStyleVal, stopAll, stopNow

Inherited from Task.Tools.Input.Input: addInputModifiers, getInputDevice, registerCommand, removeInputModifiers, unregisterCommand

Inherited from Task.Tools.View.View: compareAncestorRoles, copyAccText, cutAccText, deleteAccText, deselectAccText, doAction, findAccByName, findAccByObjId, findAccByPredicate, findAccByRole, getAccActionDescs, getAccActionKeys, getAccActionNames, getAccAllTextAttrs, getAccAnchorCount, getAccAppLocale, getAccAtRowColumn, getAccAttrs, getAccCaret, getAccClickKey, getAccColumn, getAccColumnHeader, getAccCount, getAccDefTextAttrs, getAccDesc, getAccFloatValue, getAccFloatValueExtents, getAccFocus, getAccFromPath, getAccIndex, getAccLabel, getAccLevel, getAccName, getAccPosInSet, getAccPosition, getAccRelations, getAccRole, getAccRoleName, getAccRow, getAccRowHeader, getAccSetSize, getAccTableExtents, getAccText, getAccTextAttr, getAccTextBetween, getAccTextLength, getAccTextSelection, getAccTextSelectionCount, getAccURI, getAccVisualExtents, getAccVisualPoint, getAllSelected, getAppName, getCharText, getChildAcc, getCurrItem, getCurrRow, getCurrWord, getEndAcc, getEndOfHardLine, getFirstPeerAcc, getFirstSelected, getItemText, getLastAccUnder, getLastChar, getLastKey, getLastPeerAcc, getLastWord, getNextAcc, getNextChar, getNextItem, getNextPeerAcc, getNextRow, getNextWord, getParentAcc, getPointerPOR, getPrevAcc, getPrevChar, getPrevItem, getPrevPeerAcc, getPrevRow, getPrevWord, getRootAcc, getStartOfHardLine, getStateText, getViewRootAcc, getWindowTitle, getWordText, hasAccRole, hasAccState, hasOneAccRole, hasOneAccState, inhibitAutoPointer, insertAccText, iterAncestorAccs, iterNextAccs, iterNextItems, iterPrevAccs, iterPrevItems, leftClickPOR, mouseEventPOR, moveToEnd, moveToItemStart, moveToPOR, moveToPointer, moveToRoot, pasteAccText, selectAccText, setAccCaret, setAccDeselected, setAccFocus, setAccPOR, setAccSelected, setAccText, setAccTextAttrs, setAllDeselected, setAllSelected, setPointerPOR

Inherited from Task.Tools.Utils.Utils: convertPOSIXToIANA, getColorString

Inherited from Task.Tools.System.System: associateDevice, associateMonitor, associatePerk, blockNTasks, chainTask, disassociateDevice, disassociateMonitor, disassociatePerk, doTask, getAnchorPerkClassName, getAnchorTaskId, getChooserClassNames, getChooserDescriptions, getChooserMetadata, getChooserNames, getDeviceClassNames, getDeviceDescriptions, getDeviceMetadata, getDeviceNames, getDeviceState, getHistory, getMonitorClassNames, getMonitorDescriptions, getMonitorMetadata, getMonitorNames, getPerkByName, getPerkClassNames, getPerkDescriptions, getPerkHistory, getPerkMetadata, getPerkNames, getPerkSetting, getPerkSettingVal, getPerkState, getPerkTaskNames, getPerkVar, getProfileName, getTaskHistory, getTempVal, getTierEventTasks, getTierNamedTask, getTierTaskNames, insertPerk, loadAllMonitors, loadChooser, loadMonitor, popPerk, popThisPerk, pushPerk, refreshDevices, registerConstants, registerTask, reloadPerks, setPerkSettingVal, setPerkVar, setTempVal, unchainTask, unloadAllMonitors, unloadChooser, unloadMonitor, unregisterTask

Inherited from Task.Tools.Base.TaskTools: close, init, postExecute, preExecute

Inherited from UIElement.UIE: getClassName, getDescription, getName, getPath

Inherited from object: __delattr__, __getattribute__, __hash__, __new__, __reduce__, __reduce_ex__, __repr__, __setattr__, __str__

Class Variables [hide private]
AEState.AEState class STATE = PerkState
Class to instantiate and use to store state information across all instances of this Perk.

Inherited from Task.Tools.Output.Output: may_stop

Inherited from Task.Tools.View.View (private): _state_descriptions

Instance Variables [hide private]
dictionary of {string : list of string} after_chains
Mapping from target Task name to a list of Task names which should be executed after the target
dictionary of {string : list of string} around_chains
Mapping from target Task name to one Task name which should be executed instead of the target
dictionary of {string : list of string} before_chains
Mapping from target Task name to a list of Task names which should be executed before the target
weakref.WeakValueDictionary of (GestureList : string) commands
Name of a Task to execute in response to a AEInput.GestureList sequence on some AEInput device.
dictionary of (Task subclass : list of Task instance) event_tasks
Tasks registered by type
dictionary integer : Task instance keyed_tasks
Tasks registered by unique integer ID
dictionary string : Task instance named_tasks
Tasks registered by name
list of string out_caps
Capabilities set by setIdealOutput as ideal for output from this Perk.
weakref.WeakKeyDictionary registered_modifiers
Mapping from device to a registered modifier for that device
PerkState state
Settings for this Perk.
Properties [hide private]

Inherited from object: __class__

Method Details [hide private]

__init__(self, *args, **kwargs)
(Constructor)

source code 

Creates empty dictionaries for named, event, command, and chooser Tasks. Create a state object for storage using the class in STATE in case the Perk hasn't previously persisted its settings on disk.

Overrides: Task.Tools.Base.TaskTools.__init__

Note: Perk writers should override init to do initialization, not this method.

preInit(self, ae, *args, **kwargs)

source code 

Overrides pre-initialization to load persisted state from disk. Fetches the managers from the AccessEngine first so that state can be loaded using the SettingsManager. Loads the state, then invokes the super class version of this method to finish initialization.

Parameters:
  • ae (AccessEngine) - Reference to AccessEngine for event context
Returns: boolean
Did the TaskTools initialize (True) or not (False)?
Overrides: Task.Tools.Base.TaskTools.preInit

Note: Perk writers should override init to do initialization, not this method.

postClose(self)

source code 

Frees all Tasks managed by this Perk.

Overrides: Task.Tools.Base.TaskTools.postClose

Note: Perk writers should override close to do finialization, not this method.

setIdealOutput(self, *capabilities)

source code 

Sets the ideal device capabilities to be used to locate a device for all output methods invoked from the caller's Perk module, including the Perk class itself and all of its registered Tasks. The capabilities list should include strings naming AEOutput interfaces ("audio" and/or "braille") at present.

Parameters:
  • capabilities (list of string) - Names of capabilities required on the device

getIdealOutput(self)

source code 

Gets the ideal device capabilities to locate a device to be used by all output methods invoked from the caller's Perk module, including the Perk class itself and all of its registered Tasks.

Returns: list of string
Names of capabilities set as ideal for a default output device

getState(self)

source code 
Returns: AEState.AEState
Returns the settings for this Perk or a dummy object that can be used to store state information that is neither user configurable or persistable

_initTask(self, task)

source code 

Initializes a Task by calling Task.Base.Task.preInit and Task.Base.Task.init if it has not already been initialized.

Parameters:

registerTimerTask(self, task, interval)

source code 

Registers a Task to be called on a set interval.

Parameters:
  • interval (integer) - Interval in seconds which the Task will be notified

registerCommandTask(self, device, codes, name, propagate=False)

source code 

Registers a Task in this Tier to be executed in response to an AEEvent indicating that the given action codes were input on the given AEInput device.

Parameters:
  • device (AEInput) - Input device to monitor
  • codes (list of list of integer) - List of lists of action codes forming the AEInput.Gesture that will trigger the execution of the named Task. For example, codes=[[Keyboard.AEK_CTRL, Keyboard.AEK_TILDE]] indicates the single gesture of simultaneously pressing Ctrl and ~ on the keyboard device.
  • name (string) - Name of the Task registered via registerNamedTask to execute when the input gesture is detected on the device
  • propagate (boolean) - Should the input gesture be allowed to propagate to the OS after we receive it?
Raises:
  • ValueError - When a Task with the given name is not registered

registerChooserTask(self, chooser, task)

source code 

Registers a Task with the given name to be executed in response to a change in the given AEChooser.

Parameters:

registerNamedTask(self, task, name)

source code 

Registers a new Task under the given name if no Task is already registered with that name in this Tier.

Only one Task can be registered under a name in a Tier. If a Task is already registered under the given name, any other registration with that name is ignored.

Parameters:
Raises:
  • ValueError - When a Task with the given name is already registered in this Tier

registerEventTask(self, task, focus=False, tier=False, background=False)

source code 

Registers a new Task in this Perk under the Task type. The type determines which kind of AEEvent will trigger the execution of the registered Task. If one or more Tasks are already registered for this type, the given Task will be inserted at the top of the registered stack of Tasks (i.e. it will be executed first for the appropriate event).

The focus, tier, and background parameters specify on which layer the Task will handle events. If focus is True, the Task will be executed in response to an event from a focused control within this Tier. If tier is True, the Task will be executed in response to an event from an unfocused control within this Tier. If background is True, the Task will be executed in response to an event from any control within the tier when the Tier is not active.

The three layers are mutually exclusive. You may set any combination of focus, tier, and background to True to register the given task on each selected layer in one call. If all three parameters are False, the registration defaults to the focus layer.

The Task passed to this method must implement the interface defined by Task.EventTask.

Parameters:
  • task (Task.Base.Task) - Task to register
  • focus (boolean) - Should this Task handle events from focused accessibles in this Tier?
  • tier (boolean) - Should this Task handle events from unfocused accessibles in this Tier?
  • background (boolean) - Should this Task handle events from any accessible in this Tier when the Tier is inactive?
Raises:

unregisterTimerTask(self, task)

source code 

Unregisters a Task from being called on a set interval.

Parameters:
Raises:
  • KeyError - When the Task is not registered

unregisterCommandTask(self, device, codes)

source code 

Unregisters a Task set to execute in response to the given action codes on the given device from this Perk only.

Parameters:
  • device (AEInput) - Input device to monitor
  • codes (list of list of integer) - List of lists of action codes forming the AEInput.Gesture that will trigger the execution of the named Task. For example, codes=[[Keyboard.AEK_CTRL, Keyboard.AEK_TILDE]] indicates the single gesture of simultaneously pressing Ctrl and ~ on the keyboard device.
Raises:

unregisterChooserTask(self, chooser)

source code 

Unregisters a Task so it is no longer executed in response to a change in the given AEChooser.

Parameters:
  • chooser (AEChooser) - Chooser that the Task should no longer observe
Raises:
  • KeyError - When the given AEChooser is not registered

unregisterNamedTask(self, name)

source code 

Unregisters a named Task from this Perk only. If a Task with the given name is not found in this Perk, an exception is raised.

Parameters:
  • name (string) - Name of the Task to unregister
Raises:
  • KeyError - When a Task with the given name is not registered

unregisterEventTask(self, task, focus=False, tier=False, background=False)

source code 

Unregisters the given Task instance from this Perk only. If the given Task instance was not registered for an event in this Perk, an exception is raised. The focus, tier, and background parameters state from which layer(s) this Task should be unregistered.

The Task passed to this method must implement the interface defined by Task.EventTask.

Parameters:
Raises:
  • KeyError - When there are no Tasks registered with the type of the given Task
  • ValueError - When the given Task is not registered on one of the specified layers
  • AttributeError - When the Task does not implement Task.EventTask
  • NotImplementedError - When the Task does not properly subclass Task.EventTask

See Also: registerEventTask

getCommandTask(self, gesture_list)

source code 

Gets the Task registered in this Perk only to execute in response to the given AEInput.GestureList.

Called by Tier.Tier.getCommandTask during a search through all Perks in the owning Tier for the given key list.

Parameters:
Returns: string
Name of the Task set to execute in response to the input gesture or None

getKeyedTask(self, key)

source code 

Gets a Task registered under a particular key set to execute in response to events. None is returned if not found.

Called by Tier.Tier.getKeyedTask during a search through all Perks in the owning Tier for the given AEChooser.

Parameters:
  • key (integer) - Unique key identifying this Task
Returns: Task.ChooserTask.ChooserTask
Task set to execute in response to the chooser or None

getNamedTask(self, name)

source code 

Gets the Task with the given name if it is registered in this Perk only. If no Task is registered under the given name in this Perk, returns None.

Called by Tier.Tier.getNamedTask during a search through all Perks in the owning Tier for the given name.

Parameters:
  • name (string) - Name of the Task to locate
Returns: Task.Base.Task
Task with the given name or None
Overrides: Task.Tools.System.System.getNamedTask

getEventTasks(self, event_type, task_layer)

source code 

Get all registered Tasks registered to handle the given AEEvent type in this Perk only. Makes a copy of the list of tasks such that registering or unregistering Tasks does not affect the list gotten by this method.

Called by Tier.Tier.getEventTasks during a search through all Perks in the owning Tier for the given task type.

Parameters:
  • event_type (AEEvent class) - Desired type of AEEvent
  • task_layer (integer) - Layer on which the desired Tasks are registered
Returns: list of Task.Base.Task
List of all Tasks that handle the given event type on the given layer in this Perk
Overrides: Task.Tools.System.System.getEventTasks

getChainSegment(self, target, link)

source code 

Gets a copy of the segment of the Task chain for target specified by the link type. A copy is returned to avoid iteration errors if the list changes size during execution of the Tasks in the chain.

Parameters:
  • target (string) - Name of the Task to link to
  • link (integer) - One of the CHAIN constants in AEConstants.Tools
Returns: list of string
Task names chained in the given manner

mergeChain(self, target, before, after)

source code 

Adds the before and after segments of the chain for the target specified. The parameters before and after are lists, possibly containing segments from other Perks. These lists are modified in place for performance. The around segment is returned since it is a single value.

Parameters:
  • target (string) - Name of the Task to link to
Returns: string
Task name for around link type, or None if nothing is linked around the target

linkTaskToChain(self, name, link, target)

source code 

Links a Task to the one named in target. The Task will be added either before, after, or around depending on the value of link. Does not allow a Task to link to itself (i.e. name cannot equal target).

Invokes Tier.Tier.addChainRef to add a reference to this Perk to the Tier which will later have to traverse the chain across Perks.

Parameters:
  • name (string) - Name of the Task to link
  • link (integer) - One of the CHAIN constants in AEConstants.Tools
  • target (string) - Name of the Task to link to
Raises:
  • ValueError - When the link type is unknown
  • AssertionError - When the name equals the target

unlinkTaskFromChain(self, name, link, target)

source code 

Unlinks a Task from the one named in target. The Task will be unlinked either before, after, or around depending on the value of link. If link is None, the Task will be unlinked from all cases if possible.

Invokes Tier.Tier.removeChainRef to delete a reference to this Perk to the Tier which will later have to traverse the chain across Perks.

Parameters:
  • name (string) - Name of the Task to link
  • link (integer) - One of the CHAIN constants in AEConstants.Tools
  • target (string) - Name of the Task to unlink from
Raises:
  • ValueError - When the named Task is not unlinked at least once or the link type is unknown
  • KeyError - When the target Task does not have a chain segement in this Perk for the given link type

getTaskNames(self)

source code 

Gets the names of all Tasks registered in this Perk.

Returns: list of string
All names

unregisterModifiers(self, dev, modifiers)

source code 

Unregisters a list of input modifiers. Ignores the error cases when the device has no registered modifiers or one of the given modifiers is not registered.

Parameters:
  • dev (AEInput) - An AEInput device.
  • modifiers (integer) - A list of key codes used as modifiers.

registerModifiers(self, dev, modifiers)

source code 

Registers a list of input modifiers.

Parameters:
  • dev (AEInput) - An AEInput device.
  • modifiers (integer) - A list of key codes used as modifiers.

Class Variable Details [hide private]

STATE

Class to instantiate and use to store state information across all instances of this Perk. Defaults to the AEState base class, but can be overridden with a subclass of AEState.
Type:
AEState.AEState class
Value:
PerkState

Instance Variable Details [hide private]

commands

Name of a Task to execute in response to a AEInput.GestureList sequence on some AEInput device. The name should be hashed into the named_tasks dictionary to fully resolve the Task.
Type:
weakref.WeakValueDictionary of (GestureList : string)

out_caps

Capabilities set by setIdealOutput as ideal for output from this Perk. These are used to "late bind" a device for use during execution of this Perk and its Tasks. Defaults to audio.
Type:
list of string

state

Settings for this Perk. Defaults to an empty PerkState object that can be used to store state information that is not configurable or persistable unless STATE is specified.
Type:
PerkState