Mini Shell

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

3

�2[4�@sldZdZdZdZdZddlZddlZddlmZdd	lm	Z	dd
l
mZmZGdd�d�Z
e
�Zd
d�ZdS)z$Id$z
$Revision$z$Date$zCopyright (c) 2011. Orca Team.ZLGPL�N�)�debug)�
orca_state)�apps�toolkitsc@s�eZdZdd�Zdd�Zdd�Zdd�Zd	d
�Zdd�Zd
d�Z	ddd�Z
d dd�Zdd�Zd!dd�Z
d"dd�Zdd�Zdd�ZdS)#�
ScriptManagercCs�tjtjdd�i|_i|_i|_tj|_t	j|_
d|_ddddg|_ddd	d
ddd
d�|_
|jdd�tjjd�|_d|_tjtjdd�dS)NzSCRIPT MANAGER: InitializingTzorca-scriptszorca.scriptszorca.scripts.appszorca.scripts.toolkitsZMozillaZThunderbirdZempathyZ	gcalctoolZmetacityZBansheeznotification-daemon)ZFirefoxZIcedovezempathy-chatzgnome-calculatorZmarcoZNereidzmate-notification-daemon�__init__rFzSCRIPT MANAGER: Initialized)r�println�
LEVEL_INFO�
appScripts�toolkitScripts�
customScriptsr�__all__�_appModulesr�_toolkitModules�_defaultScript�_scriptPackages�	_appNames�setActiveScript�pyatspiZRegistryZ
getDesktop�_desktop�_active)�self�r�$/usr/lib/python3.6/script_manager.pyr$s,
zScriptManager.__init__cCsNtjtjdd�|jd�|_|jj�|j|jd�d|_tjtjdd�dS)z-Called when this script manager is activated.zSCRIPT MANAGER: ActivatingTN�activatezSCRIPT MANAGER: Activated)rr	r
�	getScriptrZregisterEventListenersrr)rrrrr@s
zScriptManager.activatecCs^tjtjdd�|jr |jj�d|_|jdd�i|_i|_i|_d|_	tjtjdd�dS)z/Called when this script manager is deactivated.zSCRIPT MANAGER: DectivatingTN�
deactivateFzSCRIPT MANAGER: Deactivated)
rr	r
rZderegisterEventListenersrrrr
r)rrrrrJs
zScriptManager.deactivatecs�y|dk	o|jdk}Wn4ttfk
rJd}d|}tjtj|d�YnX|sTdS|jjd�d�t|jj	��}�fdd	�|D�}|r�|jj
|d��n6x4|j|jfD]$}�fd
d	�|D�}|r�|d�Pq�Wd|j�f}tjtj|d��S)zAReturns the module name of the script to use for application app.N�FzERROR: %s no longer existsT�.rcs g|]}|j��j�kr|�qSr)�lower)�.0�n)�namerr�
<listcomp>jsz/ScriptManager.getModuleName.<locals>.<listcomp>cs g|]}|j��j�kr|�qSr)r )r!r")r#rrr$oszSCRIPT MANAGER: mapped %s to %s)
r#�LookupError�RuntimeErrorrr	r
�split�listr�keys�getrr)r�appZappAndNameExist�msgZaltNames�namesZnameListr)r#r�
getModuleNameXs*zScriptManager.getModuleNamecCsPd}|rLy|j�}Wnttfk
r,Yn Xtdd�|D��}|jdd�}|S)z4Returns the name of the toolkit associated with obj.rcSsg|]}|jdd��qS)�:r)r')r!�attrrrrr$�sz3ScriptManager._toolkitForObject.<locals>.<listcomp>Ztoolkit)Z
getAttributesr%r&�dictr*)r�objr#Z
attributes�attrsrrr�_toolkitForObjectxszScriptManager._toolkitForObjectc	Cs*y|j�}Wn
dS|tjkr&dSdS)NrZterminal)�getRolerZ
ROLE_TERMINAL)rr2�rolerrr�_scriptForRole�s
zScriptManager._scriptForRolecCs�|o|sdSd}x�|jD]�}dj||f�}ytj|�}Wn0tk
rNwYntk
rhtj�YnXtjtj	d|d�y&t
|d�r�|j|�}n
|j|�}PWqtj
tj	�d|}tjtj	|d�YqXqW|S)zkAttempts to locate and load the named module. If successful, returns
        a script based on this module.NrzSCRIPT MANAGER: Found %sTrzERROR: Could not load %s)r�join�	importlib�
import_module�ImportError�OSErrorrZexamineProcessesr	r
�hasattrr�Script�printException)rr+r#�script�package�
moduleName�moduler,rrr�_newNamedScript�s,

