소스 검색

wxGUI: fix settings when item added to settings but it doesn't exist yet locally (#1811)

Anna Petrasova 3 년 전
부모
커밋
3ad82d314f
1개의 변경된 파일12개의 추가작업 그리고 1개의 파일을 삭제
  1. 12 1
      gui/wxpython/core/settings.py

+ 12 - 1
gui/wxpython/core/settings.py

@@ -26,6 +26,7 @@ import sys
 import copy
 import wx
 import json
+import collections.abc
 
 from core import globalvar
 from core.gcmd import GException, GError
@@ -900,9 +901,19 @@ class Settings:
 
         :param settings: dict where to store settings (None for self.userSettings)
         """
+
+        def update_nested_dict_by_dict(dictionary, update):
+            """Recursively update nested dictionary by another nested dictionary"""
+            for key, value in update.items():
+                if isinstance(value, collections.abc.Mapping):
+                    update_nested_dict_by_dict(dictionary.get(key, {}), value)
+                else:
+                    dictionary[key] = value
+
         try:
             with open(self.filePath, "r") as f:
-                settings.update(json.load(f, object_hook=settings_JSON_decode_hook))
+                update = json.load(f, object_hook=settings_JSON_decode_hook)
+                update_nested_dict_by_dict(settings, update)
         except json.JSONDecodeError as e:
             sys.stderr.write(
                 _("Unable to read settings file <{path}>:\n{err}").format(