forked from LeoJr2015/python
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTestApp.py
More file actions
executable file
·75 lines (68 loc) · 2.29 KB
/
TestApp.py
File metadata and controls
executable file
·75 lines (68 loc) · 2.29 KB
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
#!/usr/bin/env python
# -*- coding: utf-8 -*-
#
# untitled.py
#
# Copyright 2012 Scott Thomson <[email protected]>
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
# MA 02110-1301, USA.
#
#
from Tkinter import *
from autodetectgui import *
from functools import partial
class App(Frame):
def __init__(self,parent=None,**kw):
Frame.__init__(self,parent,**kw)
self.sersel = SerialPortSelect(self)
self.sersel.grid(row=0,column=0,columnspan=2,sticky=E)
self.btnSend = Button(self,text='Browse',command=self.send)
self.btnSend.grid(column=0,row=1)
self.msgs=Text(self,width=60,height=20,padx=5,pady=5)
self.msgs.grid(row=2,column=0)
self.s=Scrollbar(self,orient=VERTICAL)
self.s.grid(row=2,column=1,sticky=N+S)
self.buttons = []
self.commands = ["Switch 1 On","Switch 1 Off","Switch 2 On","Switch 2 Off"]
btnIndex = 0
btnRow = 1
btnCol = 1
self.btnFrame = Frame(self,parent,**kw)
for command in self.commands:
cmd = partial(self.send, command)
self.buttons.append(Button(self.btnFrame,text=command,command=cmd,width=10,height=5))
self.buttons[btnIndex].grid(row=btnRow,column=btnCol,padx=5,pady=5)
btnCol += 1
btnIndex += 1
if btnCol > 2:
btnCol = 1
btnRow += 1
self.btnFrame.grid(row=3,column=0,columnspan=2)
self._update()
def send(self,text="Hello"):
if self.sersel.state == "connected":
self.sersel.port.write(text)
def _update(self):
if self.sersel.state == "connected":
self.msgs.insert(END,self.sersel.port.read(self.sersel.port.inWaiting()))
self._timer = self.after(500,self._update)
def main():
root = App()
root.grid()
root.mainloop()
return 0
if __name__ == '__main__':
main()