forked from zietzm/Helmholtz_Test_Bench
comments
This commit is contained in:
+24
-22
@@ -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()
|
||||
|
||||
+1
-1
@@ -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)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user