forked from zietzm/Helmholtz_Test_Bench
added output console to ui
This commit is contained in:
+49
-18
@@ -32,8 +32,16 @@ class HelmholtzGUI(Tk):
|
||||
self.frames[F] = frame
|
||||
frame.grid(row=0, column=0, sticky="nsew")
|
||||
|
||||
self.StatusDisplay = StatusDisplay(self, self)
|
||||
self.StatusDisplay.pack(side="bottom", fill="x", expand=False)
|
||||
status_frame = Frame(self)
|
||||
status_frame.pack(side="bottom", fill="x", expand=False)
|
||||
status_frame.grid_rowconfigure(ALL, weight=1)
|
||||
status_frame.grid_columnconfigure(1, weight=1)
|
||||
|
||||
self.StatusDisplay = StatusDisplay(status_frame, self)
|
||||
self.StatusDisplay.grid(row=0, column=0, sticky="nesw")
|
||||
|
||||
self.OutputConsole = OutputConsole(status_frame)
|
||||
self.OutputConsole.grid(row=0, column=1, sticky="nesw")
|
||||
|
||||
self.show_frame(ManualMode)
|
||||
|
||||
@@ -66,7 +74,7 @@ class TestFrame(Frame): # ToDo: remove
|
||||
one.pack(fill=X)
|
||||
two = Label(self, text="Two", bg="blue")
|
||||
two.pack()
|
||||
button = ttk.Button(self, text="Print stuff", command=lambda: print("Hello"))
|
||||
button = ttk.Button(self, text="Print stuff", command=lambda: func.ui_print("Hello"))
|
||||
button.pack()
|
||||
|
||||
|
||||
@@ -130,14 +138,26 @@ class ManualMode(Frame):
|
||||
row_counter = row_counter + 1
|
||||
|
||||
# Setup execute button
|
||||
Label(self, text="").grid(row=row_counter, column=0) # add spacer
|
||||
row_counter = row_counter + 1
|
||||
execute_button = Button(self, text="Execute!", command=self.execute,
|
||||
pady=5, padx=5, font=BIG_BUTTON_FONT)
|
||||
execute_button.grid(row=row_counter, column=0, columnspan=2)
|
||||
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
|
||||
|
||||
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)
|
||||
|
||||
# add button for reinitialization
|
||||
reinit_button = Button(self.buttons_frame, text="Reinitialize", command=func.setup_axes,
|
||||
pady=5, padx=5, font=BIG_BUTTON_FONT)
|
||||
reinit_button.grid(row=row_counter, column=1)
|
||||
|
||||
# Add spacer to Frame below
|
||||
row_counter = row_counter + 1
|
||||
# Add spacer to Frame below
|
||||
|
||||
Label(self, text="", pady=10).grid(row=row_counter, column=0)
|
||||
|
||||
self.input_mode.trace_add('write', self.change_mode_callback) # call mode change function on dropdown change
|
||||
@@ -158,19 +178,19 @@ class ManualMode(Frame):
|
||||
|
||||
@staticmethod
|
||||
def execute_field(vector):
|
||||
print("field executing", vector)
|
||||
func.ui_print("field executing", vector)
|
||||
try:
|
||||
func.set_field_simple(vector*1e-6) # ToDo: change to set_field
|
||||
except ValueError as e:
|
||||
print(e)
|
||||
func.ui_print(e)
|
||||
|
||||
@staticmethod
|
||||
def execute_current(vector):
|
||||
print("current executing:", vector)
|
||||
func.ui_print("current executing:", vector)
|
||||
try:
|
||||
func.set_current_vec(vector)
|
||||
except ValueError as e:
|
||||
print(e)
|
||||
func.ui_print(e)
|
||||
|
||||
|
||||
class StatusDisplay(Frame):
|
||||
@@ -219,11 +239,6 @@ class StatusDisplay(Frame):
|
||||
col = col + 1
|
||||
# rowCounter = rowCounter + self.rowNo # increase row counter to place future stuff below this
|
||||
|
||||
# add button for reinitialization
|
||||
reinit_button = Button(self, text="Reinitialize", command=func.setup_axes,
|
||||
pady=5, padx=5, font=BIG_BUTTON_FONT)
|
||||
reinit_button.grid(row=0, column=self.columnNo+1, rowspan=3)
|
||||
|
||||
self.update_labels(controller)
|
||||
|
||||
def update_labels(self, controller):
|
||||
@@ -249,3 +264,19 @@ class StatusDisplay(Frame):
|
||||
self.label_dict["Inverted:"][i].set(axis.polarity_switched)
|
||||
i = i + 1
|
||||
controller.after(500, lambda: self.update_labels(controller))
|
||||
|
||||
|
||||
class OutputConsole(Frame):
|
||||
|
||||
def __init__(self, parent):
|
||||
Frame.__init__(self, parent, relief=SUNKEN, bd=1)
|
||||
|
||||
self.grid_rowconfigure(ALL, weight=1)
|
||||
self.grid_columnconfigure(0, weight=1, minsize=60)
|
||||
|
||||
scrollbar = Scrollbar(self)
|
||||
self.console = Text(self)
|
||||
scrollbar.grid(row=0, column=1, sticky="ns")
|
||||
self.console.grid(row=0, column=0, sticky="nesw")
|
||||
scrollbar.config(command=self.console.yview)
|
||||
self.console.config(yscrollcommand=scrollbar.set)
|
||||
|
||||
@@ -6,6 +6,7 @@ import time
|
||||
import numpy as np
|
||||
import serial
|
||||
import traceback # ToDo: remove
|
||||
from tkinter import *
|
||||
|
||||
|
||||
class Axis:
|
||||
@@ -167,6 +168,16 @@ class ArduinoCtrl(Arduino):
|
||||
self.digitalWrite(pin, "LOW")
|
||||
|
||||
|
||||
def ui_print(*content): # prints text to built in console
|
||||
output = ""
|
||||
for text in content:
|
||||
output = " ".join((output, str(text)))
|
||||
if g.app is not None:
|
||||
g.app.OutputConsole.console.insert(END, output)
|
||||
else:
|
||||
print(output)
|
||||
|
||||
|
||||
def setup_axes(): # creates device objects for all PSUs and sets their values
|
||||
# Connect to Arduino:
|
||||
try:
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
from User_Interface import HelmholtzGUI
|
||||
import cage_func as func
|
||||
import traceback
|
||||
import settings as g
|
||||
|
||||
try: # start normal operations
|
||||
|
||||
@@ -8,13 +9,11 @@ try: # start normal operations
|
||||
func.setup_axes() # initiate communication, set handles
|
||||
|
||||
print("\nOpening User Interface...")
|
||||
'''g.TestValuesX = ui.TestValues()
|
||||
g.TestValuesY = ui.TestValues()
|
||||
#g.TestValuesZ = ui.TestValues()
|
||||
g.TestValues = [g.TestValuesX, g.TestValuesY]#, g.TestValuesZ]'''
|
||||
|
||||
application = HelmholtzGUI()
|
||||
application.mainloop()
|
||||
g.app = HelmholtzGUI()
|
||||
g.app.mainloop()
|
||||
g.app = None # reset to None so nothing tries to print in the UI output
|
||||
|
||||
|
||||
except BaseException as e: # if there is an error, print what happened
|
||||
print("\nAn error occurred, Shutting down.")
|
||||
|
||||
@@ -27,4 +27,6 @@ ARDUINO = None
|
||||
|
||||
RELAY_PINS = [15, 16, 17] # pin on the Arduino for switching relay of each axis [x,y,z]
|
||||
|
||||
app = None
|
||||
|
||||
# ToDo: make proper settings file to read from and write to
|
||||
|
||||
Reference in New Issue
Block a user