Mini Shell

Direktori : /lib/python3.6/site-packages/orca/__pycache__/
Upload File :
Current File : //lib/python3.6/site-packages/orca/__pycache__/event_manager.cpython-36.pyc

3

�p5[=y�@s�dZdZdZdZdZddlmZddlZddlZddl	Z	ddl
Z
dd	lmZdd
lm
Z
ddlmZddlmZdd
lmZddlmZej�ZGdd�d�Ze�Zdd�ZdS)z$Id$z
$Revision$z$Date$zCopyright (c) 2011. Orca Team.ZLGPL�)�GLibN�)�debug)�input_event)�messages)�
orca_state)�script_manager)�settingsc@s�eZdZdZd4dd�Zdd�Zdd�Zd	d
�Zdd�Zd
d�Z	dd�Z
d5dd�Zdd�Zdd�Z
dd�Zdd�Zdd�Zdd�Zdd �Zd!d"�Zd6d$d%�Zd7d&d'�Zd(d)�Zed*d+��Zd8d,d-�Zd.d/�Zd0d1�Zd2d3�Zd#S)9�EventManageruTcCs�tjtjdd�tjtjd|d�||_i|_tj|_tjjd�|_	d|_
d|_d|_t
jd�|_d|_tj�|_d|_dg|_dd	d
g|_tjtjdd�dS)NzEVENT MANAGER: InitializingTzEVENT MANAGER: Async Mode is %srFg�h㈵��>ZVCLzobject:bounds-changedzobject:state-changed:defunctz(object:property-change:accessible-parentzEvent manager initialized)r�println�
LEVEL_INFO�
_asyncMode�_scriptListenerCounts�pyatspiZRegistry�registryZ
getDesktop�_desktop�_active�
_enqueueCount�
_dequeueCount�queueZQueue�_eventQueue�_gidleId�	threadingZLock�
_gidleLock�
_gilSleepTime�_synchronousToolkits�_ignoredEvents)�self�	asyncMode�r�#/usr/lib/python3.6/event_manager.py�__init__.s$
zEventManager.__init__cCs^tjtjdd�|jd�|jd�|jd�|jd�|j|j�d|_tjtjdd�dS)	z3Called when this presentation manager is activated.zEVENT MANAGER: ActivatingTzwindow:activatezwindow:deactivatezobject:children-changedzmouse:buttonzEVENT MANAGER: ActivatedN)rrr�_registerListener�registerKeystrokeListener�_processKeyboardEventr)rrrr �activateBs



