-
Notifications
You must be signed in to change notification settings - Fork 0
/
proves.py
99 lines (77 loc) · 2.86 KB
/
proves.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
"""
Created on Fri Sep 30 11:18:37 2016
@author: Carles Estrada
"""
import Tkinter as Tk
class Ports():
def __init__(self, frame, port, row):
self.frame = frame
self.port = port
self.row = row
self.var = Tk.BooleanVar()
self.widget(self.var, self.row)
def check(self):
i = self.var.get()
if i:
print self.port
return int(1)
elif not i:
print i
return int(0)
else:
print "Error"
def widget(self, var, row):
cb = Tk.Checkbutton(self.frame, text = self.port, variable = var, command = self.check)
cb.grid(row = row, column = 1)
import serial
class Interface():
def __init__(self):
pass
def main(self):
def newexperiment():
self.activeports = []
self.onports = []
self.newe = Tk.Tk()
neweframe = Tk.Frame(self.newe)
neweframe.grid(row = 0, column = 0)
newebottomframe = Tk.Frame(self.newe)
newebottomframe.grid(row = 1, column = 0)
lserport = Tk.Label(neweframe, text = "Serial Port:")
lserport.grid(row = 0, column = 0)
self.serialports()
self.onports = []
self.onportswid = []
self.portcount = 0
for port in self.activeports:
self.onportswid.append(Ports(neweframe, port, self.portcount))
self.portcount += 1
bsavenewe = Tk.Button(newebottomframe, text = "Save", command = self.savenewe)
bsavenewe.grid(row = 1, column = 0)
self.newe.bind('<Return>', self.savenewe)
self.newe.mainloop()
self.root = Tk.Tk()
newexp = Tk.Button(self.root, text = "New experiment", command = newexperiment)
newexp.grid(row = 0, column = 1, sticky = Tk.E + Tk.W)
self.root.mainloop()
def serialports(self):
self.ports = ['COM%s' % (i + 1) for i in range(256)]
for port in self.ports:
try:
s = serial.Serial(port)
s.close()
self.activeports.append(port)
except (OSError, serial.SerialException):
pass
def savenewe(self, event = None):
for i in range(self.portcount):
var = int(self.onportswid[i].check())
print var
if var == 1:
self.onports.append(self.onportswid[i].port)
print self.onports
self.newe.destroy()
self.root.destroy()
self.main()
gui = Interface()
gui.main()
#gui.main()