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

Source Code for Module Task.MouseTask

  1  ''' 
  2  Defines a L{Task} to execute when the mouse pointer moves or a mouse button 
  3  changes state. 
  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   
 16  import Base, EventTask, AEConstants 
 17  import AEEvent 
 18   
19 -class MouseTask(EventTask.EventTask):
20 ''' 21 Executed when a mouse moves or mouse buttons are pressed. 22 23 This class registers its name and whether it should be monitored by default 24 in an L{AEMonitor} using the L{Base.registerTaskType} function when this 25 module is first imported. The L{AEMonitor} can use this information to build 26 its menus. 27 ''' 28 Base.registerTaskType('MouseTask', False) 29
30 - def getEventType(self):
31 ''' 32 @return: Type of L{AEEvent} this L{Task} wants to handle 33 @rtype: class 34 ''' 35 return AEEvent.MouseChange
36
37 - def update(self, kind, button, pos, **kwargs):
38 ''' 39 Updates this L{Task} in response to a consumed mouse event. Called by 40 L{Tier.Tier._executeTask}. 41 42 @param kind: Kind of event 43 @type kind: integer 44 @param pos: Absolute position of the mouse pointer 45 @type pos: 2-tuple of integer 46 @param button: Number of the button pressed 47 @type button: integer 48 ''' 49 pass
50
51 - def execute(self, kind, pos, button, **kwargs):
52 ''' 53 Executes this L{Task} in response to a mouse event. Called by 54 L{Tier.Tier._executeTask}. 55 56 @param kind: Kind of event 57 @type kind: integer 58 @param pos: Absolute position of the mouse pointer 59 @type pos: 2-tuple of integer 60 @param button: Number of the button pressed or released 61 @type button: integer 62 @return: True to allow other L{Task}s to process this event 63 @rtype: boolean 64 ''' 65 if kind == AEConstants.EVENT_MOUSE_MOVE: 66 return self.executeMoved(pos=pos, **kwargs) 67 elif kind == AEConstants.EVENT_MOUSE_PRESS: 68 return self.executePressed(button=button, **kwargs) 69 else: 70 return self.executeReleased(button=button, **kwargs)
71
72 - def executeMoved(self, pos, **kwargs):
73 ''' 74 Executes this L{Task} in response to a mouse movement. 75 76 @param pos: Absolute position of the mouse pointer 77 @type pos: 2-tuple of integer 78 @return: True to allow other L{Task}s to process this event 79 @rtype: boolean 80 ''' 81 return True
82
83 - def executePressed(self, button, **kwargs):
84 ''' 85 Executes this L{Task} in response to a mouse button press. 86 87 @param button: Number of the button pressed 88 @type button: integer 89 @return: True to allow other L{Task}s to process this event 90 @rtype: boolean 91 ''' 92 return True
93
94 - def executeReleased(self, button, **kwargs):
95 ''' 96 Executes this L{Task} in response to a mouse button release. 97 98 @param button: Number of the button released 99 @type button: integer 100 @return: True to allow other L{Task}s to process this event 101 @rtype: boolean 102 ''' 103 return True
104