From 8447a2a1560a68f02dcbe6ecfc0b58335b306752 Mon Sep 17 00:00:00 2001 From: Martin Zietz Date: Thu, 4 Feb 2021 18:10:12 +0100 Subject: [PATCH] comments --- User_Interface.py | 46 ++++++++++++++++++++++++---------------------- cage_func.py | 2 +- 2 files changed, 25 insertions(+), 23 deletions(-) diff --git a/User_Interface.py b/User_Interface.py index 2ad47a6..451c36d 100644 --- a/User_Interface.py +++ b/User_Interface.py @@ -454,42 +454,44 @@ class Configuration(Frame): func.edit_config(g.AXIS_NAMES[i], config_key, value, True) # if user chooses 'no' nothing happens, old value is kept - def implement(self): - self.write_values() + def implement(self): # executed on button press + self.write_values() # write current values from entry fields to config object func.setup_all() # reinitialize devices and program with new values self.update_fields() # update entry fields to show new values - def load_config(self): # ToDo: comments - directory = os.path.dirname(os.path.abspath(g.CONFIG_FILE)) + def load_config(self): # load configuration from some config file + directory = os.path.dirname(os.path.abspath(g.CONFIG_FILE)) # get directory of current config file + # open file selection dialogue and save path of selected file filename = filedialog.askopenfilename(initialdir=directory, title="Select Config File", filetypes=(("Config File", "*.ini*"), ("All Files", "*.*"))) - if exists(filename): - g.CONFIG_FILE = filename - g.CONFIG_OBJECT = func.get_config_from_file(filename) - func.check_config(g.CONFIG_OBJECT) - func.setup_all() - self.update_fields() - elif filename == '': + if exists(filename): # does the file exist? + g.CONFIG_FILE = filename # set global config file to the new file + g.CONFIG_OBJECT = func.get_config_from_file(filename) # load values from config file to config object + func.check_config(g.CONFIG_OBJECT) # check the values and display warnings if values are out of bounds + func.setup_all() # reinitialize devices and program with new values + self.update_fields() # update entry fields to show new values + elif filename == '': # this happens when file selection window is closed without selecting a file func.ui_print("No file selected, could not load config.") else: - func.ui_print("Selected file", filename, "does not seem to exist, could not load config.") + func.ui_print("Selected file", filename, "does not exist, could not load config.") - def save_config_as(self): # ToDo: comments - directory = os.path.dirname(os.path.abspath(g.CONFIG_FILE)) + def save_config_as(self): # save current configuration to a new config file + directory = os.path.dirname(os.path.abspath(g.CONFIG_FILE)) # get directory of current config file + # open file selection dialogue and save path of selected file filename = filedialog.asksaveasfilename(initialdir=directory, title="Select Config File", filetypes=([("Config File", "*.ini*")]), defaultextension=[("Config File", "*.ini*")]) - if exists(filename): - g.CONFIG_FILE = filename - self.write_values() - func.write_config_to_file(g.CONFIG_OBJECT) - self.update_fields() - elif filename == '': + if exists(filename): # does the file exist? + g.CONFIG_FILE = filename # set global config file to the new file + self.write_values() # write current entry field values to the config object + func.write_config_to_file(g.CONFIG_OBJECT) # write contents of config object to file + self.update_fields() # update entry fields to show values as they are in the config + elif filename == '': # this happens when file selection window is closed without selecting a file func.ui_print("No file selected, could not save config.") else: - func.ui_print("Selected file", filename, "does not seem to exist, could not save config.") + func.ui_print("Selected file", filename, "does not exist, could not save config.") - def save_config(self): # ToDo: comments + def save_config(self): # same as save_config_as() but with the current config file self.write_values() func.write_config_to_file(g.CONFIG_OBJECT) self.update_fields() diff --git a/cage_func.py b/cage_func.py index d3007ce..d62592c 100644 --- a/cage_func.py +++ b/cage_func.py @@ -186,7 +186,7 @@ def get_config_from_file(file=g.CONFIG_FILE): return config_object # return config object, that contains all info from the file -def write_config_to_file(config_object): # ToDo: comments +def write_config_to_file(config_object): # write contents of config object to a config file with open(g.CONFIG_FILE, 'w') as conf: # Write changes to config file config_object.write(conf)