
# HG changeset patch # User Tom Hayward tom@tomh.us # Date 1417908731 28800 # Sat Dec 06 15:32:11 2014 -0800 # Node ID 9d504f2619b345da0735dbbb34cf9f8d02c3c17b # Parent d10199843d9fcd169738dffbe028cc56feef40e7 Add bool cast and improve charset options in settings. For #2095
Previously, tests could not be done on RadioSettingValueBoolean values. This patch adds bool casting / test support so that checked boxes test True and unchecked boxes test False.
RadioSettingValueString supported setting the charset, but only after initializing the value. This fails if the value contains characters not in the default charset. With this patch, the charset can be set during initialization, so when the value is set, it is tested against the appropriate charset.
diff -r d10199843d9f -r 9d504f2619b3 chirp/settings.py --- a/chirp/settings.py Sat Dec 06 15:31:47 2014 -0800 +++ b/chirp/settings.py Sat Dec 06 15:32:11 2014 -0800 @@ -143,6 +143,10 @@ def set_value(self, value): RadioSettingValue.set_value(self, bool(value))
+ def __bool__(self): + return bool(self.get_value()) + __nonzero__ = __bool__ + def __str__(self): return str(bool(self.get_value()))
@@ -168,11 +172,11 @@ class RadioSettingValueString(RadioSettingValue): """A string setting""" def __init__(self, minlength, maxlength, current, - autopad=True): + autopad=True, charset=chirp_common.CHARSET_ASCII): RadioSettingValue.__init__(self) self._minlength = minlength self._maxlength = maxlength - self._charset = chirp_common.CHARSET_ASCII + self._charset = charset self._autopad = autopad self.set_value(current)