Package Task :: Module CyclicInputTask
[hide private]
[frames] | no frames]

Source Code for Module Task.CyclicInputTask

 1  ''' 
 2  Defines a L{Task} to execute a sequence of  a L{AEEvent.InputGesture} occurs. 
 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 InputTask, Base 
15   
16 -class CyclicInputTask(InputTask.InputTask):
17 ''' 18 Executes when an input gesture occurs. In turn, this task will execute the 19 next named L{Task.InputTask}s stored in this object. 20 21 Unlike other L{Task} classes, this one is unlikely to be subclassed. The 22 common use is to instantiate it directly with names of other input tasks 23 and bind it to an input command. 24 25 This class registers its name and whether it should be monitored by default 26 in an L{AEMonitor} using the L{Base.registerTaskType} function when this 27 module is first imported. The L{AEMonitor} can use this information to build 28 its menus. 29 ''' 30 Base.registerTaskType('CyclicInputTask', False) 31
32 - def __init__(self, ident, *names):
33 ''' 34 Stores a sequence of named L{InputTask}s to execute. 35 36 @param ident: Programmatic identifier 37 @type ident: string 38 @param names: Names of L{Task}s that should be executed 39 @type names: list of string 40 ''' 41 InputTask.InputTask.__init__(self, ident) 42 self.names = names
43
44 - def execute(self, cycle_count, layer, **kwargs):
45 ''' 46 Executes the next named L{Task} in the cycle in response to an input 47 gesture. Called by L{Tier.Tier._executeTask}. 48 49 @param cycle_count: Task index in sequence to execute 50 @type cycle_count: integer 51 @param layer: Layer on which the event occurred, ignored here but pulled 52 out of kwargs so kwargs can be passed directly to L{doTask} 53 @type layer: integer 54 @param kwargs: Dictionary containing parameters passed to a task. 55 @type kwargs: dictionary 56 @return: Should processing continue? Defaults to the return value from the 57 invoked L{Task}. 58 @rtype: boolean 59 ''' 60 if not len(self.names): 61 # do nothing if no tasks to cycle 62 return 63 i = cycle_count % len(self.names) 64 return self.doTask(self.names[i], **kwargs)
65
66 - def update(self, cycle_count, layer, **kwargs):
67 ''' 68 Executes the next named L{Task} in the cycle in response to an input 69 gesture. Called by L{Tier.Tier._executeTask}. 70 71 @param cycle_count: Task index in sequence to execute 72 @type cycle_count: integer 73 @param layer: Layer on which the event occurred, ignored here but pulled 74 out of kwargs so kwargs can be passed directly to L{doTask} 75 @type layer: integer 76 @param kwargs: Dictionary containing parameters passed to a task. 77 @type kwargs: dictionary 78 @return: Should processing continue? Defaults to the return value from the 79 invoked L{Task}. 80 @rtype: boolean 81 ''' 82 if not len(self.names): 83 # do nothing if no tasks to cycle 84 return 85 i = cycle_count % len(self.names) 86 return self.doTask(self.names[i], propagate=False, **kwargs)
87