add better value handling
This commit is contained in:
parent
87c987ab4c
commit
0059fedd3c
@ -5,11 +5,14 @@
|
|||||||
# By Chrys, Storm Dragon, and contributers.
|
# By Chrys, Storm Dragon, and contributers.
|
||||||
|
|
||||||
from fenrirscreenreader.core import debug
|
from fenrirscreenreader.core import debug
|
||||||
|
from fenrirscreenreader.core.settingsData import settingsData
|
||||||
|
|
||||||
class quickMenuManager():
|
class quickMenuManager():
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
self.position = 0
|
self.position = 0
|
||||||
self.quickMenu = []
|
self.quickMenu = []
|
||||||
|
self.settings = settingsData
|
||||||
|
|
||||||
def initialize(self, environment):
|
def initialize(self, environment):
|
||||||
self.env = environment
|
self.env = environment
|
||||||
self.loadMenu(self.env['runtime']['settingsManager'].getSetting('menu', 'quickMenu'))
|
self.loadMenu(self.env['runtime']['settingsManager'].getSetting('menu', 'quickMenu'))
|
||||||
@ -25,6 +28,11 @@ class quickMenuManager():
|
|||||||
entry = e.split('#')
|
entry = e.split('#')
|
||||||
if len(entry) != 2:
|
if len(entry) != 2:
|
||||||
continue
|
continue
|
||||||
|
try:
|
||||||
|
t = self.settings[entry[0]][entry[1]]
|
||||||
|
except:
|
||||||
|
print(entry[0],entry[1], 'not found')
|
||||||
|
continue
|
||||||
self.quickMenu.append({'section': entry[0], 'setting': entry[1]})
|
self.quickMenu.append({'section': entry[0], 'setting': entry[1]})
|
||||||
def nextEntry(self):
|
def nextEntry(self):
|
||||||
if len(self.quickMenu) == 0:
|
if len(self.quickMenu) == 0:
|
||||||
@ -43,48 +51,67 @@ class quickMenuManager():
|
|||||||
def nextValue(self):
|
def nextValue(self):
|
||||||
if len(self.quickMenu) == 0:
|
if len(self.quickMenu) == 0:
|
||||||
return False
|
return False
|
||||||
|
section = self.quickMenu[self.position]['section']
|
||||||
|
setting = self.quickMenu[self.position]['setting']
|
||||||
|
valueString = ''
|
||||||
try:
|
try:
|
||||||
valueString = self.env['runtime']['settingsManager'].getSetting(self.quickMenu[self.position]['section'], self.quickMenu[self.position]['setting'])
|
valueString = self.env['runtime']['settingsManager'].getSetting(self.quickMenu[self.position]['section'], self.quickMenu[self.position]['setting'])
|
||||||
except:
|
except:
|
||||||
return False
|
return False
|
||||||
# bool
|
|
||||||
if valueString.upper() in ['TRUE', 'FALSE']:
|
|
||||||
value = valueString.upper() == 'TRUE'
|
|
||||||
value = not value
|
|
||||||
self.env['runtime']['settingsManager'].setSettingAsBool(self.quickMenu[self.position]['section'], self.quickMenu[self.position]['setting'], value)
|
|
||||||
return True
|
|
||||||
# float
|
|
||||||
try:
|
try:
|
||||||
|
if isinstance(self.settings[section][setting], str):
|
||||||
|
value = str(valueString)
|
||||||
|
return False
|
||||||
|
elif isinstance(self.settings[section][setting], bool):
|
||||||
|
if not valueString in ['True','False']:
|
||||||
|
return False
|
||||||
|
value = not value
|
||||||
|
self.env['runtime']['settingsManager'].setSettingAsBool(section, setting, value)
|
||||||
|
elif isinstance(self.settings[section][setting], int):
|
||||||
|
value = int(valueString)
|
||||||
|
value += 1
|
||||||
|
self.env['runtime']['settingsManager'].setSettingAsInt(section, setting, value)
|
||||||
|
elif isinstance(self.settings[section][setting], float):
|
||||||
value = float(valueString)
|
value = float(valueString)
|
||||||
value += 0.05
|
value += 0.05
|
||||||
if value > 1.0:
|
if value > 1.0:
|
||||||
value = 1.0
|
value = 1.0
|
||||||
self.env['runtime']['settingsManager'].setSettingAsFloat(self.quickMenu[self.position]['section'], self.quickMenu[self.position]['setting'], value)
|
self.env['runtime']['settingsManager'].setSettingAsFloat(section, setting, value)
|
||||||
return True
|
|
||||||
except:
|
except:
|
||||||
return False
|
return False
|
||||||
return True
|
return True
|
||||||
def prevValue(self):
|
def prevValue(self):
|
||||||
if len(self.quickMenu) == 0:
|
if len(self.quickMenu) == 0:
|
||||||
return False
|
return False
|
||||||
|
section = self.quickMenu[self.position]['section']
|
||||||
|
setting = self.quickMenu[self.position]['setting']
|
||||||
|
valueString = ''
|
||||||
try:
|
try:
|
||||||
valueString = self.env['runtime']['settingsManager'].getSetting(self.quickMenu[self.position]['section'], self.quickMenu[self.position]['setting'])
|
valueString = self.env['runtime']['settingsManager'].getSetting(section, setting)
|
||||||
except:
|
except:
|
||||||
return False
|
return False
|
||||||
# bool
|
|
||||||
if valueString.upper() in ['TRUE', 'FALSE']:
|
|
||||||
value = valueString.upper() == 'TRUE'
|
|
||||||
value = not value
|
|
||||||
self.env['runtime']['settingsManager'].setSettingAsBool(self.quickMenu[self.position]['section'], self.quickMenu[self.position]['setting'], value)
|
|
||||||
return True
|
|
||||||
# float
|
|
||||||
try:
|
try:
|
||||||
|
if isinstance(self.settings[section][setting], str):
|
||||||
|
value = str(valueString)
|
||||||
|
return False
|
||||||
|
elif isinstance(self.settings[section][setting], bool):
|
||||||
|
if not valueString in ['True','False']:
|
||||||
|
return False
|
||||||
|
value = not value
|
||||||
|
self.env['runtime']['settingsManager'].setSettingAsBool(section, setting, value)
|
||||||
|
elif isinstance(self.settings[section][setting], int):
|
||||||
|
value = int(valueString)
|
||||||
|
value -= 1
|
||||||
|
if value < 0:
|
||||||
|
value = 0
|
||||||
|
self.env['runtime']['settingsManager'].setSettingAsInt(section, setting, value)
|
||||||
|
elif isinstance(self.settings[section][setting], float):
|
||||||
value = float(valueString)
|
value = float(valueString)
|
||||||
value -= 0.05
|
value -= 0.05
|
||||||
if value < 0.0:
|
if value < 0.0:
|
||||||
value = 0
|
value = 0.0
|
||||||
self.env['runtime']['settingsManager'].setSettingAsFloat(self.quickMenu[self.position]['section'], self.quickMenu[self.position]['setting'], value)
|
self.env['runtime']['settingsManager'].setSettingAsFloat(section, setting, value)
|
||||||
return True
|
|
||||||
except:
|
except:
|
||||||
return False
|
return False
|
||||||
return True
|
return True
|
||||||
@ -102,4 +129,3 @@ class quickMenuManager():
|
|||||||
return self.env['runtime']['settingsManager'].getSetting(self.quickMenu[self.position]['section'], self.quickMenu[self.position]['setting'])
|
return self.env['runtime']['settingsManager'].getSetting(self.quickMenu[self.position]['section'], self.quickMenu[self.position]['setting'])
|
||||||
except:
|
except:
|
||||||
return _('setting value invalid')
|
return _('setting value invalid')
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user