home *** CD-ROM | disk | FTP | other *** search
/ Mac Easy 2010 May / Mac Life Ubuntu.iso / casper / filesystem.squashfs / usr / lib / python2.6 / dist-packages / pyatspi / registry.pyc (.txt) < prev    next >
Encoding:
Python Compiled Bytecode  |  2009-04-20  |  29.0 KB  |  844 lines

  1. # Source Generated with Decompyle++
  2. # File: in.pyc (Python 2.6)
  3.  
  4. '''
  5. Registry that hides some of the details of registering for AT-SPI events and
  6. starting and stopping the main program loop.
  7.  
  8. @todo: PP: when to destroy device listener?
  9.  
  10. @author: Peter Parente
  11. @organization: IBM Corporation
  12. @copyright: Copyright (c) 2005, 2007 IBM Corporation
  13. @license: LGPL
  14.  
  15. This library is free software; you can redistribute it and/or
  16. modify it under the terms of the GNU Library General Public
  17. License as published by the Free Software Foundation; either
  18. version 2 of the License, or (at your option) any later version.
  19.  
  20. This library is distributed in the hope that it will be useful,
  21. but WITHOUT ANY WARRANTY; without even the implied warranty of
  22. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
  23. Library General Public License for more details.
  24.  
  25. You should have received a copy of the GNU Library General Public
  26. License along with this library; if not, write to the
  27. Free Software Foundation, Inc., 59 Temple Place - Suite 330,
  28. Boston, MA 02111-1307, USA.
  29.  
  30. Portions of this code originally licensed and copyright (c) 2005, 2007
  31. IBM Corporation under the BSD license, available at
  32. U{http://www.opensource.org/licenses/bsd-license.php}
  33. '''
  34. import signal
  35. import time
  36. import weakref
  37. import Queue
  38. import traceback
  39. import ORBit
  40. import bonobo
  41. import gobject
  42. import Accessibility
  43. import Accessibility__POA
  44. import utils
  45. import constants
  46. import event
  47.  
  48. class _Observer(object):
  49.     '''
  50.   Parent class for all event observers. Dispatches all received events to the 
  51.   L{Registry} that created this L{_Observer}. Provides basic reference counting
  52.   functionality needed by L{Registry} to determine when an L{_Observer} can be
  53.   released for garbage collection. 
  54.   
  55.   The reference counting provided by this class is independent of the reference
  56.   counting used by CORBA. Keeping the counts separate makes it easier for the
  57.   L{Registry} to detect when an L{_Observer} can be freed in the 
  58.   L{Registry._unregisterObserver} method.
  59.   
  60.   @ivar registry: Reference to the L{Registry} that created this L{_Observer}
  61.   @type registry: weakref.proxy to L{Registry}
  62.   @ivar ref_count: Reference count on this L{_Observer}
  63.   @type ref_count: integer
  64.   '''
  65.     
  66.     def __init__(self, registry):
  67.         '''
  68.     Stores a reference to the creating L{Registry}. Intializes the reference
  69.     count on this object to zero.
  70.     
  71.     @param registry: The L{Registry} that created this observer
  72.     @type registry: weakref.proxy to L{Registry}
  73.     '''
  74.         self.registry = weakref.proxy(registry)
  75.         self.ref_count = 0
  76.  
  77.     
  78.     def clientRef(self):
  79.         '''
  80.     Increments the Python reference count on this L{_Observer} by one. This
  81.     method is called when a new client is registered in L{Registry} to receive
  82.     notification of an event type monitored by this L{_Observer}.
  83.     '''
  84.         self.ref_count += 1
  85.  
  86.     
  87.     def clientUnref(self):
  88.         '''    
  89.     Decrements the pyatspi reference count on this L{_Observer} by one. This
  90.     method is called when a client is unregistered in L{Registry} to stop
  91.     receiving notifications of an event type monitored by this L{_Observer}.
  92.     '''
  93.         self.ref_count -= 1
  94.  
  95.     
  96.     def getClientRefCount(self):
  97.         '''
  98.     @return: Current Python reference count on this L{_Observer}
  99.     @rtype: integer
  100.     '''
  101.         return self.ref_count
  102.  
  103.     
  104.     def ref(self):
  105.         '''Required by CORBA. Does nothing.'''
  106.         pass
  107.  
  108.     
  109.     def unref(self):
  110.         '''Required by CORBA. Does nothing.'''
  111.         pass
  112.  
  113.  
  114.  
  115. class _DeviceObserver(_Observer, Accessibility__POA.DeviceEventListener):
  116.     '''
  117.   Observes keyboard press and release events.
  118.   
  119.   @ivar registry: The L{Registry} that created this observer
  120.   @type registry: L{Registry}
  121.   @ivar key_set: Set of keys to monitor
  122.   @type key_set: list of integer
  123.   @ivar mask: Watch for key events while these modifiers are held
  124.   @type mask: integer
  125.   @ivar kind: Kind of events to monitor
  126.   @type kind: integer
  127.   @ivar mode: Keyboard event mode
  128.   @type mode: Accessibility.EventListenerMode
  129.   '''
  130.     
  131.     def __init__(self, registry, synchronous, preemptive, global_):
  132.         '''
  133.     Creates a mode object that defines when key events will be received from 
  134.     the system. Stores all other information for later registration.
  135.     
  136.     @param registry: The L{Registry} that created this observer
  137.     @type registry: L{Registry}
  138.     @param synchronous: Handle the key event synchronously?
  139.     @type synchronous: boolean
  140.     @param preemptive: Allow event to be consumed?
  141.     @type preemptive: boolean
  142.     @param global_: Watch for events on inaccessible applications too?
  143.     @type global_: boolean
  144.     '''
  145.         _Observer.__init__(self, registry)
  146.         self.mode = Accessibility.EventListenerMode()
  147.         self.mode.preemptive = preemptive
  148.         self.mode.synchronous = synchronous
  149.         self.mode._global = global_
  150.  
  151.     
  152.     def register(self, dc, key_set, mask, kind):
  153.         '''
  154.     Starts keyboard event monitoring.
  155.     
  156.     @param dc: Reference to a device controller
  157.     @type dc: Accessibility.DeviceEventController
  158.     @param key_set: Set of keys to monitor
  159.     @type key_set: list of integer
  160.     @param mask: Integer modifier mask or an iterable over multiple masks to
  161.       unapply all at once
  162.     @type mask: integer, iterable, or None
  163.     @param kind: Kind of events to monitor
  164.     @type kind: integer
  165.     '''
  166.         
  167.         try:
  168.             iter(mask)
  169.         except TypeError:
  170.             dc.registerKeystrokeListener(self._this(), key_set, mask, kind, self.mode)
  171.  
  172.         for m in mask:
  173.             dc.registerKeystrokeListener(self._this(), key_set, m, kind, self.mode)
  174.         
  175.  
  176.     
  177.     def unregister(self, dc, key_set, mask, kind):
  178.         '''
  179.     Stops keyboard event monitoring.
  180.     
  181.     @param dc: Reference to a device controller
  182.     @type dc: Accessibility.DeviceEventController
  183.     @param key_set: Set of keys to monitor
  184.     @type key_set: list of integer
  185.     @param mask: Integer modifier mask or an iterable over multiple masks to
  186.       unapply all at once
  187.     @type mask: integer, iterable, or None
  188.     @param kind: Kind of events to monitor
  189.     @type kind: integer
  190.     '''
  191.         
  192.         try:
  193.             iter(mask)
  194.         except TypeError:
  195.             dc.deregisterKeystrokeListener(self._this(), key_set, mask, kind)
  196.  
  197.         for m in mask:
  198.             dc.deregisterKeystrokeListener(self._this(), key_set, m, kind)
  199.         
  200.  
  201.     
  202.     def queryInterface(self, repo_id):
  203.         '''
  204.     Reports that this class only implements the AT-SPI DeviceEventListener 
  205.     interface. Required by AT-SPI.
  206.     
  207.     @param repo_id: Request for an interface 
  208.     @type repo_id: string
  209.     @return: The underlying CORBA object for the device event listener
  210.     @rtype: Accessibility.EventListener
  211.     '''
  212.         if repo_id == utils.getInterfaceIID(Accessibility.DeviceEventListener):
  213.             return self._this()
  214.         return None
  215.  
  216.     
  217.     def notifyEvent(self, ev):
  218.         '''
  219.     Notifies the L{Registry} that an event has occurred. Wraps the raw event 
  220.     object in our L{Event} class to support automatic ref and unref calls. An
  221.     observer can return True to indicate this event should not be allowed to pass 
  222.     to other AT-SPI observers or the underlying application.
  223.     
  224.     @param ev: Keyboard event
  225.     @type ev: Accessibility.DeviceEvent
  226.     @return: Should the event be consumed (True) or allowed to pass on to other
  227.       AT-SPI observers (False)?
  228.     @rtype: boolean
  229.     '''
  230.         ev = event.DeviceEvent(ev)
  231.         return self.registry.handleDeviceEvent(ev, self)
  232.  
  233.  
  234.  
  235. class _EventObserver(_Observer, Accessibility__POA.EventListener):
  236.     '''
  237.   Observes all non-keyboard AT-SPI events. Can be reused across event types.
  238.   '''
  239.     
  240.     def register(self, reg, name):
  241.         '''
  242.     Starts monitoring for the given event.
  243.     
  244.     @param name: Name of the event to start monitoring
  245.     @type name: string
  246.     @param reg: Reference to the raw registry object
  247.     @type reg: Accessibility.Registry
  248.     '''
  249.         reg.registerGlobalEventListener(self._this(), name)
  250.  
  251.     
  252.     def unregister(self, reg, name):
  253.         '''
  254.     Stops monitoring for the given event.
  255.     
  256.     @param name: Name of the event to stop monitoring
  257.     @type name: string
  258.     @param reg: Reference to the raw registry object
  259.     @type reg: Accessibility.Registry
  260.     '''
  261.         reg.deregisterGlobalEventListener(self._this(), name)
  262.  
  263.     
  264.     def queryInterface(self, repo_id):
  265.         '''
  266.     Reports that this class only implements the AT-SPI DeviceEventListener 
  267.     interface. Required by AT-SPI.
  268.  
  269.     @param repo_id: Request for an interface 
  270.     @type repo_id: string
  271.     @return: The underlying CORBA object for the device event listener
  272.     @rtype: Accessibility.EventListener
  273.     '''
  274.         if repo_id == utils.getInterfaceIID(Accessibility.EventListener):
  275.             return self._this()
  276.         return None
  277.  
  278.     
  279.     def notifyEvent(self, ev):
  280.         '''
  281.     Notifies the L{Registry} that an event has occurred. Wraps the raw event 
  282.     object in our L{Event} class to support automatic ref and unref calls.
  283.     Aborts on any exception indicating the event could not be wrapped.
  284.     
  285.     @param ev: AT-SPI event signal (anything but keyboard)
  286.     @type ev: Accessibility.Event
  287.     '''
  288.         ev = event.Event(ev)
  289.         self.registry.handleEvent(ev)
  290.  
  291.  
  292.  
  293. class Registry(object):
  294.     '''
  295.   Wraps the Accessibility.Registry to provide more Pythonic registration for
  296.   events. 
  297.   
  298.   This object should be treated as a singleton, but such treatment is not
  299.   enforced. You can construct another instance of this object and give it a
  300.   reference to the Accessibility.Registry singleton. Doing so is harmless and
  301.   has no point.
  302.   
  303.   @ivar async: Should event dispatch to local listeners be decoupled from event
  304.     receiving from the registry?
  305.   @type async: boolean
  306.   @ivar reg: Reference to the real, wrapped registry object
  307.   @type reg: Accessibility.Registry
  308.   @ivar dev: Reference to the device controller
  309.   @type dev: Accessibility.DeviceEventController
  310.   @ivar queue: Queue of events awaiting local dispatch
  311.   @type queue: Queue.Queue
  312.   @ivar clients: Map of event names to client listeners
  313.   @type clients: dictionary
  314.   @ivar observers: Map of event names to AT-SPI L{_Observer} objects
  315.   @type observers: dictionary
  316.   '''
  317.     
  318.     def __init__(self, reg):
  319.         '''
  320.     Stores a reference to the AT-SPI registry. Gets and stores a reference
  321.     to the DeviceEventController.
  322.     
  323.     @param reg: Reference to the AT-SPI registry daemon
  324.     @type reg: Accessibility.Registry
  325.     '''
  326.         self.reg = reg
  327.         self.async = None
  328.         self.queue = Queue.Queue()
  329.         self.clients = { }
  330.         self.observers = { }
  331.         if self.reg is not None:
  332.             self.dev = self.reg.getDeviceEventController()
  333.         else:
  334.             self.dev = None
  335.  
  336.     
  337.     def __call__(self, reg = None):
  338.         '''
  339.     @return: This instance of the registry. If we are passed a remote registry
  340.     instance for the first time, add it to our instance, and get a device event
  341.     controller.
  342.     @rtype: L{Registry}
  343.     '''
  344.         if reg and not (self.reg):
  345.             self.reg = reg
  346.             self.dev = self.reg.getDeviceEventController()
  347.         
  348.         return self
  349.  
  350.     
  351.     def __getattribute__(self, attr):
  352.         if attr != 'reg' and object.__getattribute__(self, 'reg') is None:
  353.             raise RuntimeError('Could not find or activate registry')
  354.         object.__getattribute__(self, 'reg') is None
  355.         return object.__getattribute__(self, attr)
  356.  
  357.     
  358.     def start(self, async = False, gil = True):
  359.         '''
  360.     Enter the main loop to start receiving and dispatching events.
  361.     
  362.     @param async: Should event dispatch be asynchronous (decoupled) from 
  363.       event receiving from the AT-SPI registry?
  364.     @type async: boolean
  365.     @param gil: Add an idle callback which releases the Python GIL for a few
  366.       milliseconds to allow other threads to run? Necessary if other threads
  367.       will be used in this process.
  368.     @type gil: boolean
  369.     '''
  370.         self.async = async
  371.         if gil:
  372.             
  373.             def releaseGIL():
  374.                 
  375.                 try:
  376.                     time.sleep(1e-05)
  377.                 except KeyboardInterrupt:
  378.                     e = None
  379.                     releaseGIL.keyboard_exception = e
  380.                     self.stop()
  381.  
  382.                 return True
  383.  
  384.             releaseGIL.keyboard_exception = None
  385.             i = gobject.idle_add(releaseGIL)
  386.         
  387.         
  388.         try:
  389.             bonobo.main()
  390.         finally:
  391.             for name, ob in self.observers.items():
  392.                 ob.unregister(self.reg, name)
  393.             
  394.             if gil:
  395.                 gobject.source_remove(i)
  396.                 if releaseGIL.keyboard_exception is not None:
  397.                     raise releaseGIL.keyboard_exception
  398.                 releaseGIL.keyboard_exception is not None
  399.             
  400.  
  401.  
  402.     
  403.     def stop(self, *args):
  404.         '''Quits the main loop.'''
  405.         
  406.         try:
  407.             bonobo.main_quit()
  408.         except RuntimeError:
  409.             pass
  410.  
  411.         self.flushEvents()
  412.  
  413.     
  414.     def getDesktopCount(self):
  415.         '''
  416.     Gets the number of available desktops.
  417.     
  418.     @return: Number of desktops
  419.     @rtype: integer
  420.     @raise LookupError: When the count cannot be retrieved
  421.     '''
  422.         
  423.         try:
  424.             return self.reg.getDesktopCount()
  425.         except Exception:
  426.             raise LookupError
  427.  
  428.  
  429.     
  430.     def getDesktop(self, i):
  431.         '''
  432.     Gets a reference to the i-th desktop.
  433.     
  434.     @param i: Which desktop to get
  435.     @type i: integer
  436.     @return: Desktop reference
  437.     @rtype: Accessibility.Desktop
  438.     @raise LookupError: When the i-th desktop cannot be retrieved
  439.     '''
  440.         
  441.         try:
  442.             return self.reg.getDesktop(i)
  443.         except Exception:
  444.             e = None
  445.             raise LookupError(e)
  446.  
  447.  
  448.     
  449.     def registerEventListener(self, client, *names):
  450.         """
  451.     Registers a new client callback for the given event names. Supports 
  452.     registration for all subevents if only partial event name is specified.
  453.     Do not include a trailing colon.
  454.     
  455.     For example, 'object' will register for all object events, 
  456.     'object:property-change' will register for all property change events,
  457.     and 'object:property-change:accessible-parent' will register only for the
  458.     parent property change event.
  459.     
  460.     Registered clients will not be automatically removed when the client dies.
  461.     To ensure the client is properly garbage collected, call 
  462.     L{deregisterEventListener}.
  463.  
  464.     @param client: Callable to be invoked when the event occurs
  465.     @type client: callable
  466.     @param names: List of full or partial event names
  467.     @type names: list of string
  468.     """
  469.         for name in names:
  470.             self._registerClients(client, name)
  471.         
  472.  
  473.     
  474.     def deregisterEventListener(self, client, *names):
  475.         '''
  476.     Unregisters an existing client callback for the given event names. Supports 
  477.     unregistration for all subevents if only partial event name is specified.
  478.     Do not include a trailing colon.
  479.     
  480.     This method must be called to ensure a client registered by
  481.     L{registerEventListener} is properly garbage collected.
  482.  
  483.     @param client: Client callback to remove
  484.     @type client: callable
  485.     @param names: List of full or partial event names
  486.     @type names: list of string
  487.     @return: Were event names specified for which the given client was not
  488.       registered?
  489.     @rtype: boolean
  490.     '''
  491.         missed = False
  492.         for name in names:
  493.             missed |= self._unregisterClients(client, name)
  494.         
  495.         return missed
  496.  
  497.     
  498.     def registerKeystrokeListener(self, client, key_set = [], mask = 0, kind = (constants.KEY_PRESSED_EVENT, constants.KEY_RELEASED_EVENT), synchronous = True, preemptive = True, global_ = False):
  499.         '''
  500.     Registers a listener for key stroke events.
  501.     
  502.     @param client: Callable to be invoked when the event occurs
  503.     @type client: callable
  504.     @param key_set: Set of hardware key codes to stop monitoring. Leave empty
  505.       to indicate all keys.
  506.     @type key_set: list of integer
  507.     @param mask: When the mask is None, the codes in the key_set will be 
  508.       monitored only when no modifier is held. When the mask is an 
  509.       integer, keys in the key_set will be monitored only when the modifiers in
  510.       the mask are held. When the mask is an iterable over more than one 
  511.       integer, keys in the key_set will be monitored when any of the modifier
  512.       combinations in the set are held.
  513.     @type mask: integer, iterable, None
  514.     @param kind: Kind of events to watch, KEY_PRESSED_EVENT or 
  515.       KEY_RELEASED_EVENT.
  516.     @type kind: list
  517.     @param synchronous: Should the callback notification be synchronous, giving
  518.       the client the chance to consume the event?
  519.     @type synchronous: boolean
  520.     @param preemptive: Should the callback be allowed to preempt / consume the
  521.       event?
  522.     @type preemptive: boolean
  523.     @param global_: Should callback occur even if an application not supporting
  524.       AT-SPI is in the foreground? (requires xevie)
  525.     @type global_: boolean
  526.     '''
  527.         
  528.         try:
  529.             ob = self.clients[client]
  530.         except KeyError:
  531.             ob = _DeviceObserver(self, synchronous, preemptive, global_)
  532.             self.clients[ob] = client
  533.             self.clients[client] = ob
  534.  
  535.         if mask is None:
  536.             mask = utils.allModifiers()
  537.         
  538.         ob.register(self.dev, key_set, mask, kind)
  539.  
  540.     
  541.     def deregisterKeystrokeListener(self, client, key_set = [], mask = 0, kind = (constants.KEY_PRESSED_EVENT, constants.KEY_RELEASED_EVENT)):
  542.         """
  543.     Deregisters a listener for key stroke events.
  544.     
  545.     @param client: Callable to be invoked when the event occurs
  546.     @type client: callable
  547.     @param key_set: Set of hardware key codes to stop monitoring. Leave empty
  548.       to indicate all keys.
  549.     @type key_set: list of integer
  550.     @param mask: When the mask is None, the codes in the key_set will be 
  551.       monitored only when no modifier is held. When the mask is an 
  552.       integer, keys in the key_set will be monitored only when the modifiers in
  553.       the mask are held. When the mask is an iterable over more than one 
  554.       integer, keys in the key_set will be monitored when any of the modifier
  555.       combinations in the set are held.
  556.     @type mask: integer, iterable, None
  557.     @param kind: Kind of events to stop watching, KEY_PRESSED_EVENT or 
  558.       KEY_RELEASED_EVENT.
  559.     @type kind: list
  560.     @raise KeyError: When the client isn't already registered for events
  561.     """
  562.         ob = self.clients[client]
  563.         if mask is None:
  564.             mask = utils.allModifiers()
  565.         
  566.         ob.unregister(self.dev, key_set, mask, kind)
  567.  
  568.     
  569.     def generateKeyboardEvent(self, keycode, keysym, kind):
  570.         '''
  571.     Generates a keyboard event. One of the keycode or the keysym parameters
  572.     should be specified and the other should be None. The kind parameter is 
  573.     required and should be one of the KEY_PRESS, KEY_RELEASE, KEY_PRESSRELEASE,
  574.     KEY_SYM, or KEY_STRING.
  575.     
  576.     @param keycode: Hardware keycode or None
  577.     @type keycode: integer
  578.     @param keysym: Symbolic key string or None
  579.     @type keysym: string
  580.     @param kind: Kind of event to synthesize
  581.     @type kind: integer
  582.     '''
  583.         if keysym is None:
  584.             self.dev.generateKeyboardEvent(keycode, '', kind)
  585.         else:
  586.             self.dev.generateKeyboardEvent(None, keysym, kind)
  587.  
  588.     
  589.     def generateMouseEvent(self, x, y, name):
  590.         '''
  591.     Generates a mouse event at the given absolute x and y coordinate. The kind
  592.     of event generated is specified by the name. For example, MOUSE_B1P 
  593.     (button 1 press), MOUSE_REL (relative motion), MOUSE_B3D (butten 3 
  594.     double-click).
  595.     
  596.     @param x: Horizontal coordinate, usually left-hand oriented
  597.     @type x: integer
  598.     @param y: Vertical coordinate, usually left-hand oriented
  599.     @type y: integer
  600.     @param name: Name of the event to generate
  601.     @type name: string
  602.     '''
  603.         self.dev.generateMouseEvent(x, y, name)
  604.  
  605.     
  606.     def handleDeviceEvent(self, event, ob):
  607.         '''
  608.     Dispatches L{event.DeviceEvent}s to registered clients. Clients are called
  609.     in the order they were registered for the given AT-SPI event. If any
  610.     client returns True, callbacks cease for the event for clients of this registry 
  611.     instance. Clients of other registry instances and clients in other processes may 
  612.     be affected depending on the values of synchronous and preemptive used when invoking
  613.     L{registerKeystrokeListener}. 
  614.     
  615.     @note: Asynchronous dispatch of device events is not supported.
  616.     
  617.     @param event: AT-SPI device event
  618.     @type event: L{event.DeviceEvent}
  619.     @param ob: Observer that received the event
  620.     @type ob: L{_DeviceObserver}
  621.  
  622.     @return: Should the event be consumed (True) or allowed to pass on to other
  623.       AT-SPI observers (False)?
  624.     @rtype: boolean
  625.     '''
  626.         
  627.         try:
  628.             client = self.clients[ob]
  629.         except KeyError:
  630.             return False
  631.  
  632.         
  633.         try:
  634.             if not client(event):
  635.                 pass
  636.             return event.consume
  637.         except Exception:
  638.             traceback.print_exc()
  639.  
  640.  
  641.     
  642.     def handleEvent(self, event):
  643.         '''    
  644.     Handles an AT-SPI event by either queuing it for later dispatch when the
  645.     L{Registry.async} flag is set, or dispatching it immediately.
  646.  
  647.     @param event: AT-SPI event
  648.     @type event: L{event.Event}
  649.     '''
  650.         if self.async:
  651.             self.queue.put_nowait(event)
  652.         else:
  653.             self._dispatchEvent(event)
  654.  
  655.     
  656.     def _dispatchEvent(self, event):
  657.         '''
  658.     Dispatches L{event.Event}s to registered clients. Clients are called in
  659.     the order they were registered for the given AT-SPI event. If any client
  660.     returns True, callbacks cease for the event for clients of this registry 
  661.     instance. Clients of other registry instances and clients in other processes 
  662.     are unaffected.
  663.  
  664.     @param event: AT-SPI event
  665.     @type event: L{event.Event}
  666.     '''
  667.         et = event.type
  668.         
  669.         try:
  670.             clients = self.clients[et.name]
  671.         except KeyError:
  672.             
  673.             try:
  674.                 if et.detail is not None:
  675.                     clients = self.clients['%s:%s:%s' % (et.klass, et.major, et.minor)]
  676.                 elif et.minor is not None:
  677.                     clients = self.clients['%s:%s' % (et.klass, et.major)]
  678.             except KeyError:
  679.                 return None
  680.             
  681.  
  682.             None<EXCEPTION MATCH>KeyError
  683.  
  684.         consume = False
  685.         for client in clients:
  686.             
  687.             try:
  688.                 if not client(event):
  689.                     pass
  690.                 consume = False
  691.             except Exception:
  692.                 traceback.print_exc()
  693.  
  694.             if consume or event.consume:
  695.                 break
  696.                 continue
  697.         
  698.  
  699.     
  700.     def flushEvents(self):
  701.         '''
  702.     Flushes the event queue by destroying it and recreating it.
  703.     '''
  704.         self.queue = Queue.Queue()
  705.  
  706.     
  707.     def pumpQueuedEvents(self, num = -1):
  708.         '''
  709.     Provides asynch processing of events in the queue by executeing them with 
  710.     _dispatchEvent() (as is done immediately when synch processing). 
  711.     This method would normally be called from a main loop or idle function.
  712.  
  713.     @param num: Number of events to pump. If number is negative it pumps
  714.     the entire queue. Default is -1.
  715.     @type num: integer
  716.     @return: True if queue is not empty after events were pumped.
  717.     @rtype: boolean
  718.     '''
  719.         if num < 0:
  720.             num = self.queue.qsize()
  721.         
  722.         for i in xrange(num):
  723.             
  724.             try:
  725.                 event = self.queue.get_nowait()
  726.             except Queue.Empty:
  727.                 break
  728.  
  729.             self._dispatchEvent(event)
  730.         
  731.         return not self.queue.empty()
  732.  
  733.     
  734.     def _registerClients(self, client, name):
  735.         '''
  736.     Internal method that recursively associates a client with AT-SPI event 
  737.     names. Allows a client to incompletely specify an event name in order to 
  738.     register for subevents without specifying their full names manually.
  739.     
  740.     @param client: Client callback to receive event notifications
  741.     @type client: callable
  742.     @param name: Partial or full event name
  743.     @type name: string
  744.     '''
  745.         
  746.         try:
  747.             events = constants.EVENT_TREE[name]
  748.         except KeyError:
  749.             et = event.EventType(name)
  750.             clients = self.clients.setdefault(et.name, [])
  751.             
  752.             try:
  753.                 clients.index(client)
  754.             except ValueError:
  755.                 clients.append(client)
  756.                 self._registerObserver(name)
  757.             except:
  758.                 None<EXCEPTION MATCH>ValueError
  759.             
  760.  
  761.             None<EXCEPTION MATCH>ValueError
  762.  
  763.         for e in events:
  764.             self._registerClients(client, e)
  765.         
  766.  
  767.     
  768.     def _unregisterClients(self, client, name):
  769.         '''
  770.     Internal method that recursively unassociates a client with AT-SPI event 
  771.     names. Allows a client to incompletely specify an event name in order to 
  772.     unregister for subevents without specifying their full names manually.
  773.     
  774.     @param client: Client callback to receive event notifications
  775.     @type client: callable
  776.     @param name: Partial or full event name
  777.     @type name: string
  778.     '''
  779.         missed = False
  780.         
  781.         try:
  782.             events = constants.EVENT_TREE[name]
  783.         except KeyError:
  784.             
  785.             try:
  786.                 et = event.EventType(name)
  787.                 clients = self.clients[et.name]
  788.                 clients.remove(client)
  789.                 self._unregisterObserver(name)
  790.             except (ValueError, KeyError):
  791.                 missed = True
  792.  
  793.             return missed
  794.  
  795.         for e in events:
  796.             missed |= self._unregisterClients(client, e)
  797.         
  798.         return missed
  799.  
  800.     
  801.     def _registerObserver(self, name):
  802.         '''    
  803.     Creates a new L{_Observer} to watch for events of the given type or
  804.     returns the existing observer if one is already registered. One
  805.     L{_Observer} is created for each leaf in the L{constants.EVENT_TREE} or
  806.     any event name not found in the tree.
  807.    
  808.     @param name: Raw name of the event to observe
  809.     @type name: string
  810.     @return: L{_Observer} object that is monitoring the event
  811.     @rtype: L{_Observer}
  812.     '''
  813.         et = event.EventType(name)
  814.         
  815.         try:
  816.             ob = self.observers[et.name]
  817.         except KeyError:
  818.             ob = _EventObserver(self)
  819.             ob.register(self.reg, name)
  820.             self.observers[et.name] = ob
  821.  
  822.         ob.clientRef()
  823.         return ob
  824.  
  825.     
  826.     def _unregisterObserver(self, name):
  827.         '''    
  828.     Destroys an existing L{_Observer} for the given event type only if no
  829.     clients are registered for the events it is monitoring.
  830.     
  831.     @param name: Name of the event to observe
  832.     @type name: string
  833.     @raise KeyError: When an observer for the given event is not regist
  834.     '''
  835.         et = event.EventType(name)
  836.         ob = self.observers[et.name]
  837.         ob.clientUnref()
  838.         if ob.getClientRefCount() == 0:
  839.             ob.unregister(self.reg, name)
  840.             del self.observers[et.name]
  841.         
  842.  
  843.  
  844.