zScriptManager._newNamedScriptNcCs�|j|�}|j||�}|r|S|j|�}|j||�}|r<|Syt|dd�}Wn0ttfk
r|d|}tjtj|d�YnX|r�|r�|j||�}|s�|j	|�}d}tjtj|d�|S)z8For the given application, create a new script instance.�toolkitNameNz,ERROR: Exception getting toolkitName for: %sTz&SCRIPT MANAGER: Default script created)
r.rDr4�getattrr%r&rr	r
�getDefaultScript)rr+r2rBr@�
objToolkitrEr,rrr�
_createScript�s(


zScriptManager._createScriptcCs6|r|jr|jSddlm}|j|�}|s2||_|S)Nr)�default)r�scriptsrJr>)rr+rJr@rrrrG�s
zScriptManager.getDefaultScriptc
Cs�|js
|Sy|j|jk}Wnd}YnX|r4|Sd|j}tjtj|d�|j|j�}|rzd|}tjtj|d�|Sd|j}tjtj|d�|S)NFz,WARNING: %s is not in the registry's desktopTz2SCRIPT MANAGER: Script for app replicant found: %sz2WARNING: Failed to get a replacement script for %s)rr+rrr	r
�_getScriptForAppReplicant)rr@ZappInDesktopr,�	newScriptrrr�sanityCheckScript�s$


zScriptManager.sanityCheckScriptFcCs�d}d}d}|j|�}|rT|jj|i�}|j|�}|sJ|j||�}|||<||j|<|j|�}	|	r�|jj|i�}
|
j|	�}|s�|j||�}||
|	<|
|j|<y>|s�|j�}n,||jkr�|j|}n|j|d�}||j|<Wn4d}t	j
t	j�t	jt	j
|d�|j�}YnX|�r|Sy|j�}Wnd}
YnX|tjtjgk}
|�rl|
�rlt|j|j��rl|S|�r�|�r�|j|�}|S)z�Get a script for an app (and make it if necessary).  This is used
        instead of a simple calls to Script's constructor.

        Arguments:
        - app: the Python app

        Returns an instance of a Script.
        Nz&WARNING: Exception getting app script.TF)r7r
r*rDr4rrIrGrrr?Z	LEVEL_ALLr	Z
LEVEL_WARNINGr5rZ
ROLE_FRAMEZROLE_STATUS_BAR�
issubclass�	__class__rN)rr+r2ZsanityCheck�customScript�	appScript�
toolkitScriptZroleNamer
rHrr,r6ZforceAppScriptrrrr�sX










zScriptManager.getScriptcCsVtj|krdStjrtjj�|t_|s,dS|j�d|j|f}tjtj|d�dS)znSet the new active script.

        Arguments:
        - newScript: the new script to be made active.
        Nz5SCRIPT MANAGER: Setting active script: %s (reason=%s)T)rZactiveScriptrrr#rr	r
)rrM�reasonr,rrrr6s

zScriptManager.setActiveScriptcCsh|js
dSdd�}||�}|dkr&dS|jj�}x2|D]*\}}||kr6||�|kr6||jkr6|Sq6WdS)Nc	Ssy|j�SdSdS)Nr���)Zget_process_id)r+rrr�_pidPsz5ScriptManager._getScriptForAppReplicant.<locals>._pidrrU)rr�itemsr)rr+rV�pidrW�ar@rrrrLLs
z'ScriptManager._getScriptForAppReplicantc
sbt�jj��}y�fdd�|D�}Wntjtj�dS�x|D�]}d|}tjtj|d��jj|�}�j	|�}|r�d|}tjtj|d�|j
�}x<|j�D]0\}}d||f}tjtj|d�t|||�q�W~y�j
j|�}	Wntk
�rYnXx|	j�D]}
~
�qWy�jj|�}Wntk
�r@YnXx|j�D]}~�qLW~qDWdS)zqCompares the list of known scripts to the list of known apps,
        deleting any scripts as necessary.
        cs"g|]}|dk	r|�jkr|�qS)N)r)r!rY)rrrr$hsz0ScriptManager.reclaimScripts.<locals>.<listcomp>Nz5SCRIPT MANAGER: %s is no longer in registry's desktopTz2SCRIPT MANAGER: Script for app replicant found: %sz SCRIPT MANAGER: Setting %s to %s)r(rr)rr?ZLEVEL_FINESTr	r
�poprLZgetTransferableAttributesrW�setattrr�KeyError�valuesr
)
rZappListr+r,rRrMr3r0�valuerrSr
rQr)rr�reclaimScriptsasB
zScriptManager.reclaimScripts)N)N)NF)N)�__name__�
__module__�__qualname__rrrr.r4r7rDrIrGrNrrrLr_rrrrr"s
 


C
rcCstS)N)�_managerrrrr�
getManager�srd)Z__id__�__version__Z__date__Z
__copyright__Z__license__r9rrrrrKrrrrcrdrrrr�<module>sq