moved ui_print function to User_Interface.py

This commit is contained in:
Martin Zietz
2021-02-07 15:15:05 +01:00
parent 08d4ca463d
commit 063a7049d0
5 changed files with 51 additions and 46 deletions
+28 -14
View File
@@ -214,7 +214,7 @@ class ManualMode(Frame):
field = g.AXES[i].max_comp_field * 1e6
else:
field = [0, 0]
func.ui_print("Unexpected value encountered: compensate =", comp)
ui_print("Unexpected value encountered: compensate =", comp)
val.set("(%0.1f to %0.1f \u03BCT)" % (field[0], field[1]))
i += 1
@@ -236,22 +236,22 @@ class ManualMode(Frame):
self.controller.StatusDisplay.update_labels() # update status display after change
def execute_field(self, vector):
func.ui_print("field executing", vector)
ui_print("field executing", vector)
comp = self.compensate.get()
if comp == 1:
func.set_field(vector * 1e-6)
elif comp == 0:
func.set_field_simple(vector * 1e-6)
else:
func.ui_print("Unexpected value encountered: compensate =", comp)
ui_print("Unexpected value encountered: compensate =", comp)
@staticmethod
def execute_current(vector):
func.ui_print("current executing:", vector)
ui_print("current executing:", vector)
try:
func.set_current_vec(vector)
except ValueError as e:
func.ui_print(e)
ui_print(e)
class Configuration(Frame):
@@ -425,7 +425,7 @@ class Configuration(Frame):
try:
value = self.entries[key][0][i].get() # get value from field
except TclError as e: # wrong format entered, e.g. text in number fields
func.ui_print("Invalid entry for %s %s %s" % (g.AXIS_NAMES[i], key, e))
ui_print("Invalid entry for %s %s %s" % (g.AXIS_NAMES[i], key, e))
else: # format is ok
factor = self.entries[key][4] # get unit conversion factor
@@ -484,9 +484,9 @@ class Configuration(Frame):
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.")
ui_print("No file selected, could not load config.")
else:
func.ui_print("Selected file", filename, "does not exist, could not load config.")
ui_print("Selected file", filename, "does not exist, could not load config.")
def save_config_as(self): # save current configuration to a new config file
directory = os.path.dirname(os.path.abspath(config.CONFIG_FILE)) # get directory of current config file
@@ -496,17 +496,19 @@ class Configuration(Frame):
defaultextension=[("Config File", "*.ini*")])
if filename == '': # this happens when file selection window is closed without selecting a file
func.ui_print("No file selected, could not save config.")
ui_print("No file selected, could not save config.")
else: # a file name was entered
config.CONFIG_FILE = filename # set global config file to the new file
self.write_values() # write current entry field values to the config object
config.write_config_to_file(config.CONFIG_OBJECT) # write contents of config object to file
func.setup_all() # reinitialize devices and program with new values
self.update_fields() # update entry fields to show values as they are in the config
def save_config(self): # same as save_config_as() but with the current config file
self.write_values()
config.write_config_to_file(config.CONFIG_OBJECT)
self.update_fields()
func.setup_all() # reinitialize devices and program with new values
self.update_fields() # update entry fields to show values as they are in the config
class ExecuteCSVMode(Frame):
@@ -563,19 +565,19 @@ class ExecuteCSVMode(Frame):
filename = filedialog.askopenfilename(initialdir=directory, title="Select CSV File",
filetypes=(("Comma Separated Values", "*.csv*"), ("All Files", "*.*")))
if exists(filename): # does the file exist?
func.ui_print("File selected:", filename)
ui_print("File selected:", filename)
try:
self.sequence_array = csv.read_csv_to_array(filename)
except BaseException as e:
func.ui_print("Error while opening file:", e)
ui_print("Error while opening file:", e)
# ToDo: make error a popup
# ToDo: check for excessive values
self.execute_button["state"] = "normal" # activate run button
elif filename == '': # this happens when file selection window is closed without selecting a file
func.ui_print("No file selected, could not load.")
ui_print("No file selected, could not load.")
else:
func.ui_print("Selected file", filename, "does not exist, could not load.")
ui_print("Selected file", filename, "does not exist, could not load.")
def run_sequence(self):
# (de)activate buttons as needed:
@@ -688,3 +690,15 @@ class OutputConsole(Frame): # console to print stuff in, similar to standard py
self.console.grid(row=0, column=0, sticky="nesw")
scrollbar.config(command=self.console.yview)
self.console.config(yscrollcommand=scrollbar.set)
def ui_print(*content): # prints text to built in console
output = ""
for text in content:
output = " ".join((output, str(text))) # append content
if g.app is not None:
output = "".join(("\n", output)) # begin new line each time
g.app.OutputConsole.console.insert(END, output) # print to console
g.app.OutputConsole.console.see(END) # scroll to bottom
else: # if window is not open, do normal print
print(output)