Mini Shell

Direktori : /proc/self/root/lib/python3.6/site-packages/orca/__pycache__/
Upload File :
Current File : //proc/self/root/lib/python3.6/site-packages/orca/__pycache__/settings_manager.cpython-36.pyc

3

�2[�R�@s�dZdZdZdZdZdZddlZddlZddlZddl	m
Z
mZd	d
lm
Z
d	dlmZd	dlmZd	d
lmZd	dlmZd	dlmZd	dlmZy$e
jje
jje
jjddddd�ZWndZYnXej�ZGdd�de�Z e �Z!dd�ZdS)z\Settings manager module. This will load/save user settings from a 
defined settings backend.z$Id$z
$Revision$z$Date$z2Copyright (c) 2010 Consorcio Fernando de los Rios.ZLGPL�N)�Gio�GLib�)�debug)�	orca_i18n)�script_manager)�settings)�pronunciation_dict)�ACSS)�
KeyBindingzorg.a11y.Busz
/org/a11y/buszorg.freedesktop.DBus.Propertiesc@sneZdZdZdZdd�ZdWdd�Zdifdd	�Zd
d�Zdd
�Z	dd�Z
dd�Zdd�Zdd�Z
dd�Zdd�Zdd�Zdd�ZdXdd �ZdYd!d"�Zd#d$�Zd%d&�Zd'd(�Zd)d*�Zd+d,�ZdZd-d.�Zd/d0�Zd[d2d3�Zd4d5�Zd6d7�Zd\d8d9�Zd]d:d;�Zd^d<d=�Z d>d?�Z!d@dA�Z"dBdC�Z#dDdE�Z$dFdG�Z%dHdI�Z&dJdK�Z'dLdM�Z(d_dNdO�Z)dPdQ�Z*d`dSdT�Z+dUdV�Z,dS)a�SettingsManagerz^Settings backend manager. This class manages orca user's settings
    using different backendsNcOs&dt|�kr tj|f|�|�|_|jS)NZ
__instance)�vars�object�__new__Z_SettingsManager__instance)�cls�args�kwargs�r�&/usr/lib/python3.6/settings_manager.pyr?szSettingsManager.__new__�jsoncCs�tjtjdd�d|_d|_d|_||_d|_i|_i|_	i|_
i|_i|_i|_
i|_i|_i|_d|_i|_i|_i|_|j�s�td��i|_d|_dg|_tjtjdd�dS)	z�Initialize a SettingsManager Object.
        If backend isn't defined then uses default backend, in this
        case json-backend.
        backend parameter can use the follow values:
        backend='json'
        zSETTINGS MANAGER: InitializingTN�z$SettingsManager._loadBackend failed.Fzapp-settingszSETTINGS MANAGER: Initialized)r�println�
LEVEL_INFO�
backendModule�_backend�profile�backendName�	_prefsDir�defaultGeneral�defaultPronunciations�defaultKeybindings�profileGeneral�profilePronunciations�profileKeybindings�general�pronunciations�keybindings�
_activeApp�_appGeneral�_appPronunciations�_appKeybindings�_loadBackend�	Exception�customizedSettings�_customizationCompletedZsettingsPackages)�self�backendrrr�__init__Ds2zSettingsManager.__init__cCs�tjtjdd�|jj|�|p0tjjtj	�d�|_
|jj|j
�|_
|j�|j�|j�|jj�|_|j�s�|jj|j
j��|jj�|_|jj�|_|j�tjtjdd�|jdkr�|jjd�d|_|j|j�dS)NzSETTINGS MANAGER: ActivatingT�orcazSETTINGS MANAGER: Activated�startingProfiler)rrrr-�update�os�path�joinrZget_user_data_dirrrZBackendr�_setDefaultGeneral�_setDefaultPronunciations�_setDefaultKeybindingsr�copyr$�isFirstStart�
getGeneralrr%r r&�_createDefaultsr�get�
setProfile)r/ZprefsDirZcustomSettingsrrr�activateys$
zSettingsManager.activatec	Cs,yd|j}tj|d�|_dSdSdS)z.Load specific backend for manage user settingsz.backends.%s_backendr2TFN)r�	importlib�
import_moduler)r/r0rrrr+�s
zSettingsManager._loadBackendcCsdd�}|j}||�tjj|d�}||�tjj|d�}tjj|�s\tjtj|tjd��tjj|d�}||�tjj|d�}||�tjj|d�}tjj|�s�tjtj|tjd��tjj|d�}tjj|�s�tjtj|tjd��|j��r|j	j
|j|j|j
�d	S)
z�Let the active backend to create the initial structure
        for storing the settings and save the default ones from
        orca.settingscSstjj|�stj|�dS)N)r5r6�isdir�makedirs)ZdirNamerrr�
