diff --git a/Drone/client.py b/Drone/client.py index 43f9b74..73a6188 100644 --- a/Drone/client.py +++ b/Drone/client.py @@ -170,7 +170,6 @@ class Client(object): while True: #self.server_connection.send_message("telemetry", kwargs={"value":{"time": time.time()}}) events = self.selector.select(timeout=1) - for key, mask in events: connection = key.data if connection is not None: @@ -217,7 +216,7 @@ def _command_config_write(*args, **kwargs): @messaging.request_callback("config") def _response_config(*args, **kwargs): - response = {"config": active_client.config.full_dict, + response = {"config": active_client.config.full_dict(), "configspec": dict(active_client.config.config.configspec)} return response diff --git a/Server/config_editor_models.py b/Server/config_editor_models.py index b12627c..eb7aeff 100644 --- a/Server/config_editor_models.py +++ b/Server/config_editor_models.py @@ -773,7 +773,7 @@ class ConfigDialog(QtWidgets.QDialog): cfg = config.ConfigManager() cfg.load_from_dict(config_dict, spec_dict) - self.setupModel(config_dict) + self.setupModel(cfg.full_dict(include_defaults=True)) if not self.validation_loop(cfg, spec_dict): return False @@ -799,7 +799,7 @@ class ConfigDialog(QtWidgets.QDialog): "Config cannot be opened or validated: {}".format(error)) return False - self.setupModel(cfg.full_dict, convert_types=(not cfg.validated)) + self.setupModel(cfg.full_dict(include_defaults=True), convert_types=(not cfg.validated)) self.ui.do_restart.setDisabled(True) filename = cfg.config.filename diff --git a/Server/server_qt.py b/Server/server_qt.py index 862741c..8292258 100644 --- a/Server/server_qt.py +++ b/Server/server_qt.py @@ -462,7 +462,7 @@ class MainWindow(QtWidgets.QMainWindow): config = cfg.ConfigManager() config.load_only_config(path) - data = config.full_dict + data = config.full_dict() logging.info(f"Loaded config from {path}") copters = self.model.user_selected() diff --git a/config.py b/config.py index f3e8e81..f5ade20 100644 --- a/config.py +++ b/config.py @@ -92,7 +92,7 @@ class ConfigManager: self.validated = True @classmethod - def _full_dict(cls, item): + def _full_dict(cls, item, include_defaults=False): if not isinstance(item, Section): return item @@ -103,15 +103,17 @@ class ConfigManager: inline_comments = item.inline_comments for key, value in item.items(): - result = cls._full_dict(value) + result = cls._full_dict(value, include_defaults) if not isinstance(result, dict): item_d = {'__option__': True, 'value': value, - 'default': default_values.get(key, None), - 'unchanged': key in defaults, 'comments': comments.get(key, []), 'inline_comment': inline_comments.get(key, None), } + if include_defaults: + item_d.update({'default': default_values.get(key, None), + 'unchanged': key in defaults, + }) data[key] = item_d else: @@ -119,9 +121,8 @@ class ConfigManager: return data - @property - def full_dict(self): - d = self._full_dict(self.config) + def full_dict(self, include_defaults=False): + d = self._full_dict(self.config, include_defaults=include_defaults) d['initial_comment'] = self.config.initial_comment d['final_comment'] = self.config.final_comment return d @@ -322,7 +323,7 @@ if __name__ == '__main__': #pprint.pprint(cfg2.full_dict) cfg.merge(cfg2) #pprint.pprint(cfg.full_dict) - print(cfg.full_dict) + print(cfg.full_dict(include_defaults=True)) print(dict(cfg.config.configspec)) #print(dict(ConfigManager(cfg.config.configspec).config))