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

Source Code for Module AccessEngine.AEAccAdapters.ATSPI.PopupAdapter

  1  ''' 
  2  Defines an L{AEAccAdapter.AEAccAdapter}s for the L{AEAccInterfaces.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  @author: Frank Zenker 
 12  @organization: IT Science Center Ruegen gGmbH, Germany 
 13  @copyright: Copyright (c) 2007, 2008 ITSC Ruegen 
 14  @license: The BSD License 
 15   
 16  All rights reserved. This program and the accompanying materials are made 
 17  available under the terms of the BSD license which accompanies 
 18  this distribution, and is available at 
 19  U{http://www.opensource.org/licenses/bsd-license.php} 
 20  ''' 
 21   
 22  from DefaultInfo import * 
 23  from DefaultEventHandler import * 
 24  from AccessEngine.AEAccInterfaces import * 
 25  from AccessEngine.AEPor import AEPor 
 26  import pyatspi 
 27   
 66   
67 -class PopupMenuEventHandlerAdapter(DefaultEventHandlerAdapter):
68 ''' 69 Overrides L{DefaultEventHandlerAdapter} to avoid generating focus events on 70 selection. Expects the subject to be a raw C{pyatspi.Accessibility.Accessible}. 71 72 Adapts accessibles with ROLE_MENU. 73 ''' 74 provides = [IEventHandler] 75 76 @staticmethod
77 - def when(subject):
78 ''' 79 Tests if the given subject can be adapted by this class. 80 81 @param subject: L{AEPor} containing an accessible to test 82 @type subject: L{AEPor} 83 @return: True when the subject meets the condition named in the docstring 84 for this class, False otherwise 85 @rtype: boolean 86 ''' 87 return subject.getRole() == pyatspi.ROLE_MENU
88
89 - def _handleFocusEvent(self, event, **kwargs):
90 ''' 91 Creates an L{AEEvent.FocusChange} indicating that the accessible being 92 adapted has gained the focus. Also creates a L{AEEvent.SelectorChange}. 93 These two L{AEEvent}s will be posted by the caller. 94 95 @param event: Raw focus change event 96 @type event: C{pyatspi.event.Event} 97 @param kwargs: Parameters to be passed to any created L{AEEvent} 98 @type kwargs: dictionary 99 @return: L{AEEvent.FocusChange} and L{AEEvent.SelectorChange} 100 @rtype: tuple of L{AEEvent} 101 ''' 102 kwargs['focused'] = True 103 try: 104 sel = (self.subject).querySelection() 105 count = sel.nSelectedChildren 106 except NotImplementedError: 107 count = 0 108 if count == 0: 109 por = AEPor(self.subject, None, 0) 110 # adapt the accessible to an adapter which provides an IAccesssibleInfo 111 # interface and get the accessible's item text 112 item = IAccessibleInfo(por).getAccItemText() 113 return (FocusChange(por, True, **kwargs), 114 SelectorChange(por, item, **kwargs))
115