-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathGUI.py
129 lines (95 loc) · 4.14 KB
/
GUI.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
from tkinter import *
from controller import *
from communicator import *
from Arduino import Arduino
import threading
from queue import Queue
import time
class Window(Frame):
def __init__(self, master=None):
Frame.__init__(self, master)
self.master = master
self.init_window()
self.ard_list = []
#Creation of init_window
def init_window(self):
# changing the title of our master widget
self.master.title("GUI")
# allowing the widget to take the full space of the root window
self.pack(fill=BOTH, expand=1)
# creating a menu instance
menu = Menu(self.master)
self.master.config(menu=menu)
# create the file object)
file = Menu(menu)
# adds a command to the menu option, calling it exit, and the
# command it runs on event is client_exit
file.add_command(label="Exit", command=self.client_exit)
file.add_command(label="Connect", command=self.getArduinos)
file.add_command(label="Stop All", command=self.stopAllMotors)
#added "file" to our menu
menu.add_cascade(label="File", menu=file)
# create the file object)
edit = Menu(menu)
# adds a command to the menu option, calling it exit, and the
# command it runs on event is client_exit
edit.add_command(label="Undo")
edit.add_command(label="Show Text", command=self.showText)
#added "file" to our menu
menu.add_cascade(label="Edit", menu=edit)
#self.getArduinos()
def client_exit(self):
exit()
def stopAllMotors(self):
if self.ard_list:
stopAll(self.ard_list)
def showText(self):
for ard in self.ard_list:
text = Label(self, text=str(ard))
text.pack()
def getArduinos(self):
# text = Label(self, text="Connecting to Arduinos...")
# text.pack()
ard_list1 = setup()
self.ard_list = ard_list1
self.showText()
class ThreadedTask(threading.Thread):
def __init__(self, queue):
threading.Thread.__init__(self)
self.queue = queue
def run(self):
time.sleep(5) # Simulate long running process
self.queue.put("Task finished")
root = Tk()
#size of the window
root.geometry("400x300")
app = Window(root)
root.mainloop()
# class Root(tkinter.Tk) :
# def __init__(self):
# super().__init__()
# self.title("Multichannel Peristaltic Pump Interface")
# self.GUI_canvas = tkinter.Canvas(self)
# # self.motors_canvas = tkinter.Canvas(self)
# # self.frame_motors = tkinter.Frame(self, borderwidth="2", relief="ridge")
# # self.frame_buttons = tkinter.Frame(self, borderwidth="2", relief="ridge")
# # self.frame_labels = tkinter.Frame(self, borderwidth="2", relief="ridge")
# # self.frame_GUI = tkinter.Frame(self.GUI_canvas)
# # self.scrollbar = tkinter.Scrollbar(self.GUI_canvas, orient="vertical", command=self.GUI_canvas.yview)
# # self.GUI_canvas.configure(yscrollcommand=self.scrollbar.set)
# self.GUI_canvas.pack(side=tkinter.TOP, fill=tkinter.BOTH, expand=1)
# # self.scrollbar.pack(side=tkinter.RIGHT, fill=tkinter.Y)
# # self.canvas_frame = self.GUI_canvas.create_window((0,0),window=self.frame_GUI,anchor='n')
# # self.simple_label = tkinter.Label(self.frame_labels, text="Pumps")
# # self.another_label = tkinter.Label(self.frame_labels, text="Motors")
# # self.closing_button = tkinter.Button(self.frame_buttons, text="Close window", command=self.destroy)
# # self.another_button = tkinter.Button(self.frame_buttons, text="Do nothing")
# # # self.frame_labels.grid(column=0, row=0, sticky="ns")
# # # self.frame_buttons.grid(column=1, row=0)
# # self.simple_label.grid(column=0, row=0, sticky="ew")
# # self.another_label.grid(column=0, row=1, sticky="ew")
# # self.closing_button.pack(fill="x")
# # self.another_button.pack(fill="x")
# if __name__=="__main__":
# root = Root()
# root.mainloop()