From 0ad262fd9e64f9c662b950fbc567c2e59058c4f7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gerardo=20K=C3=A9ssler?= Date: Thu, 14 Jul 2022 13:45:43 -0300 Subject: [PATCH] Configuraciones modificadas para funcionar desde NVDA --- addon/appModules/unigram.py | 80 +++++++++++++++++++++---------------- 1 file changed, 46 insertions(+), 34 deletions(-) diff --git a/addon/appModules/unigram.py b/addon/appModules/unigram.py index 1a3d9cf..065a72f 100644 --- a/addon/appModules/unigram.py +++ b/addon/appModules/unigram.py @@ -8,6 +8,7 @@ from globalCommands import commands import api from scriptHandler import script, getLastScriptRepeatCount +import config from pickle import dump, load import os import appModuleHandler @@ -25,6 +26,25 @@ # Lína de traducción addonHandler.initTranslation() +# Funciones de lectura y escritura de las configuraciones del complemento +def initConfiguration(): + confspec = { + 'AnnounceProgressBars': 'boolean(default=False)', + 'AudioRecords': 'boolean(default=True)' + } + config.conf.spec['unigram'] = confspec + +def getConfig(key): + return config.conf["unigram"][key] + +def setConfig(key, value): + try: + config.conf.profiles[0]["unigram"][key] = value + except: + config.conf["unigram"][key] = value + +initConfiguration() + getRole = lambda attr: getattr(controlTypes, f'ROLE_{attr}') if hasattr(controlTypes, 'ROLE_BUTTON') else getattr(controlTypes.Role, attr) def speak(time, msg= False): @@ -53,17 +73,9 @@ def __init__(self, *args, **kwargs): self.recordObj = None self.fgObject = None # Translators: Mensaje que anuncia la disponibilidad solo desde la lista de mensajes + self.audioRecords = getConfig('AudioRecords') + self.announceProgressBars = getConfig('AnnounceProgressBars') self.errorMessage = _('Solo disponible desde la lista de mensajes') - self.settings = None - self.configFile() - - def configFile(self): - try: - with open(os.path.join(appArgs.configPath, 'unigram'), 'rb') as f: - self.settings = load(f) - except FileNotFoundError: - with open(os.path.join(appArgs.configPath, 'unigram'), 'wb') as f: - dump({'record': 'True', 'progress': 'False'}, f) def searchList(self): self.fgObject = api.getForegroundObject() @@ -78,10 +90,10 @@ def searchList(self): pass def event_valueChange(self, obj, nextHandler): - if self.settings['progress'] == 'False': - return - else: + if self.announceProgressBars: nextHandler() + else: + return def event_gainFocus(self, obj, nextHandler): try: @@ -305,7 +317,7 @@ def finish(self): @script(gesture='kb:control+r') def script_voiceMessage(self, gesture): - if self.settings['record'] == 'False': + if not self.audioRecords: gesture.send() return self.focusObj = api.getFocusObject() @@ -336,16 +348,16 @@ def script_voiceMessage(self, gesture): gesture='kb:control+shift+r' ) def script_recordConfig(self, gesture): - self.configFile() - with open(os.path.join(appArgs.configPath, 'unigram'), 'wb') as f: - if self.settings['record'] == 'True': - dump({'record': 'False', 'progress': self.settings['progress']}, f) - self.settings['record'] = 'False' - message(_('mensajes de voz por defecto')) - else: - dump({'record': 'True', 'progress': self.settings['progress']}, f) - self.settings['record'] = 'True' - message(_('mensajes de voz del complemento')) + if self.audioRecords: + setConfig('AudioRecords', False) + self.audioRecords = False + # Translators: Anuncia el tipo de grabación por defecto + message(_('mensajes de voz por defecto')) + else: + setConfig('AudioRecords', True) + self.audioRecords = True + # Translators: Anuncia la grabación de mensajes del complemento + message(_('mensajes de voz del complemento')) @script( category=category, @@ -354,16 +366,16 @@ def script_recordConfig(self, gesture): gesture='kb:control+shift+b' ) def script_progressConfig(self, gesture): - self.configFile() - with open(os.path.join(appArgs.configPath, 'unigram'), 'wb') as f: - if self.settings['progress'] == 'True': - dump({'record': self.settings['record'], 'progress': 'False'}, f) - self.settings['progress'] = 'False' - message(_('Barras de progreso desactivadas')) - else: - dump({'record': self.settings['record'], 'progress': 'True'}, f) - self.settings['progress'] = 'True' - message(_('Barras de progreso activadas')) + if self.announceProgressBars: + setConfig('AnnounceProgressBars', False) + self.announceProgressBars = False + # Translators: Anuncia la desactivación del anunciado de las barras de progreso + message(_('Barras de progreso desactivadas')) + else: + setConfig('AnnounceProgressBars', True) + self.announceProgressBars = True + # Translators: Anuncia la activación del anunciado de las barras de progreso + message(_('Barras de progreso activadas')) @script(gesture='kb:control+d') def script_cancelVoiceMessage(self, gesture):