_createDir�sz3SettingsManager._createDefaults.<locals>._createDirzorca-scriptsz__init__.pyi�zapp-settingsZsoundszorca-customizations.pyN)rr5r6r7�exists�close�open�O_CREATr<rZsaveDefaultSettingsrrr )r/rFZorcaDirZ
orcaScriptDirZinitFileZorcaSettingsDirZ
orcaSoundsDirZuserCustomFilerrrr>�s,

zSettingsManager._createDefaultscCs
i|_dS)z4Get the pronunciations by default from orca.settingsN)r)r/rrrr9�sz)SettingsManager._setDefaultPronunciationscCs
i|_dS)z1Get the keybindings by default from orca.settingsN)r )r/rrrr:�sz&SettingsManager._setDefaultKeybindingsc
Cs\|j�i|_xHtjD]>}|jj|�}|dkrJytt|�}WnYnX||j|<qWdS)z6Get the general settings by default from orca.settingsN)�_getCustomizedSettingsrrZuserCustomizableSettingsr-r?�getattr)r/�key�valuerrrr8�sz"SettingsManager._setDefaultGeneralcCsr|jr|jSi}xtjj�D]\}}|||<qW|j�|_x2|j�D]&\}}tjj|�}||krD||j|<qDWdS)N)r.r-r�__dict__�items�_loadUserCustomizationsr?)r/ZoriginalSettingsrMrNZcustomValuerrrrK�s
z&SettingsManager._getCustomizedSettingscCs�d}|jg}y6d}tjd|�\}}}|d|7}tjd|||�Wn2tk
rbd}|d7}Yn(tk
rtdSX|d7}|j�d}tjtj	|d�|S)z�Attempt to load the user's orca-customizations. Returns a boolean
        indicating our success at doing so, where success is measured by the
        likelihood that the results won't be different if we keep trying.Fz6SETTINGS MANAGER: Attempt to load orca-customizations zorca-customizationszfrom %s Tz%failed due to ImportError. Giving up.z
succeeded.)
r�imp�find_module�load_module�ImportError�AttributeErrorrHrrZ	LEVEL_ALL)r/�successZpathList�msgZfileHndZ
moduleNameZdescrrrrQ�s"z'SettingsManager._loadUserCustomizationscCs|jS)N)r)r/rrr�getPrefsDir
szSettingsManager.getPrefsDircCs|j||i�dS)N)�_setSettingsRuntime)r/�settingNameZsettingValuerrr�
setSetting
szSettingsManager.setSettingcCstt|d�S)N)rLr)r/r[rrr�
getSettingszSettingsManager.getSetting�defaultcCsR|jd�}t|j|i��}|j�}|j�}|rNtt|��dkrNd||j�f}|S)N�voices�z%s_%s)r]r
r?Z	getLocaleZ
getDialect�len�str�upper)r/Zvoicer_�vZlangZdialectrrr�getVoiceLocales
zSettingsManager.getVoiceLocalecCsB|dkr|j}|j|�pi|_|j|�p*i|_|j|�p:i|_dS)z�Get from the active backend all the settings for the current
        profile and store them in the object's attributes.
        A profile can be passed as a parameter. This could be useful for
        change from one profile to another.N)r�getGeneralSettingsr!�getPronunciationsr"�getKeybindingsr#)r/rrrr�_loadProfileSettingss
z$SettingsManager._loadProfileSettingscCsX|jj|j�|jj|j�|jj|j�|jj|j�|jj|j�|j	j|j�dS)z^Update the changed values on the profile settings
        over the current and active settingsN)
