|
@@ -1,187 +0,0 @@
|
|
-# The code for changing pages was derived from: http://stackoverflow.com/questions/7546050/switch-between-two-frames-in-tkinter
|
|
|
|
-# License: http://creativecommons.org/licenses/by-sa/3.0/
|
|
|
|
-
|
|
|
|
-import matplotlib
|
|
|
|
-from matplotlib.backends.backend_tkagg import (
|
|
|
|
- FigureCanvasTkAgg, NavigationToolbar2Tk)
|
|
|
|
-from matplotlib.figure import Figure
|
|
|
|
-import matplotlib.animation as animation
|
|
|
|
-from matplotlib import style
|
|
|
|
-
|
|
|
|
-import tkinter as tk
|
|
|
|
-import tk_tools
|
|
|
|
-from time import *
|
|
|
|
-
|
|
|
|
-LARGE_FONT= ("Verdana", 12)
|
|
|
|
-style.use("ggplot")
|
|
|
|
-
|
|
|
|
-class Plot():
|
|
|
|
- def __init__(self, n):
|
|
|
|
- self.fig = Figure()
|
|
|
|
- self.ax = self.fig.add_subplot(111)
|
|
|
|
- self.xs = range(n)
|
|
|
|
- self.ys = [0] * n
|
|
|
|
- self.i = 0
|
|
|
|
- self.n = n
|
|
|
|
-
|
|
|
|
- def update(self, y):
|
|
|
|
- # Add x and y to lists
|
|
|
|
- ys[i] = y
|
|
|
|
- i = i+1 if i+1 < self.n else 0
|
|
|
|
-
|
|
|
|
-
|
|
|
|
- ax.clear()
|
|
|
|
- ax.plot(xs, ys, "#00A3E0", label="1. Graph")
|
|
|
|
- ax.legend(bbox_to_anchor=(0, 1.02, 1, .102), loc=3, ncol=2, borderaxespad=0)
|
|
|
|
- ax.set_title('Windkanal')
|
|
|
|
-
|
|
|
|
- return self.fig
|
|
|
|
-
|
|
|
|
-
|
|
|
|
-class Main(tk.Tk):
|
|
|
|
- def __init__(self, *args, **kwargs):
|
|
|
|
- tk.Tk.__init__(self, *args, **kwargs)
|
|
|
|
- tk.Tk.wm_title(self, "Windkanal-Tool")
|
|
|
|
-
|
|
|
|
-
|
|
|
|
- container = tk.Frame(self)
|
|
|
|
- container.pack(side="top", fill="both", expand = True)
|
|
|
|
- container.grid_rowconfigure(0, weight=1)
|
|
|
|
- container.grid_columnconfigure(0, weight=1)
|
|
|
|
-
|
|
|
|
-
|
|
|
|
- menubar = tk.Menu(container)
|
|
|
|
- filemenu = tk.Menu(menubar, tearoff=0)
|
|
|
|
- filemenu.add_command(label="Save settings", command = lambda: self.popupmsg("Not supported just yet!"))
|
|
|
|
- filemenu.add_separator()
|
|
|
|
- filemenu.add_command(label="Exit", command=quit)
|
|
|
|
- menubar.add_cascade(label="File", menu=filemenu)
|
|
|
|
-
|
|
|
|
- tk.Tk.config(self, menu=menubar)
|
|
|
|
-
|
|
|
|
- self.frames = {}
|
|
|
|
-
|
|
|
|
- for F in (Page_1, Page_2, Page_3, Page_4):
|
|
|
|
-
|
|
|
|
- frame = F(container, self)
|
|
|
|
-
|
|
|
|
- self.frames[F] = frame
|
|
|
|
-
|
|
|
|
- frame.grid(row=0, column=0, sticky="nsew")
|
|
|
|
-
|
|
|
|
- self.show_frame(Page_1)
|
|
|
|
-
|
|
|
|
- def show_frame(self, cont):
|
|
|
|
- frame = self.frames[cont]
|
|
|
|
- frame.tkraise()
|
|
|
|
-
|
|
|
|
- def popupmsg(self, msg=""):
|
|
|
|
- popup = tk.Toplevel(self.master)
|
|
|
|
- popup.wm_title("Error!")
|
|
|
|
- label = tk.Label(popup, text=msg, font=LARGE_FONT)
|
|
|
|
- label.pack(side="top", fill="x", pady=10)
|
|
|
|
- b1 = tk.Button(popup, text="Okay", command=popup.destroy)
|
|
|
|
- b1.pack()
|
|
|
|
-
|
|
|
|
-class Page_4(tk.Frame):
|
|
|
|
- def __init__(self, parent, controller):
|
|
|
|
- tk.Frame.__init__(self, parent)
|
|
|
|
- label = tk.Label(self, text="Einstellungen", font=LARGE_FONT)
|
|
|
|
- label.pack(pady=10,padx=10)
|
|
|
|
- button1 = tk.Button(self, text="Page_0", command=lambda: controller.show_frame(Page_0))
|
|
|
|
- button1.pack()
|
|
|
|
- button2 = tk.Button(self, text="Page_1", command=lambda: controller.show_frame(Page_1))
|
|
|
|
- button2.pack()
|
|
|
|
-
|
|
|
|
-class Page_3(tk.Frame):
|
|
|
|
- def __init__(self, parent, controller):
|
|
|
|
- tk.Frame.__init__(self, parent)
|
|
|
|
- label = tk.Label(self, text="Druck", font=LARGE_FONT)
|
|
|
|
- label.pack(pady=10,padx=10)
|
|
|
|
- button1 = tk.Button(self, text="Page_0", command=lambda: controller.show_frame(Page_0))
|
|
|
|
- button1.pack()
|
|
|
|
- button2 = tk.Button(self, text="Page_1", command=lambda: controller.show_frame(Page_1))
|
|
|
|
- button2.pack()
|
|
|
|
-
|
|
|
|
-class Page_2(tk.Frame):
|
|
|
|
- def __init__(self, parent, controller):
|
|
|
|
- tk.Frame.__init__(self, parent)
|
|
|
|
- label = tk.Label(self, text="Kräfte", font=LARGE_FONT)
|
|
|
|
- label.pack(pady=10,padx=10)
|
|
|
|
- button1 = tk.Button(self, text="Page_0", command=lambda: controller.show_frame(Page_0))
|
|
|
|
- button1.pack()
|
|
|
|
- button2 = tk.Button(self, text="Page_1", command=lambda: controller.show_frame(Page_1))
|
|
|
|
- button2.pack()
|
|
|
|
-
|
|
|
|
-
|
|
|
|
-
|
|
|
|
-class Page_1(tk.Frame):
|
|
|
|
- def __init__(self, parent, controller):
|
|
|
|
- tk.Frame.__init__(self, parent)
|
|
|
|
- self.t = 0
|
|
|
|
- label = tk.Label(self, text="Bedienelemente", font=LARGE_FONT)
|
|
|
|
- label.pack(pady=10,padx=10)
|
|
|
|
- # top menu
|
|
|
|
- top = tk.Frame(self, borderwidth=2, relief="solid")
|
|
|
|
- button1 = tk.Button(top, text="Bedienelemente", command=lambda: controller.show_frame(Page_0))
|
|
|
|
- button1.pack(side=tk.LEFT)
|
|
|
|
-
|
|
|
|
- button2 = tk.Button(top, text="Kräfte", command=lambda: controller.show_frame(Page_2))
|
|
|
|
- button2.pack(side=tk.LEFT)
|
|
|
|
-
|
|
|
|
- button3 = tk.Button(top, text="Druck", command=lambda: controller.show_frame(Page_2))
|
|
|
|
- button3.pack(side=tk.LEFT)
|
|
|
|
-
|
|
|
|
- button4 = tk.Button(top,text="Einstellungen",command=lambda: controller.show_frame(Page_2))
|
|
|
|
- button4.pack(side=tk.LEFT)
|
|
|
|
-
|
|
|
|
- button5 = tk.Button(top, text="QUIT", fg="red",command=quit)
|
|
|
|
- button5.pack(side=tk.LEFT)
|
|
|
|
- top.pack(side="top", expand=True, fill="both")
|
|
|
|
- # graph
|
|
|
|
- self.serialPlot = Plot()
|
|
|
|
- canvas = FigureCanvasTkAgg(self.serialPlot.fig, self)
|
|
|
|
- canvas.draw()
|
|
|
|
- canvas.get_tk_widget().pack(side=tk.LEFT, fill=tk.BOTH, expand=True)
|
|
|
|
- canvas._tkcanvas.pack(side=tk.LEFT, fill=tk.BOTH, expand=True)
|
|
|
|
- # right menu
|
|
|
|
- left = tk.Frame(self, borderwidth=2, relief="solid")
|
|
|
|
- container = tk.Frame(left, borderwidth=2, relief="solid")
|
|
|
|
- label1 = tk.Label(container, text="I could be a canvas, but I'm a label right now")
|
|
|
|
-
|
|
|
|
- self.label4 = tk.Label(self,font=("Arial","30"),fg="red")
|
|
|
|
- self.label4.pack()
|
|
|
|
- self.label4.config(text=str(self.t))
|
|
|
|
-
|
|
|
|
- SendButton = tk.Button(left, text='Quit', command=quit)
|
|
|
|
- label2 = tk.Label(left, text="I could be a button")
|
|
|
|
- label3 = tk.Label(left, text="So could I")
|
|
|
|
-
|
|
|
|
- left.pack(side="left", expand=True, fill="both")
|
|
|
|
- container.pack(expand=True, fill="both", padx=7, pady=5)
|
|
|
|
- SendButton.pack()
|
|
|
|
-
|
|
|
|
- label1.pack()
|
|
|
|
- label2.pack()
|
|
|
|
- label3.pack()
|
|
|
|
-
|
|
|
|
- self.after(100,self.interval)
|
|
|
|
-
|
|
|
|
- def interval(self):
|
|
|
|
-
|
|
|
|
-
|
|
|
|
-
|
|
|
|
- self.serialPlot.update(3)
|
|
|
|
-
|
|
|
|
- self.label4.config(text="{:3d} Nm".format(3))
|
|
|
|
-
|
|
|
|
- self.after(100,self.interval)
|
|
|
|
-
|
|
|
|
-
|
|
|
|
- def sendFactorToMCU(self):
|
|
|
|
- self.serialReference.sendSerialData(self.entry.get() + '%')
|
|
|
|
-
|
|
|
|
-
|
|
|
|
-app = Main()
|
|
|
|
-app.geometry("1280x720")
|
|
|
|
-app.mainloop()
|
|
|