3 import wx
, serial
, threading
, sys
, warnings
, png_g
, os
, time
6 class Listbox(wx
.Frame
):
7 def __init__(self
, parent
, id, title
):
8 wx
.Frame
.__init
__(self
, parent
, id, title
, size
=(880, 500))
10 baudrate
=['9600','19200','38400','115200']
12 databits
=['8','7','6','5']
14 parity
=['even','odd','None','space']
16 stopbits
=['1','1.5','2']
18 flowctrl
=['Hardware','None']
20 vbox
= wx
.BoxSizer(wx
.VERTICAL
)
22 menubar
= wx
.MenuBar()
28 file.Append(101, '&quit', 'Quit')
29 edit
.Append(101, '&option', 'Option')
30 about
.Append(101, '&about', 'About Me')
32 menubar
.Append(file, '&File')
33 menubar
.Append(edit
, '&Edit')
34 menubar
.Append(ctrl
, '&Ctrl')
35 menubar
.Append(about
, '&About')
37 self
.SetMenuBar(menubar
)
39 panel
= wx
.Panel(self
, -1,pos
=(0,0),size
=(480,460),style
=wx
.SUNKEN_BORDER
)
42 wx.ComboBox(panel, 3, pos=(10,330),size=(50,50),choices=baudrate,
44 wx.ComboBox(panel, 4, pos=(110,330),size=(50,-1),choices=databits,
46 wx.ComboBox(panel, 5, pos=(210,330),size=(50,-1),choices=parity,
48 wx.ComboBox(panel, 6, pos=(310,330),size=(50,-1),choices=stopbits,
50 wx.ComboBox(panel, 7, pos=(410,330),size=(50,-1),choices=flowctrl,
54 hbox
= wx
.BoxSizer(wx
.HORIZONTAL
)
57 self
.text
= wx
.TextCtrl(panel
, 3,
58 'Please select the varibles below before pressing Start button to get connected ...............',
59 size
=(530, 300), style
=wx
.TE_MULTILINE
)
61 ppanel
=wx
.Panel(self
,-1,pos
=(480,0),size
=(400,460),style
=wx
.SUNKEN_BORDER
)
62 self
.picture
=wx
.StaticBitmap(ppanel
,-1,pos
=(0,0),size
=(250,300),style
=wx
.SUNKEN_BORDER
)
63 self
.picture
.SetBackgroundColour(wx
.WHITE
)
65 hbox
.Add(self
.text
,-1)
66 hbox
.Add(self
.picture
,-1)
69 btn
= wx
.Button(panel
, wx
.ID_CLOSE
, 'Close',(100,370))
70 st
= wx
.Button(panel
, 2, 'Start',(10,370))
71 pause
= wx
.ToggleButton(panel
, 8, 'Pause', (190,370))
72 load
= wx
.Button(ppanel
,9,'Load Image',pos
=(10,370))
73 stop
= wx
.Button(ppanel
,10,'Stop',pos
=(120,370))
74 genimg
= wx
.Button(panel
, 11, 'GenImg', (290,370))
76 vbox
.Add(hbox
, 0, wx
.ALIGN_CENTRE
)
80 wx
.EVT_BUTTON(self
, wx
.ID_CLOSE
, self
.OnClose
)
81 wx
.EVT_BUTTON(self
, 2, self
.OnStart
)
83 wx.EVT_COMBOBOX(self, 3, self.OnSelect1)
84 wx.EVT_COMBOBOX(self, 4, self.OnSelect2)
85 wx.EVT_COMBOBOX(self, 5, self.OnSelect3)
86 wx.EVT_COMBOBOX(self, 6, self.OnSelect4)
87 wx.EVT_COMBOBOX(self, 7, self.OnSelect5)
89 wx
.EVT_TOGGLEBUTTON(self
, 8, self
.OnPause
)
90 wx
.EVT_BUTTON(self
, 9, self
.OnLoad
)
91 wx
.EVT_BUTTON(self
, 10, self
.OnStop
)
92 wx
.EVT_BUTTON(self
, 11, self
.OnGenimg
)
94 StatusBar
=self
.CreateStatusBar()
95 StatusBar
.SetStatusText("Ready...")
102 def OnClose(self
, event
):
108 def OnStart(self
, event
):
109 self
.t
= threading
.Thread(target
=self
.Brun
)
113 def OnPause(self
, event
):
123 def OnLoad(self
, event
):
126 lst
= os
.listdir(cur
)
131 for i
in range(1,148):
134 self
.picture
.SetFocus()
135 self
.picture
.SetBitmap(wx
.Bitmap(name
))
137 def OnStop(self
, event
):
138 #warnings.simplefilter("ignore",wx)
139 self
.picture
.SetFocus()
140 self
.picture
.SetBitmap(wx
.Bitmap('001.png'))
142 def OnGenimg(self
, event
):
143 m
=png_g(data
=self
.data
,wt
=50,ht
=60)
145 f
=open("gen.png",'wb')
150 img = Image.open("genimg.png")
151 re_img = img.resize(120)
152 re_img.save("genimg.png")
154 self
.picture
.SetFocus()
155 self
.picture
.SetBitmap(wx
.Bitmap('gen.png'))
159 def OnSelect1(self
, event
):
160 self
.br
= event
.GetSelection()
162 def OnSelect2(self
, event
):
163 self
.db
= event
.GetSelection()
165 def OnSelect3(self
, event
):
166 self
.pr
= event
.GetSelection()
168 def OnSelect4(self
, event
):
169 self
.sb
= event
.GetSelection()
171 def OnSelect5(self
, event
):
172 self
.fc
= event
.GetSelection()
176 # self.nf=open("name.dat",'w')
177 self
.df
=open("000.dat",'ab')
179 self
.StatusBar
.SetStatusText("About to writing data to 000.dat...")
181 ser
= serial
.Serial(port
='COM1',baudrate
=115200,bytesize
=serial
.EIGHTBITS
,parity
=serial
.PARITY_NONE
, stopbits
=serial
.STOPBITS_ONE
,timeout
=None,xonxoff
=0,rtscts
=0)
183 ser
.baudrate
= 115200
188 str = ser
.read(ser
.inWaiting())
193 #sbars=str(self.count)+"been written!"
194 #self.StatusBar.SetStatusText(s)
196 self
.text
.AppendText(". ")
197 while self
.status
==0 :
198 self
.status
= self
.status
207 Listbox(None, -1, 'Python Serial terminal')