diff --git a/docs/Installation.md b/docs/Installation.md index e831d484..a02ad5cd 100644 --- a/docs/Installation.md +++ b/docs/Installation.md @@ -38,3 +38,6 @@ python virtual environment at ${HOME}/.KlipperScreen-env and install a systemd service file. As an option to do development or interact with KlipperScreen from your computer, you may install tigervnc-scraping-server and VNC to your pi instance. Follow tigervnc server setup procedures for details on how to do that. + +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. diff --git a/docs/changelog.md b/docs/changelog.md index 0006c312..a6c00faa 100644 --- a/docs/changelog.md +++ b/docs/changelog.md @@ -1,5 +1,8 @@ ## Changelog +#### 2020 12 16 +* Config file can now be specified when running from the command line + #### 2020 12 09 * Z value in job status now reflects the gcode Z value. This allows people with ABL to have a better understanding of Z diff --git a/ks_includes/config.py b/ks_includes/config.py index a8dd1da0..3e8ae778 100644 --- a/ks_includes/config.py +++ b/ks_includes/config.py @@ -16,10 +16,10 @@ class KlipperScreenConfig: config = None configfile_name = "KlipperScreen.conf" - def __init__(self): + def __init__(self, configfile): self.default_config_path = "%s/ks_includes/%s" % (os.getcwd(), self.configfile_name) self.config = configparser.ConfigParser() - self.config_path = self.get_config_file_location() + self.config_path = self.get_config_file_location(configfile) try: self.config.read(self.default_config_path) @@ -32,8 +32,7 @@ class KlipperScreenConfig: self.get_menu_items("__main") #self.build_main_menu(self.config) - def get_config_file_location(self): - file = "%s/%s" % (os.getenv("HOME"), self.configfile_name) + def get_config_file_location(self, file): if not path.exists(file): file = "%s/%s" % (os.getcwd(), self.configfile_name) if not path.exists(file): diff --git a/screen.py b/screen.py index 7ffafc7f..9bf3bdc1 100644 --- a/screen.py +++ b/screen.py @@ -1,5 +1,6 @@ #!/usr/bin/python +import argparse import gi import gettext import time @@ -65,7 +66,17 @@ class KlipperScreen(Gtk.Window): def __init__(self): self.version = get_software_version() logger.info("KlipperScreen version: %s" % self.version) - self._config = KlipperScreenConfig() + + parser = argparse.ArgumentParser(description="KlipperScreen - A GUI for Klipper") + parser.add_argument( + "-c","--configfile", default="~/KlipperScreen.conf", metavar='', + help="Location of KlipperScreen configuration file" + ) + args = parser.parse_args() + configfile = os.path.normpath(os.path.expanduser(args.configfile)) + + + self._config = KlipperScreenConfig(configfile) self.printer = Printer({ "software_version": "Unknown" }, {