added protection against excessive values

This commit is contained in:
Martin Zietz
2021-02-02 17:56:43 +01:00
parent 27c804904b
commit 2a2a538fd8
4 changed files with 83 additions and 32 deletions
+25 -10
View File
@@ -5,6 +5,7 @@ import cage_func as func
import numpy as np
NORM_FONT = ()
HEADER_FONT = ("Arial", 13, "bold")
SUB_HEADER_FONT = ("Arial", 9, "bold")
BIG_BUTTON_FONT = ("Arial", 11, "bold")
@@ -82,6 +83,11 @@ class ManualMode(Frame):
row_counter = 0
header = Label(self, text="Manual Input Mode", font=HEADER_FONT, pady=3)
header.grid(row=row_counter, column=0)
row_counter += 1
# Setup Dropdown Menu for input mode
dropdown_frame = Frame(self)
dropdown_frame.grid_rowconfigure(ALL, weight=1)
@@ -241,6 +247,11 @@ class Configuration(Frame):
row_counter = 0
header = Label(self, text="Configuration Window", font=HEADER_FONT, pady=3)
header.grid(row=row_counter, column=0, padx=100, sticky=W)
row_counter += 1
# Serial port settings frame:
port_frame = Frame(self)
port_frame.grid_rowconfigure(ALL, weight=1)
@@ -349,20 +360,24 @@ class Configuration(Frame):
self.entries[key][0][i].set(round(type_value * factor, 3)) # set value with correct unit conversion
def implement(self): # update config file with user inputs into entry fields and reinitialize
# ToDo: Error handling with warning messages to user if wrong data format or high/low value is entered
# ToDo: Warning messages if too high values are entered
func.edit_config("PORTS", "xy_port", self.XY_port.get())
func.edit_config("PORTS", "z_port", self.Z_port.get())
for key in self.entries.keys():
for i in [0, 1, 2]:
value = self.entries[key][0][i].get()
factor = self.entries[key][4] # get unit conversion factor
if factor not in [0, 1]: # prevent conversion of int variables to float representation
value = value / factor # implement unit conversion
print(key, value)
func.edit_config(g.AXIS_NAMES[i], self.entries[key][3], value)
for key in self.entries.keys(): # go through rows of entry table
for i in [0, 1, 2]: # go through columns of entry table
try:
value = self.entries[key][0][i].get() # get value from field
factor = self.entries[key][4] # get unit conversion factor
if factor not in [0, 1]: # prevent conversion of int variables to float and div/0
value = value / factor # do unit conversion
func.edit_config(g.AXIS_NAMES[i], self.entries[key][3], value) # write new value to config file
except TclError as e:
func.ui_print("Invalid entry for %s %s %s" % (g.AXIS_NAMES[i], key, e))
func.setup_axes()
func.setup_axes() # reinitialize devices and program with new values
self.update_fields() # update entry fields to show new values
class StatusDisplay(Frame):