config: fix menu and preheat merge bugs
it's now possible to define a custom menu without the need to copy all the menu entries from defaults.conf if you want to define all the entries, disable the default menu with 'use_default_menu: False' under [main] if a preheat is defined then defaults are dropped in favor of keeping only user defines, this behaviour has not changed, and it's intended since the user may not want any of the defaults; but it's now possible to put preheat options in an include file. fixes #530 fixes #497 fixes #408
This commit is contained in:
parent
64ebf861fb
commit
bc34b3c8d6
@ -39,6 +39,11 @@ service: KlipperScreen
|
||||
|
||||
# If multiple printers are defined, this can be set the name of the one to show at startup.
|
||||
default_printer: Ender 3 Pro
|
||||
|
||||
# To define a full set of custom menues (instead of merging user entries with default entries)
|
||||
# set this to False. See Menu section below.
|
||||
use_default_menu: True
|
||||
|
||||
```
|
||||
|
||||
## Printer Options
|
||||
@ -178,8 +183,9 @@ KlipperScreen will search for a configuration file in the following order:
|
||||
If you need a custom location for the configuration file, you can add -c or --configfile to the systemd file and specify
|
||||
the location of your configuration file.
|
||||
|
||||
If one of those files are found, it will be used over the default configuration. The default configuration will be
|
||||
merged with the custom configuration, so if you do not define any menus the default menus will be used.
|
||||
If one of those files are found, it will be merged with the default configuration.
|
||||
Default Preheat options will be discarded if a custom preheat is found.
|
||||
If include files are defined then, they will be merged first.
|
||||
|
||||
The default config is included here: (do not edit use as reference)
|
||||
_${KlipperScreen_Directory}/ks_includes/default.conf_
|
||||
|
@ -49,19 +49,15 @@ class KlipperScreenConfig:
|
||||
for include in includes:
|
||||
self._include_config("/".join(self.config_path.split("/")[:-1]), include)
|
||||
|
||||
for i in ['menu __main', 'menu __print', 'menu __splashscreen', 'preheat']:
|
||||
for j in self.defined_config.sections():
|
||||
if j.startswith(i):
|
||||
for k in list(self.config.sections()):
|
||||
if k.startswith(i):
|
||||
del self.config[k]
|
||||
break
|
||||
self.exclude_from_config(self.defined_config)
|
||||
|
||||
self.log_config(self.defined_config)
|
||||
self.config.read_string(user_def)
|
||||
if saved_def is not None:
|
||||
self.config.read_string(saved_def)
|
||||
logging.info("====== Saved Def ======\n%s\n=======================" % saved_def)
|
||||
# This is the final config
|
||||
# self.log_config(self.config)
|
||||
except KeyError:
|
||||
raise ConfigError(f"Error reading config: {self.config_path}")
|
||||
except Exception:
|
||||
@ -196,6 +192,20 @@ class KlipperScreenConfig:
|
||||
if name not in list(self.config[vals['section']]):
|
||||
self.config.set(vals['section'], name, vals['value'])
|
||||
|
||||
def exclude_from_config(self, config):
|
||||
exclude_list = ['preheat']
|
||||
if not self.defined_config.getboolean('main', "use_default_menu", fallback=True):
|
||||
logging.info("Using custom menu, removing default menu entries.")
|
||||
exclude_list.append('menu __main')
|
||||
exclude_list.append('menu __print')
|
||||
exclude_list.append('menu __splashscreen')
|
||||
for i in exclude_list:
|
||||
for j in config.sections():
|
||||
if j.startswith(i):
|
||||
for k in list(self.config.sections()):
|
||||
if k.startswith(i):
|
||||
del self.config[k]
|
||||
|
||||
def _include_config(self, dir, path):
|
||||
full_path = path if path[0] == "/" else "%s/%s" % (dir, path)
|
||||
parse_files = []
|
||||
@ -224,8 +234,9 @@ class KlipperScreenConfig:
|
||||
includes = [i[8:] for i in config.sections() if i.startswith("include ")]
|
||||
for include in includes:
|
||||
self._include_config("/".join(full_path.split("/")[:-1]), include)
|
||||
self.exclude_from_config(config)
|
||||
self.log_config(config)
|
||||
self.config.read(file)
|
||||
self.defined_config.read(file)
|
||||
|
||||
def separate_saved_config(self, config_path):
|
||||
user_def = []
|
||||
|
Loading…
x
Reference in New Issue
Block a user