-
Notifications
You must be signed in to change notification settings - Fork 1
/
Dialogs.py
160 lines (129 loc) · 5 KB
/
Dialogs.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
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
from tkinter.messagebox import showerror
from tkinter import *
from tkinter.ttk import *
import ipaddress
class NewScreenDialog(Toplevel):
def __init__(self, root):
super().__init__(root)
self.minsize(width=250, height=10)
self.title("Select Screen")
self.var = ""
Label(self, text="Select Screen Type").pack(anchor=NW, pady=20, padx=10)
self.combo = Combobox(self, values=['Spectrum', 'SpectrumBar', 'ResponsiveStar', 'ResponsiveBox',
'ResponsiveHelix', 'Video'])
self.combo.pack(padx=10, fill=X)
self.combo.current(0)
b = Button(self, text="OK", command=self.ok, width=35)
b.pack(pady=30, padx=20, anchor=SE)
def ok(self):
self.var = self.combo.get()
if self.var != '':
self.destroy()
def show(self):
try:
self.wm_deiconify()
self.combo.focus_force()
self.wait_window()
return self.var
except Exception as e:
return ""
class SerialConnDialog(Toplevel):
def __init__(self, root, COMs):
super().__init__(root)
self.minsize(width=300, height=10)
self.title("Select COM")
self.root = root
self.COMs = COMs
Label(self, text="Select Serial Communication Device").pack(anchor=NW, pady=20, padx=10)
self.combo = Combobox(self, values=[str(i) for i in COMs])
self.combo.pack(padx=10, fill=X)
self.combo.current(len(COMs)-1)
Label(self, text="Select Baudrate").pack(anchor=NW, pady=20, padx=10)
self.combo1 = Combobox(self, values=[300, 1200, 2400, 4800, 9600, 19200, 38400, 57600, 74880, 115200, 230400,
250000, 500000, 1000000, 2000000])
self.combo1.pack(padx=10, fill=X)
self.combo1.current(11)
b = Button(self, text="OK", command=self.ok, width=10)
b.pack(pady=30, padx=20, anchor=SE)
def ok(self):
port = self.combo.current()
rate = self.combo1.get()
if port is not None and rate is not None:
self.res = (self.COMs[port].device, rate)
while not self.root.queue.empty(): self.root.queue.get_nowait()
self.destroy()
def show(self):
try:
self.wm_deiconify()
self.combo.focus_force()
self.wait_window()
return self.res
except Exception as e:
return ""
class NetworkConnDialog(Toplevel):
def __init__(self, root):
super().__init__(root)
self.minsize(width=300, height=10)
self.title("Configure Connection")
self.root = root
Label(self, text="Configure TCP Connection").pack(pady=20, padx=20, anchor=W)
entries = Frame(self)
Label(entries, text="IPv4:").pack(side=LEFT, padx=5)
self.ip = StringVar()
self.ip.set("192.168.1.")
self.ip.trace('w', self.check_ip)
self.ip_entry = Entry(entries, textvariable=self.ip, width=15)
self.ip_entry.pack(side=LEFT, padx=5)
Label(entries, text='Port:').pack(side=LEFT, padx=5)
self.port = StringVar()
self.port.set("25566")
Entry(entries, textvariable=self.port, width=6).pack(side=LEFT, padx=5)
entries.pack(pady=20, padx=20, anchor=W)
b = Button(self, text="OK", command=self.ok, width=10)
b.pack(pady=30, padx=20, anchor=SE)
def check_ip(self, *args):
temp = self.ip.get()
# if len(temp) in (3, 7, 11):
# self.ip_entry.insert(END, '.')
if len(temp) >= 15: self.ip.set(temp[:15])
def ok(self):
ip = self.ip.get()
port = self.port.get()
try:
ip = ipaddress.ip_address(ip)
self.res = (ip, port)
self.destroy()
except ValueError:
showerror("Invalid IP Address", "The IP you provided is not a valid IPv4 address!", parent=self)
self.ip.set("")
def show(self):
try:
self.wm_deiconify()
self.wait_window()
return self.res
except Exception as e:
return ""
class ChooseConnDialog(Toplevel):
def __init__(self, root):
super().__init__(root)
self.minsize(width=300, height=10)
self.title("Select Connection")
Label(self, text="Select Communication Method").pack(anchor=NW, pady=20, padx=10)
self.combo = Combobox(self, values=["Shredder", "Console", "Serial", "Network-TCP", "Network-UDP"])
self.combo.pack(padx=10, fill=X)
self.combo.current(0)
b = Button(self, text="OK", command=self.ok, width=10)
b.pack(pady=30, padx=20, anchor=SE)
def ok(self):
res = self.combo.current()
if res is not None:
self.res = res
self.destroy()
def show(self):
try:
self.wm_deiconify()
self.combo.focus_force()
self.wait_window()
return self.res
except Exception as e:
return ""