aboutsummaryrefslogtreecommitdiffstats
path: root/klippy/configfile.py
diff options
context:
space:
mode:
authorKevin O'Connor <kevin@koconnor.net>2021-08-25 10:36:45 -0400
committerKevin O'Connor <kevin@koconnor.net>2021-08-25 10:36:45 -0400
commit84ac5b0146cbcec46419d4636b949f144992072e (patch)
tree81aaefd6ea5f939b9ad23935bdfbfaf4eefcb3b3 /klippy/configfile.py
parent75183bfb86c7003d3bac0116dba7765e4a4ab241 (diff)
downloadkutter-84ac5b0146cbcec46419d4636b949f144992072e.tar.gz
kutter-84ac5b0146cbcec46419d4636b949f144992072e.tar.xz
kutter-84ac5b0146cbcec46419d4636b949f144992072e.zip
configfile: Support config.getchoice() with integer keys
If the choice mapping uses integer keys then lookup the config option using self.getint(). This simplifies the callers and improves the encoding of the printer.configfile.settings export. Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
Diffstat (limited to 'klippy/configfile.py')
-rw-r--r--klippy/configfile.py5
1 files changed, 4 insertions, 1 deletions
diff --git a/klippy/configfile.py b/klippy/configfile.py
index d6fd8beb..c24cfe16 100644
--- a/klippy/configfile.py
+++ b/klippy/configfile.py
@@ -69,7 +69,10 @@ class ConfigWrapper:
return self._get_wrapper(self.fileconfig.getboolean, option, default,
note_valid=note_valid)
def getchoice(self, option, choices, default=sentinel, note_valid=True):
- c = self.get(option, default, note_valid=note_valid)
+ if choices and type(list(choices.keys())[0]) == int:
+ c = self.getint(option, default, note_valid=note_valid)
+ else:
+ c = self.get(option, default, note_valid=note_valid)
if c not in choices:
raise error("Choice '%s' for option '%s' in section '%s'"
" is not a valid choice" % (c, option, self.section))