From 7ef361dfc3442956d5dbbf9e702445c0d452d38d Mon Sep 17 00:00:00 2001 From: AUTOMATIC <16777216c@gmail.com> Date: Fri, 23 Sep 2022 09:15:00 +0300 Subject: [PATCH] add warning for when user's settings are broken --- modules/shared.py | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/modules/shared.py b/modules/shared.py index 7befbdcf..f30bef02 100644 --- a/modules/shared.py +++ b/modules/shared.py @@ -248,6 +248,27 @@ class Options: with open(filename, "r", encoding="utf8") as file: self.data = json.load(file) + typemap = {int: float} + + def same_type(x, y): + if x is None or y is None: + return True + + type_x = typemap.get(type(x), type(x)) + type_y = typemap.get(type(y), type(y)) + + return type_x == type_y + + bad_settings = 0 + for k, v in self.data.items(): + info = self.data_labels.get(k, None) + if info is not None and not same_type(info.default, v): + print(f"Warning: bad setting value: {k}: {v} ({type(v).__name__}; expected {type(info.default).__name__})", file=sys.stderr) + bad_settings += 1 + + if bad_settings > 0: + print(f"The program is likely to not work with bad settings.\nSettings file: {filename}\nEither fix the file, or delete it and restart.", file=sys.stderr) + def onchange(self, key, func): item = self.data_labels.get(key) item.onchange = func