forked from probotics/Rosbee-GUI-serial-port-and-ROS-driver
-
Notifications
You must be signed in to change notification settings - Fork 0
/
comportconfig.py
197 lines (166 loc) · 7.95 KB
/
comportconfig.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
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
#! /usr/bin/env python
#
# GUI module generated by PAGE version 4.4.4
# In conjunction with Tcl version 8.6
# Aug 10, 2015 09:17:04 AM
import sys
from tkinter import StringVar
try:
from Tkinter import *
except ImportError:
from tkinter import *
try:
import ttk
py3 = 0
except ImportError:
import tkinter.ttk as ttk
py3 = 1
import listports
import comportconfig_support
#import serial.tools.list_ports
def vp_start_gui():
'''Starting point when module is the main routine.'''
global val, w, root
root = Tk()
root.title('ComportConfig')
root.geometry('295x163+633+117')
# ComportConfig_support.set_Tk_var()
w = ComportConfig (root)
comportconfig_support.init(root, w)
root.mainloop()
#create_New_Toplevel_1
w = None
def create_ComportConfig(root, param=None):
'''Starting point when module is imported by another program.'''
global w, w_win, rt
rt = root
w = Toplevel (root)
w.title('ComportConfig')
w.geometry('295x163+633+117')
# comportconfig_support.set_Tk_var()
w_win = ComportConfig (w)
comportconfig_support.init(w, w_win, param)
return w_win
def destroy_ComportConfig():
global w
w.destroy()
w = None
class ComportConfig():
def __init__(self, master=None):
_bgcolor = 'wheat' # X11 color: #f5deb3
_fgcolor = '#000000' # X11 color: 'black'
_compcolor = '#d9d9d9' # X11 color: 'gray85'
_ana1color = '#d9d9d9' # X11 color: 'gray85'
_ana2color = '#d9d9d9' # X11 color: 'gray85'
self.style = ttk.Style()
if sys.platform == "win32":
self.style.theme_use('winnative')
self.style.configure('.',background=_bgcolor)
self.style.configure('.',foreground=_fgcolor)
self.style.configure('.',font="TkDefaultFont")
self.style.map('.',background=
[('selected', _compcolor), ('active',_ana2color)])
master.configure(background="#d0d0d0")
master.configure(highlightbackground="#d9d9d9")
master.configure(highlightcolor="black")
self.btn_Save = Button(master)
self.btn_Save.place(relx=0.34, rely=0.74, height=24, width=87)
self.btn_Save.configure(activebackground="#c0c0c0")
self.btn_Save.configure(activeforeground="#000000")
self.btn_Save.configure(background="#d0d0d0")
# self.btn_Save.configure(command=comportconfig_support.Close)
self.btn_Save.configure(command=comportconfig_support.Close)
self.btn_Save.configure(disabledforeground="#a3a3a3")
self.btn_Save.configure(foreground="#000000")
self.btn_Save.configure(highlightbackground="#d0d0d0")
self.btn_Save.configure(highlightcolor="black")
self.btn_Save.configure(pady="0")
self.btn_Save.configure(text='''Save&Close''')
self.btn_Cancel = Button(master)
self.btn_Cancel.place(relx=0.68, rely=0.74, height=24, width=87)
self.btn_Cancel.configure(activebackground="#d0d0d0")
self.btn_Cancel.configure(activeforeground="#000000")
self.btn_Cancel.configure(background="#d0d0d0")
self.btn_Cancel.configure(command=comportconfig_support.cancel)
self.btn_Cancel.configure(disabledforeground="#a3a3a3")
self.btn_Cancel.configure(foreground="#000000")
self.btn_Cancel.configure(highlightbackground="#d0d0d0")
self.btn_Cancel.configure(highlightcolor="black")
self.btn_Cancel.configure(pady="0")
self.btn_Cancel.configure(text='''Cancel''')
self.Labelframe1 = LabelFrame(master)
self.Labelframe1.place(relx=0.1, rely=0.06, relheight=0.58
, relwidth=0.86)
self.Labelframe1.configure(relief=GROOVE)
self.Labelframe1.configure(foreground="black")
self.Labelframe1.configure(text='''Comport settings''')
self.Labelframe1.configure(background="#d0d0d0")
self.Labelframe1.configure(highlightbackground="#d9d9d9")
self.Labelframe1.configure(highlightcolor="black")
self.Labelframe1.configure(width=255)
self.Label1 = Label(self.Labelframe1)
self.Label1.place(relx=0.04, rely=0.21, height=21, width=54)
self.Label1.configure(activebackground="#f9f9f9")
self.Label1.configure(activeforeground="black")
self.Label1.configure(background="#d0d0d0")
self.Label1.configure(disabledforeground="#a3a3a3")
self.Label1.configure(foreground="#000000")
self.Label1.configure(highlightbackground="#d9d9d9")
self.Label1.configure(highlightcolor="black")
self.Label1.configure(text='''Comport''')
self.Label2 = Label(self.Labelframe1)
self.Label2.place(relx=0.04, rely=0.53, height=21, width=53)
self.Label2.configure(activebackground="#f9f9f9")
self.Label2.configure(activeforeground="black")
self.Label2.configure(background="#d0d0d0")
self.Label2.configure(disabledforeground="#a3a3a3")
self.Label2.configure(foreground="#000000")
self.Label2.configure(highlightbackground="#d9d9d9")
self.Label2.configure(highlightcolor="black")
self.Label2.configure(text='''Baudrate''')
comportconfig_support.Readconfig()
baudrateindex = self.find_index(comportconfig_support.localserialconfig['baudrate'],
comportconfig_support.cbaudrates) # check if baudrate in list
if baudrateindex < 0:
baudrateindex = 0
comportindex = self.find_index(comportconfig_support.localserialconfig['comport'],
listports.serial_ports()) # check if baudrate in list
# comportindex = self.find_index(comportconfig_support.localserialconfig['comport'],
# serial.tools.list_ports.comports() ) # check if baudrate in list
if comportindex < 0:
comportindex = 0
print('Config: ', comportconfig_support.localserialconfig)
self.tc_baudrate= StringVar()
self.tc_baudrate = ttk.Combobox(self.Labelframe1, textvariable=self.tc_baudrate)
self.tc_baudrate.place(relx=0.35, rely=0.21, relheight=0.35
, relwidth=0.56)
self.tc_baudrate['values'] = comportconfig_support.cbaudrates
self.tc_baudrate.current(baudrateindex)
self.tc_baudrate.configure(takefocus="")
self.tc_baudrate.bind('<<ComboboxSelected>>',self.set_baudrate)
self.tc_comports= StringVar()
self.tc_comport = ttk.Combobox(self.Labelframe1, textvariable=self.tc_comports)
self.tc_comport.place(relx=0.35, rely=0.53, relheight=0.35 , relwidth=0.56)
self.tc_comport['values']= listports.serial_ports()
self.tc_comport.current(comportindex)
self.tc_comport.bind('<<ComboboxSelected>>',self.set_comport)
self.tc_comport.configure(takefocus="")
print ('baudrate: ', self.tc_baudrate['values'])
print ('ports: ', listports.serial_ports())
def set_baudrate(self, event):
comportconfig_support.localserialconfig["baudrate"] = self.tc_baudrate.get()
print('Set baudrate ', comportconfig_support.localserialconfig["baudrate"]) #, ComportConfig.tc_newbaudrate)
print(comportconfig_support.localserialconfig)
def set_comport(self, event):
comportconfig_support.localserialconfig["comport"] = self.tc_comports.get()
print('Set comport', comportconfig_support.localserialconfig["comport"])
print(comportconfig_support.localserialconfig)
def find_index(self, value, qlist): # find index of value in qlist and return index if found or -1 if not found
try:
idx = qlist.index(value)
except ValueError:
idx = -1
print('find_index: ', idx, ' Value: ' , value , ' list: ', qlist)
return idx
if __name__ == '__main__':
vp_start_gui()