r!r4r(r"r)r#r*r$r%r&)r/rrr�_mergeSettings'szSettingsManager._mergeSettingscCs|j�}|s|jd�|S)z�Enables the GNOME accessibility flag.  Users need to log out and
        then back in for this to take effect.

        Returns True if an action was taken (i.e., accessibility was not
        set prior to this call).
        T)�isAccessibilityEnabled�setAccessibility)r/ZalreadyEnabledrrr�_enableAccessibility2s
z$SettingsManager._enableAccessibilitycCstsdStjddd�S)NFz(ss)zorg.a11y.Status�	IsEnabled)�_proxy�Get)r/rrrrk@sz&SettingsManager.isAccessibilityEnabledcCs(tsdStjd|�}tjddd|�dS)NF�bz(ssv)zorg.a11y.Statusrn)rorZVariant�Set)r/�enableZvEnablerrrrlFsz SettingsManager.setAccessibilitycCstsdStjddd�S)z�Returns True if the screen reader service is enabled. Note that
        this does not necessarily mean that Orca (or any other screen reader)
        is running at the moment.Fz(ss)zorg.a11y.StatusZScreenReaderEnabled)rorp)r/rrr�isScreenReaderServiceEnabledMsz,SettingsManager.isScreenReaderServiceEnabledcCs |dkrtj}|jjd|�dS)Nr3)rrrZ_setProfileKey)r/rrrr�setStartingProfileWsz"SettingsManager.setStartingProfilecCs|jS)N)r)r/rrr�
getProfile\szSettingsManager.getProfileFcCsj|jd�}||_|j|�|j�|j|j�|s6dS|jd�}||krftj|�tj|�tj	|�dS)z�Set a specific profile as the active one.
        Also the settings from that profile will be loading
        and updated the current settings with them.r^N)
rerrirjrZr$rZsetLocaleForNamesZsetLocaleForMessagesZsetLocaleForGUI)r/rZupdateLocaleZoldVoiceLocaleZnewVoiceLocalerrrr@_s




zSettingsManager.setProfilecCsZx$|j�D]\}}ttt|�|�q
W|j�x&|jj�D]\}}ttt|�|�q:WdS)N)rP�setattrrrbrKr-)r/ZsettingsDictrMrNrrrrZts
z#SettingsManager._setSettingsRuntimecCs4it_x(|j�D]\}}|r|rtj||�qWdS)N)r	�valuesZsetPronunciation)r/ZpronunciationsDictrMrNrrr�_setPronunciationsRuntime{sz)SettingsManager._setPronunciationsRuntimecCs|jj|�S)z�Return the current general settings.
        Those settings comes from updating the default settings
        with the profiles' ones)rr=)r/rrrrrf�sz"SettingsManager.getGeneralSettingscCs|jj|�S)z�Return the current pronunciations settings.
        Those settings comes from updating the default settings
        with the profiles' ones)rrg)r/rrrrrg�sz!SettingsManager.getPronunciationscCs|jj|�S)z�Return the current keybindings settings.
        Those settings comes from updating the default settings
        with the profiles' ones)rrh)r/rrrrrh�szSettingsManager.getKeybindingscCsvi|_xj|j�D]^\}}|dkr$qq|dkr8||j|<q||jj|�krT||j|<q|jj|�|kr||j|<qWdS)zRSet the changed general settings from the defaults' ones
        as the profile's.r3�
activeProfilerN)r3rz)r!rPrr?r$)r/r$rMrNrrr�_setProfileGeneral�sz"SettingsManager._setProfileGeneralcCs|jj�|_|jj|�dS)zYSet the changed pronunciations settings from the defaults' ones
        as the profile's.N)rr;r"r4)r/r%rrr�_setProfilePronunciations�sz)SettingsManager._setProfilePronunciationscCs|jj�|_|jj|�dS)zVSet the changed keybindings settings from the defaults' ones
        as the profile's.N)r r;r#r4)r/r&rrr�_setProfileKeybindings�sz&SettingsManager._setProfileKeybindingsc