zEventManager.activatecCs`tjtjdd�d|_x"|jj�D]}|jj|j|�q"Wi|_|j	|j
�tjtjdd�dS)z.Called when this event manager is deactivated.zEVENT MANAGER: DectivatingTFzEVENT MANAGER: DeactivatedN)rrrrr�keysr�deregisterEventListener�_enqueue�deregisterKeystrokeListenerr$)r�	eventTyperrr �
deactivateNszEventManager.deactivatecCs(x"|D]}||jkr|jj|�qWdS)N)r�append)r�
eventTypeListr*rrr �ignoreEventTypesYs

zEventManager.ignoreEventTypescCs(x"|D]}||jkr|jj|�qWdS)N)r�remove)rr-r*rrr �unignoreEventTypes^s

zEventManager.unignoreEventTypescCs�tjtjd�d|j|j|j|j|j|jf}tjtj|d�|j	s\d}tjtj|d�dSt
t|jj|j
��r�d}tjtj|d�dS|jjd�r�d}tjtj|d�dStj}|jjd	��r|s�d
}tjtj|d�dS|j|jk�rd}tjtj|d�dS|jjd��r6|j|jk�r6d}tjtj|d�dS|jjd
��rx|jjd��rx|j|jk�rxd}tjtj|d�dSy|jj�}|jj�}Wnd}tjtj|d�dS|jtj��r�d}tjtj|d�dS|jjd	��r|tjtjtjgk�rd}tjtj|d�dS|jjd��rJ|tjtjgk�rJd}tjtj|d�dS|jjd��r�|tjtjtjgk�r�d}tjtj|d�dS|jjd��r�|tj tj!tj"tj#tj$tj%tj&gk�r�d}tjtj|d�dS|jjd	��s�|jjd��r�|j�sd}tjtj|d�dSy|jj�}|jj�}Wnd}tjtj|d�dS|jtj��rld}tjtj|d�dS|tj'k�r�d}tjtj|d�dSd}tjtj|d�dS)z-Returns True if this event should be ignored.�z+EVENT MANAGER: %s for %s in %s (%s, %s, %s)Tz;EVENT MANAGER: Ignoring because event manager is not activez5EVENT MANAGER: Ignoring because event type is ignoredZwindowz?EVENT MANAGER: Not ignoring because event type is never ignoredFzobject:children-changed:addz9EVENT MANAGER: Ignoring because there is no active scriptz<EVENT MANAGER: Ignoring because event is not from active appzobject:children-changed:removezobject:text-changed�systemz?EVENT MANAGER: Ignoring because changed text is embedded objectz/ERROR: Event is from potentially-defunct sourcez#ERROR: Event is from defunct sourcez.EVENT MANAGER: Ignoring event type due to rolez&object:property-change:accessible-namezobject:state-changed:sensitivezobject:state-changed:showingz object:active-descendant-changedz,ERROR: Event any_data lacks child/descendantzCERROR: Event any_data contains potentially-defunct child/descendantz7ERROR: Event any_data contains defunct child/descendantz0EVENT MANAGER: Not ignoring due to lack of cause)(rrr�type�source�host_application�detail1�detail2�any_datar�list�filter�
startswithrr�activeScript�appr�endswith�EMBEDDED_OBJECT_CHARACTER�getState�getRole�containsr�
STATE_DEFUNCT�	ROLE_MENUZROLE_LAYERED_PANEZROLE_MENU_ITEMZROLE_CANVASZ	ROLE_ICONZROLE_CHECK_MENU_ITEMZROLE_RADIO_MENU_ITEMZ
ROLE_ALERTZROLE_ANIMATIONZ
ROLE_INFO_BARZROLE_NOTIFICATION�
ROLE_PANELZROLE_STATUS_BARZ
ROLE_TOOL_TIPZ
ROLE_IMAGE)r�event�msg�script�state�rolerrr �_ignorecs�

zEventManager._ignorecCs�tj}|rtjtjd�|jj�|rZtjtjd�tjtjd�tjtjd|jj��|jj|�|rxtjtjd�|r�|j	r�|j
r�tj|j
�t
j|j�|_	|r�tjtjd�|jj�tjr�tjtjd�dS)Nz           acquiring lock...z           ...acquiredz           calling queue.put...z           (full=%s)z           ...put completez           releasing lock...z           ...released)r�debugEventQueuer�	LEVEL_ALLr�acquirerZfullZputrr�time�sleeprZidle_add�_dequeue�release)rrFr�	debuggingrrr �_addToQueue�s*


zEventManager._addToQueuecCs�t|tj�rd|j|jf}nTt|tj�r:dt|j�}n8tj	sPtj	j
|j�rnd|j|j
|j|j|jf}ndS|r�d|j|f}nd|j|f}tjtj|d�dS)z:Convenience method to output queue-related debugging info.z	'%s' (%d)z'%s'z%s (%s,%s,%s) from %sNzEVENT MANAGER: Queueing %s %szEVENT MANAGER: Dequeued %s %sT)�
isinstancer�
KeyboardEventZevent_stringZhw_code�BrailleEvent�reprrFr�eventDebugFilter�matchr3r4r6r7r8r5rr)r�e�	isEnqueue�data�stringrrr �
_queuePrintlnszEventManager._queuePrintlnc
CsPtjr4|jr&d|j}tjtj|d�|jd7_tjtjf}t||�}y|oZ|j	|�}Wn(d|}tjtj
|d�d}YnX|r�tjr�|jd8_dS|j|�|j}|�r|j
j�}y
|j}Wnd}YnX||jks�t|tj�r�d}tj||j
�}	|tj�f|	j|j<|j||�|�s6|j�tj�rL|jd8_dS)zuHandles the enqueueing of all events destined for scripts.

        Arguments:
        - e: an at-spi event.
        z;EVENT MANAGER: _enqueue entered before exiting (count = %d)Trz%ERROR: Exception evaluating event: %sNF)rrLrrrMrrVrWrUrKrr_r
r4�getApplication�toolkitNamerZMouseButtonEvent�_scriptManager�	getScriptrOZ
eventCacher3rTrQ)
rr[rG�inputEventsZ
isObjectEvent�ignorerr=rarHrrr r(sH





zEventManager._enqueuec
Cs�d}tjr2d|j}tjtj|d�|jd7_�y>|jj�}|j|dd�tj	tj
f}t||�rp|j|�n~|t_
tjp�tjj|j�}|r�tj�}tjtjd|j�|j|�|r�tjtjdtj�|�tjtjd|j�d	t_
ytjp�tj}Wnd}YnX|jj�|jj��rf|�r\|j�rBtj|j�tj}tj�}	|	j |d
�d|_!d}|jj"�WnLt#j$k
�r�d}tjtj%|d�d|_!d}Yntj&tj%�YnXtj�r�|jd8_d
|j}tjtj|d�|S)zOHandles all events destined for scripts. Called by the GTK
        idle thread.TzEVENT MANAGER: Dequeue %drF)r\z$
vvvvv PROCESS OBJECT EVENT %s vvvvvzTOTAL PROCESSING TIME: %.4fz$^^^^^ PROCESS OBJECT EVENT %s ^^^^^
Nr1rz>EVENT MANAGER: Attempted dequeue, but the event queue is emptyz*EVENT MANAGER: Leaving _dequeue. Count: %d)'rrLrrrMrZ
get_nowaitr_rrVrWrU�_processInputEventZobjEventrYrZr3rO�eventDebugLevel�_processObjectEventrr<�locusOfFocusrrN�emptyrrPrZNO_FOCUSrbZgetDefaultScriptZpresentMessagerrRrZEmptyZLEVEL_SEVERE�printException)
rZrerunrGrFrdrS�	startTimeZnoFocusZfullMessageZ
defaultScriptrrr rQMsn








zEventManager._dequeuecCsTd|}tjtj|d�||jkr6|j|d7<n|jj|j|�d|j|<dS)zwTells this module to listen for the given event type.

        Arguments:
        - eventType: the event type.
        z+EVENT MANAGER: registering listener for: %sTrN)rrrrr�registerEventListenerr()rr*rGrrr r"�s
zEventManager._registerListenercCsbd|}tjtj|d�||jkr&dS|j|d8<|j|dkr^|jj|j|�|j|=dS)zTells this module to stop listening for the given event type.

        Arguments:
        - eventType: the event type.
        z-EVENT MANAGER: deregistering listener for: %sTNrr)rrrrrr'r()rr*rGrrr �_deregisterListener�s
z EventManager._deregisterListenercCs:d|}tjtj|d�x|jj�D]}|j|�q$WdS)z�Tells the event manager to start listening for all the event types
        of interest to the script.

        Arguments:
        - script: the script.
        z,EVENT MANAGER: registering listeners for: %sTN)rrr�	listenersr&r")rrHrGr*rrr �registerScriptListeners�sz$EventManager.registerScriptListenerscCs:d|}tjtj|d�x|jj�D]}|j|�q$WdS)z�Tells the event manager to stop listening for all the event types
        of interest to the script.

        Arguments:
        - script: the script.
        z.EVENT MANAGER: deregistering listeners for: %sTN)rrrror&rn)rrHrGr*rrr �deregisterScriptListeners�sz&EventManager.deregisterScriptListenerscCs(x"|j�D]\}}|jj||�q
WdS)z/Register the listeners on behalf of the caller.N)�itemsrrm)rror*�functionrrr �registerModuleListeners�sz$EventManager.registerModuleListenerscCs(x"|j�D]\}}|jj||�q
WdS)z0Deegister the listeners on behalf of the caller.N)rrrr')rror*rsrrr �deregisterModuleListeners�sz&EventManager.deregisterModuleListenersNcCsVd|}tjtj|d�|dkr,ttd��}|dkr@tjtjf}|jj	|||d�dS)z8Register the keystroke listener on behalf of the caller.z:EVENT MANAGER: registering keystroke listener function: %sTN�)�mask�kind)
rrrr9�ranger�KEY_PRESSED_EVENT�KEY_RELEASED_EVENTrr#)rrsrwrxrGrrr r#�sz&EventManager.registerKeystrokeListenercCsVd|}tjtj|d�|dkr,ttd��}|dkr@tjtjf}|jj	|||d�dS)z:Deregister the keystroke listener on behalf of the caller.z<EVENT MANAGER: deregistering keystroke listener function: %sTNrv)rwrx)
rrrr9ryrrzr{rr))rrsrwrxrGrrr r)�sz(EventManager.deregisterKeystrokeListenercCs�tjs
dSt|tj�r.tjj}dt|j�}ndSt|j	�j
�}tj�}tj
tjd||f�y||�Wn$tjtj�tjtj�YnXtj
tjdtj�|�tj
tjd||f�dS)z�Processes the given input event based on the keybinding from the
        currently-active script.

        Arguments:
        - event: an instance of BrailleEvent or a KeyboardEvent
        Nz'%s'z
vvvvv PROCESS %s %s vvvvvzTOTAL PROCESSING TIME: %.4fz^^^^^ PROCESS %s %s ^^^^^
)rr<rUrrW�processBrailleEventrXrF�strr3�upperrOrrrgrk�
LEVEL_WARNINGZ
printStack)rrFrsr]�eTyperlrrr rf�s(zEventManager._processInputEventcs��jjd�rtjSd}d}y@�jp*�jj�}|rX|j�jt	j
�rXd}tjtj
|d�dSWn d}tjtj
|d�YndXdddd	d
ddd
ddddg}tt�fdd�|��}d||f}tjtj|d�tj|�j|d�}d|}tjtj|d�|S)z)Returns the script associated with event.zmouse:Nz5WARNING: App is defunct. Cannot get script for event.Tz1WARNING: Exception when getting script for event.zobject:children-changedzobject:column-reorderedzobject:row-reorderedzobject:property-changez4object:selection-changedobject:state-changed:checkedzobject:state-changed:expandedz"object:state-changed:indeterminatezobject:state-changed:pressedzobject:state-changed:selectedzobject:state-changed:sensitivezobject:state-changed:showingzobject:text-changedcs�jj|�S)N)r3r;)�x)rFrr �<lambda>>sz1EventManager._getScriptForEvent.<locals>.<lambda>z0EVENT MANAGER: Getting script for %s (check: %s))ZsanityCheckzEVENT MANAGER: Script is %s)r3r;rr<r5r4r`r@rBrrCrrrr9r:rrbrc)rFrHr=rGZ	skipCheckZcheckr)rFr �_getScriptForEvents@zEventManager._getScriptForEventcCs&|js
dSd}}y|jj�}Wnttfk
r8dSXy|jj�}Wnttfk
r`dSX|sp|j|�}|sxdS|tjkr�dS|j|�s�dS|j	}|j
d	�r�dS|j
d�s�|j
d
�r�|jr�dS|j
d��r�|j�r�|tj
k�r�|jtj��r�dS|j
d��r"|tjk�r"|jtj��r"dSdS)aDetermines if the event is one which should cause us to
        change which script is currently active.

        Returns a (boolean, string) tuple indicating whether or not
        this is an activatable event, and our reason (for the purpose
        of debugging).
        F�!event.source? What event.source??N�!Error getting event.source's role�"Error getting event.source's state�"There is no script for this event.�,The script for this event is already active.�/The script says not to activate for this event.zwindow:activateT�window:activate eventZfocuszobject:state-changed:focused�Event source claimed focus.zobject:state-changed:selected� Selection change in focused menuzobject:state-changed:showing�Modal panel is showing.�/No reason found to activate a different script.)Fr�)Fr�)Fr�)Fr�)Fr�)Fr�)Tr�)Tr�)Tr�)Tr�)Fr�)r4rA�LookupError�RuntimeErrorr@r�rr<ZisActivatableEventr3r;r6rrDrBZ
STATE_FOCUSEDrEZSTATE_MODAL)rrFrHrJrIr�rrr �_isActivatableEventGsD	





z EventManager._isActivatableEventc
)Cs�tjtj|dd�|j}|jd�rly|j|jkr<tj�dSWn,t	t
fk
rVYntjtj�dS|jd�r�|j
d�r�tj�|jd�r�y|jj�}WnYnX|tjkr�tj�|jd�r�tjr�tjjr�tjj|jkr�dtj_y|jj�}WnRt	t
fk
�rHd	|}tjtj|d�|jd��rDdt_dt_dSdS|�r�|jtj��r�d
|j}tjtj|d�|jd��r�dt_dt_dS|�r�|jtj��r�d|j}tjtj|d�dStj�s�tjj|��r|jd��rtjtjd|j�|j |�}|�s2d|}tjtj|d�dS|j!||�\}}d||f}tjtj|d�|�r�y|j�pv|jj"�}	Wn$d|j}tjtj|d�dSytj#||�Wn$d|j}tjtj|d�dSy|j$|�Wn2d|j}tjtj|d�tjtj�YnXdtjtjf}tjtj|d�tj�sDdStjj%�}
x2|
j&�D]&\}}d||f}tjtj|d��qXWdS)zjHandles all object events destined for scripts.

        Arguments:
        - e: an at-spi event.
        T)Z	timestampzobject:children-changed:removeNzwindow:Zcreatezobject:state-changed:activezwindow:deactivatez"ERROR: Could not process event: %sz*EVENT MANAGER: Ignoring defunct object: %sz,EVENT MANAGER: Ignoring iconified object: %szmouse:� �z"ERROR: Could not get script for %sz,EVENT MANAGER: Change active script: %s (%s)z'ERROR: Could not get application for %sz)ERROR: Could not set active script for %szERROR: Could not process %sz0EVENT MANAGER: locusOfFocus: %s activeScript: %szEVENT MANAGER: %s: %sz           )'rZprintObjectEventrr3r;r4rrbZreclaimScriptsr�r�rkrr>rArZ
ROLE_FRAMErr<ZflatReviewContextr=r5r@rriZactiveWindowrBrCZSTATE_ICONIFIEDrYrZZprintDetailsr�r�r`ZsetActiveScriptZprocessObjectEventZgetTransferableAttributesrr)
rrFr�rJrIrGrHZsetNewActiveScript�reasonr=Z
attributes�key�valuerrr rhs�










z EventManager._processObjectEventcCsDtj|�}|js"tjtjd|�|j�}ddlm}|j|�|S)Nz
%sr)�orca)	rrVZis_duplicaterrrZprocessr�ZupdateKeyMap)rrFZ
keyboardEvent�rvr�rrr r$�s

z"EventManager._processKeyboardEventcCs(tjr tjj|�r |j|�dSdSdS)z�Called whenever a cursor key is pressed on the Braille display.

        Arguments:
        - brailleEvent: an instance of input_event.BrailleEvent

        Returns True if the command was consumed; otherwise False
        TFN)rr<ZconsumesBrailleEventr()rZbrailleEventrrr r|s
	
z EventManager.processBrailleEvent)T)T)NN)NN)N)�__name__�
__module__�__qualname__r?r!r%r+r.r0rKrTr_r(rQr"rnrprqrtrur#r)rf�staticmethodr�r�rhr$r|rrrr r
*s4


2H

 +
8t
r
cCstS)N)�_managerrrrr �
getManagersr�)Z__id__�__version__Z__date__Z
__copyright__Z__license__Z
gi.repositoryrrrrrOr1rrrrrr	r�rbr
r�rrrr �<module>s0k