Package Adapters :: Package ATSPI :: Module PopupAdapter
[hide private]
[frames] | no frames]

Source Code for Module Adapters.ATSPI.PopupAdapter

  1  ''' 
  2  Defines an L{AccAdapt.Adapter}s for the L{AEInterfaces.IAccessibleInfo}  
  3  interface to correct for the problem of pop-up items (e.g menus) always having 
  4  states visible and showing after having been activated once.  
  5   
  6  @author: Peter Parente 
  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   
 17  from DefaultInfo import * 
 18  from DefaultEventHandler import * 
 19  from AEInterfaces import * 
 20  from pyLinAcc import Constants, Interfaces 
 21  import pyLinAcc 
 22   
 62   
63 -class PopupMenuEventHandlerAdapter(DefaultEventHandlerAdapter):
64 ''' 65 Overrides L{DefaultEventHandlerAdapter} to avoid generating focus events on 66 selection. Expects the subject to be a raw L{pyLinAcc.Accessible}. 67 68 Adapts accessibles with ROLE_MENU. 69 ''' 70 provides = [IEventHandler] 71 72 @staticmethod
73 - def when(subject):
74 ''' 75 Tests if the given subject can be adapted by this class. 76 77 @param subject: L{POR} containing an accessible to test 78 @type subject: L{POR} 79 @return: True when the subject meets the condition named in the docstring 80 for this class, False otherwise 81 @rtype: boolean 82 ''' 83 c = Constants 84 return subject.getRole() == c.ROLE_MENU
85
86 - def _handleFocusEvent(self, event, **kwargs):
87 ''' 88 Creates an L{AEEvent.FocusChange} indicating that the accessible being 89 adapted has gained the focus. Also creates a L{AEEvent.SelectorChange}. 90 These two L{AEEvent}s will be posted by the caller. 91 92 @param event: Raw focus change event 93 @type event: L{pyLinAcc.Event.Event} 94 @param kwargs: Parameters to be passed to any created L{AEEvent} 95 @type kwargs: dictionary 96 @return: L{AEEvent.FocusChange} and L{AEEvent.SelectorChange} 97 @rtype: tuple of L{AEEvent} 98 ''' 99 kwargs['focused'] = True 100 try: 101 sel = Interfaces.ISelection(self.subject) 102 count = sel.nSelectedChildren 103 except NotImplementedError: 104 count = 0 105 if count == 0: 106 por = POR(self.subject, None, 0) 107 # adapt the accessible to an adapter which provides an IAccesssibleInfo 108 # interface and get the accessible's item text 109 item = IAccessibleInfo(por).getAccItemText() 110 return (FocusChange(por, True, **kwargs), 111 SelectorChange(por, item, **kwargs))
112