forked from zietzm/Helmholtz_Test_Bench
various changes
- added checkbox for ambient field compensation - moved part of axis setup to axis.__init__
This commit is contained in:
+50
-8
@@ -86,8 +86,8 @@ class ManualMode(Frame):
|
||||
self.input_mode = StringVar()
|
||||
# make dictionary with information on all modes.
|
||||
# content: [function to call on button press, unit text to be displayed]
|
||||
self.modes = {"Magnetic Field": [self.execute_field, "\u03BCT"],
|
||||
"Current": [self.execute_current, "A"]}
|
||||
self.modes = {"Magnetic Field": [self.execute_field, "\u03BCT", self.update_max_fields],
|
||||
"Current": [self.execute_current, "A", self.update_max_currents]}
|
||||
# "Raw Current": [self.input_raw_current, "A"]} ToDo (optional): make functions for this
|
||||
self.unit = StringVar()
|
||||
default_mode = list(self.modes.keys())[0]
|
||||
@@ -107,10 +107,12 @@ class ManualMode(Frame):
|
||||
self.entries_frame.grid_rowconfigure(ALL, weight=1)
|
||||
self.entries_frame.grid_columnconfigure(ALL, weight=1)
|
||||
self.entries_frame.grid_columnconfigure(2, weight=1, minsize=20)
|
||||
self.entries_frame.grid_columnconfigure(3, weight=1, minsize=110)
|
||||
self.entries_frame.grid(row=row_counter, column=0)
|
||||
|
||||
entry_texts = ["X-Axis:", "Y-Axis:", "Z-Axis:"]
|
||||
self.entry_vars = [StringVar() for _ in range(len(entry_texts))]
|
||||
self.entry_vars = [StringVar() for _ in range(3)]
|
||||
self.max_value_vars = [StringVar() for _ in range(3)]
|
||||
row = 0
|
||||
for text in entry_texts:
|
||||
field = ttk.Entry(self.entries_frame, textvariable=self.entry_vars[row])
|
||||
@@ -120,19 +122,33 @@ class ManualMode(Frame):
|
||||
axis_label.grid(row=row, column=0, sticky=W)
|
||||
unit_label = Label(self.entries_frame, textvariable=self.unit)
|
||||
unit_label.grid(row=row, column=2, sticky=W)
|
||||
max_value_label = Label(self.entries_frame, textvariable=self.max_value_vars[row])
|
||||
max_value_label.grid(row=row, column=3, sticky=W)
|
||||
row = row + 1
|
||||
|
||||
row_counter = row_counter + 1
|
||||
row_counter += 1
|
||||
|
||||
# Setup execute button
|
||||
# setup checkbox for compensating ambient field
|
||||
checkbox_frame = Frame(self, padx=20)
|
||||
checkbox_frame.grid(row=row_counter, column=0, sticky=W)
|
||||
|
||||
self.compensate = IntVar(value=1)
|
||||
self.compensate_checkbox = Checkbutton(checkbox_frame, text="Compensate ambient field",
|
||||
variable=self.compensate, onvalue=1, offvalue=0)
|
||||
self.compensate_checkbox.pack(side="left")
|
||||
|
||||
row_counter += 1
|
||||
|
||||
# Setup buttons
|
||||
self.buttons_frame = Frame(self)
|
||||
self.buttons_frame.grid_rowconfigure(ALL, weight=1)
|
||||
self.buttons_frame.grid_columnconfigure(ALL, weight=1)
|
||||
self.buttons_frame.grid_columnconfigure(2, weight=1, minsize=20)
|
||||
self.buttons_frame.grid(row=row_counter, column=0)
|
||||
|
||||
Label(self.buttons_frame, text="").grid(row=row_counter, column=0) # add spacer
|
||||
Label(self.buttons_frame, text="").grid(row=0, column=0) # add spacer
|
||||
|
||||
# add button for executing the current entries
|
||||
execute_button = Button(self.buttons_frame, text="Execute!", command=self.execute,
|
||||
pady=5, padx=5, font=BIG_BUTTON_FONT)
|
||||
execute_button.grid(row=row_counter, column=0)
|
||||
@@ -149,9 +165,33 @@ class ManualMode(Frame):
|
||||
|
||||
self.input_mode.trace_add('write', self.change_mode_callback) # call mode change function on dropdown change
|
||||
self.input_mode.set(default_mode) # call up default mode at the start
|
||||
self.compensate.trace_add('write', self.change_mode_callback) # call mode change function on dropdown change
|
||||
|
||||
def change_mode_callback(self, var, index, mode): # not sure what the parameters are for, but they are necessary
|
||||
self.unit.set(self.modes[self.input_mode.get()][1]) # change unit text
|
||||
self.modes[self.input_mode.get()][2]() # update max values
|
||||
|
||||
def update_max_fields(self): # update labels with maximum allowable field values
|
||||
self.compensate_checkbox.config(state=NORMAL)
|
||||
i = 0
|
||||
for val in self.max_value_vars:
|
||||
comp = self.compensate.get()
|
||||
if comp == 0:
|
||||
field = g.AXES[i].max_field * 1e6
|
||||
elif comp == 1:
|
||||
field = g.AXES[i].max_comp_field * 1e6
|
||||
else:
|
||||
field = [0, 0]
|
||||
func.ui_print("Unexpected value encountered: compensate =", comp)
|
||||
val.set("(%0.1f to %0.1f \u03BCT)" % (field[0], field[1]))
|
||||
i += 1
|
||||
|
||||
def update_max_currents(self): # update labels with maximum allowable current values
|
||||
self.compensate_checkbox.config(state=DISABLED)
|
||||
i = 0
|
||||
for val in self.max_value_vars:
|
||||
val.set("(%0.2f to %0.2f A)" % (-g.AXES[i].max_amps, g.AXES[i].max_amps))
|
||||
i += 1
|
||||
|
||||
def execute(self):
|
||||
function_to_call = self.modes[self.input_mode.get()][0] # get function of appropriate mode
|
||||
@@ -167,7 +207,7 @@ class ManualMode(Frame):
|
||||
def execute_field(vector):
|
||||
func.ui_print("field executing", vector)
|
||||
try:
|
||||
func.set_field_simple(vector*1e-6) # ToDo: change to set_field
|
||||
func.set_field_simple(vector * 1e-6) # ToDo: change to set_field
|
||||
except ValueError as e:
|
||||
func.ui_print(e)
|
||||
|
||||
@@ -253,7 +293,7 @@ class StatusDisplay(Frame):
|
||||
controller.after(500, lambda: self.update_labels(controller))
|
||||
|
||||
|
||||
class OutputConsole(Frame):
|
||||
class OutputConsole(Frame): # console to print stuff in
|
||||
|
||||
def __init__(self, parent):
|
||||
Frame.__init__(self, parent, relief=SUNKEN, bd=1)
|
||||
@@ -263,6 +303,8 @@ class OutputConsole(Frame):
|
||||
|
||||
scrollbar = Scrollbar(self)
|
||||
self.console = Text(self)
|
||||
self.console.bind("<Key>", lambda e: "break") # prevent user input into the console
|
||||
|
||||
scrollbar.grid(row=0, column=1, sticky="ns")
|
||||
self.console.grid(row=0, column=0, sticky="nesw")
|
||||
scrollbar.config(command=self.console.yview)
|
||||
|
||||
Reference in New Issue
Block a user