aboutsummaryrefslogtreecommitdiff
path: root/modules/shared.py
diff options
context:
space:
mode:
authorAUTOMATIC <16777216c@gmail.com>2022-09-23 09:15:00 +0300
committerAUTOMATIC <16777216c@gmail.com>2022-09-23 09:15:00 +0300
commit7ef361dfc3442956d5dbbf9e702445c0d452d38d (patch)
tree52effafed6a0ad7b108453c6b00d307f2d9a06b8 /modules/shared.py
parentc82e32652e589a556b0477d484b6f58d13c652b1 (diff)
add warning for when user's settings are broken
Diffstat (limited to 'modules/shared.py')
-rw-r--r--modules/shared.py21
1 files changed, 21 insertions, 0 deletions
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