The Last Modify. All Things Will Be Suspended Forever...
[sudos/utilities.git] / ssserial.py
blobbec4d70079bab9641e8950f476146bd13b00ee5c
1 #!/usr/bin/python
3 import wx, serial, threading, sys, warnings, png_g, os, time
4 from PIL import Image
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']
11 self.br = '9600'
12 databits=['8','7','6','5']
13 self.db = '8'
14 parity=['even','odd','None','space']
15 self.pr = 'None'
16 stopbits=['1','1.5','2']
17 self.sb = '1'
18 flowctrl=['Hardware','None']
19 self.fc = 'None'
20 vbox = wx.BoxSizer(wx.VERTICAL)
22 menubar = wx.MenuBar()
23 file = wx.Menu()
24 edit = wx.Menu()
25 ctrl = wx.Menu()
26 about = wx.Menu()
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)
40 """
42 wx.ComboBox(panel, 3, pos=(10,330),size=(50,50),choices=baudrate,
43 style=wx.CB_READONLY)
44 wx.ComboBox(panel, 4, pos=(110,330),size=(50,-1),choices=databits,
45 style=wx.CB_READONLY)
46 wx.ComboBox(panel, 5, pos=(210,330),size=(50,-1),choices=parity,
47 style=wx.CB_READONLY)
48 wx.ComboBox(panel, 6, pos=(310,330),size=(50,-1),choices=stopbits,
49 style=wx.CB_READONLY)
50 wx.ComboBox(panel, 7, pos=(410,330),size=(50,-1),choices=flowctrl,
51 style=wx.CB_READONLY)
52 """
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)
78 panel.SetSizer(vbox)
80 wx.EVT_BUTTON(self, wx.ID_CLOSE, self.OnClose)
81 wx.EVT_BUTTON(self, 2, self.OnStart)
82 """
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)
88 """
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...")
99 self.Show(True)
100 self.Centre()
102 def OnClose(self, event):
103 #ss=''
104 #self.df.write(ss)
105 self.df.close();
106 sys.exit()
108 def OnStart(self, event):
109 self.t = threading.Thread(target=self.Brun)
110 self.t.deamon=True
111 self.t.start()
113 def OnPause(self, event):
114 if self.status:
115 self.status = 0
116 #sys.exitfunc()
118 else :
119 self.status =1
120 #self.n.join()
121 #self.t.start()
123 def OnLoad(self, event):
124 path = '2010528'
125 cur = os.getcwd()
126 lst = os.listdir(cur)
127 tf=path in lst
128 if tf:
129 os.chdir(path)
131 for i in range(1,148):
132 time.sleep(0.05)
133 name = str(i)+'.png'
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)
144 md=m.dump()
145 f=open("gen.png",'wb')
146 f.write(md)
147 f.close()
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()
175 def Brun(self):
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...")
180 self.status = 1
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
184 str = '\n'
185 self.data=''
186 self.count = 0
187 while True:
188 str = ser.read(ser.inWaiting())
189 if len(str):
190 # self.data+=str
191 self.df.write(str)
192 #self.count+=1
193 #sbars=str(self.count)+"been written!"
194 #self.StatusBar.SetStatusText(s)
195 # str=hex(ord(str))
196 self.text.AppendText(". ")
197 while self.status ==0 :
198 self.status = self.status
201 def Nope(self):
202 while True:
203 i = 0
204 print 'a'
206 app = wx.App()
207 Listbox(None, -1, 'Python Serial terminal')
208 app.MainLoop()