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

Source Code for Module Task.ChooserTask

 1  ''' 
 2  Defines a L{Task} to execute when a L{AEEvent.InputGesture} occurs in order to 
 3  start an L{AEChooser} dialog with the user. 
 4   
 5  @author: Peter Parente 
 6  @organization: IBM Corporation 
 7  @copyright: Copyright (c) 2005, 2007 IBM Corporation 
 8  @license: The BSD License 
 9   
10  All rights reserved. This program and the accompanying materials are made  
11  available under the terms of the BSD license which accompanies 
12  this distribution, and is available at 
13  U{http://www.opensource.org/licenses/bsd-license.php} 
14  ''' 
15  import Base, InputTask 
16   
17 -class ChooserTask(InputTask.InputTask):
18 ''' 19 Executes when an input gesture occurs or a chooser changes state. 20 21 This class registers its name and whether it should be monitored by default 22 in an L{AEMonitor} using the L{Base.registerTaskType} function when this 23 module is first imported. The L{AEMonitor} can use this information to build 24 its menus. 25 ''' 26 Base.registerTaskType('ChooserTask', False) 27
28 - def execute(self, chooser=None, kind=None, **kwargs):
29 ''' 30 Executes this L{Task} in response to some change in a L{AEChooser}, 31 starting it, ending it, or applying its current options. Called by 32 L{Tier.Tier._executeTask}. 33 34 @param chooser: Chooser that fired the event 35 @type chooser: L{AEChooser} 36 @param kind: Kind of signal, APPLY, OK, or CANCEL or an arbitrary 37 constant provided by the L{AEChooser} 38 @type kind: integer 39 @return: Should processing continue? Always returns True by default. 40 @rtype: boolean 41 ''' 42 if chooser is None: 43 return self.executeStart(**kwargs) 44 elif kind in (chooser.OK, chooser.CANCEL): 45 # call signal then end 46 # return the AND of the return values 47 update = self.executeSignal(chooser=chooser, kind=kind, **kwargs) 48 end = self.executeEnd(chooser=chooser, kind=kind, **kwargs) 49 return end and update 50 else: 51 # call signal 52 return self.executeSignal(chooser=chooser, kind=kind, **kwargs)
53
54 - def executeStart(self, **kwargs):
55 ''' 56 Executes this L{Task} to start a new L{AEChooser}, typically in response 57 to input on an L{AEInput} device. Called by L{Tier.Tier._executeTask}. 58 59 @return: Should processing continue? Always returns True by default. 60 @rtype: boolean 61 ''' 62 return True
63
64 - def executeSignal(self, chooser, kind, **kwargs):
65 ''' 66 Executes this L{Task} in response to a chooser request to have its current 67 options immediately applied without its completion. Called by 68 L{Tier.Tier._executeTask}. 69 70 @param chooser: Chooser that fired the event 71 @type chooser: L{AEChooser} 72 @param kind: Kind of signal, APPLY, OK, or CANCEL or an arbitrary 73 constant provided by the L{AEChooser} 74 @type kind: integer 75 @param kwargs: Arbitrary keyword arguments returned by the chooser 76 @type kwargs: dictionary 77 ''' 78 return True
79
80 - def executeEnd(self, chooser, **kwargs):
81 ''' 82 Executes this L{Task} in response to the ending of a chooser dialog. 83 Called by L{Tier.Tier._executeTask}. 84 85 The default implementation calls L{Task.Tools.System.System.unloadChooser} 86 which is the desired behavior for most L{ChooserTask}s. 87 88 @param chooser: Chooser that fired the event 89 @type chooser: L{AEChooser} 90 @param kwargs: Arbitrary keyword arguments returned by the chooser 91 @type kwargs: dictionary 92 ''' 93 self.unloadChooser(chooser) 94 return True
95