Cs�i}|j|j�}x*|j�D]\}}||j|�kr|||<qWi}	|j|j�}
x*|j�D]\}}||
j|�krV||	|<qVWi}|j|j�}x*|j�D]\}}||j|�kr�|||<q�W|jj||j||	|�dS)N)rfrrPr?rgrhrZsaveAppSettings)
r/ZappNamer$r%r&Z
appGeneralr!rMrNZappPronunciationsr"ZappKeybindingsr#rrr�_saveAppSettings�s(z SettingsManager._saveAppSettingscCs�|j}|r |j|j|||�dS|jdtj�}|d}||_|jd|�|jd<|j|�|j|�|j	|�|j
j|j|j|j
|j�|j�S)z3Save the settings provided for the script provided.Nrrr3)�appr~�namer?rrrr{r|r}rZsaveProfileSettingsr!r"r#rm)r/�scriptr$r%r&rZ_profileZcurrentProfilerrr�saveSettings�s"



zSettingsManager.saveSettingscCs2|\}}}}|sd}n|t|�t|�t|�f}|S)zAConverts the values of bindingTuple into KeyBinding-ready values.rr)rrrr)�int)r/�bindingTuple�keysym�mask�mods�clicksrrr�_adjustBindingTupleValues�s
z)SettingsManager._adjustBindingTupleValuesc
Csz|j}xn|j�D]b\}}|jj|�}|s*q|j|�x<|D]4}|j|�}|\}}	}
}t||	|
||�}|j|�q:WqW|S)N)r#rPZinputEventHandlersr?ZremoveByHandlerr�r�add)
r/r�ZscriptKeyBindingsZkeybindingsSettingsZ
handlerStringZ
bindingTuplesZhandlerr�r�r�r�r�Z
newBindingrrr�overrideKeyBindings�s


z#SettingsManager.overrideKeyBindingscCs
|jj�S)z,Check if the firstStart key is True or false)rr<)r/rrrr<�szSettingsManager.isFirstStartcCs|jj|�dS)z�Set firstStart. This user-configurable settting is primarily
        intended to serve as an indication as to whether or not initial
        configuration is needed.N)r�
setFirstStart)r/rNrrrr�szSettingsManager.setFirstStartcCs
|jj�S)z*Get available profiles from active backend)r�availableProfiles)r/rrrr�sz!SettingsManager.availableProfilesTc	Csn|sdS|jj|j�}|jdi�}|j|ji�}|jdi�}|j|�}|dkrj|rj|jj|j�}|j|�}|S)N�profilesr$)r�getAppSettingsr�r?rr=)	r/rr[ZfallbackOnDefaultZappPrefsr��profilePrefsr$Z
appSettingrrr�
getAppSetting
s

zSettingsManager.getAppSettingcCs�|o|jsdSx|jj�D]}|jj|�qW|jj|jj�}|jdi�}|j|j	i�}|jdi�|_
|jdi�|_|jdi�|_|jj|_|j
�|j�|j|j�|j|j�|j||j��|_dS)z�Load the users application specific settings for an app.

        Arguments:
        - script: the current active script.
        Nr�r$r&r%)rr)�keysr%�poprr�r�r?rr(r*r'rirjrZr$ryr�ZgetKeyBindingsZkeyBindings)r/r�rMZprefsr�r�rrr�loadAppSettingss 

zSettingsManager.loadAppSettings)r)r^)N)N)r^F)r^)r^)r^)F)T)-�__name__�
__module__�__qualname__�__doc__Z	_instancerr1rAr+r>r9r:r8rKrQrYr\r]rerirjrmrkrlrtrurvr@rZryrfrgrhr{r|r}r~r�r�r�r<r�r�r�r�rrrrr:sT
5
+

	








rcCstS)N)�_managerrrrr�
getManager:sr�)"r�Z__id__�__version__Z__date__Z
__copyright__Z__license__rRrBr5Z
gi.repositoryrrrrrrrr	Zacssr
r&rZ	DBusProxyZnew_for_bus_syncZBusTypeZSESSIONZDBusProxyFlagsZNONEror�Z_scriptManagerrrr�rrrr�<module>sF