#!D:\Python27\python.exe
import wx
import subprocess
def ShowLog(text = "..."):
dlg = wx.TextEntryDialog(None, text)
if dlg.ShowModal() == wx.ID_OK:
res = dlg.GetValue
print (res)
class TextFrame(wx.Frame):
def __init__(self):
wx.Frame.__init__(self,None,-1,"Write SSID Tool",size=(300,250))
panel = wx.Panel(self,-1)
self.strSSIDFilePath = "/cache/pv_wifi_switch_ssid.cfg"
self.basicLabel = wx.StaticText(panel, -1, "...", pos=(100, 10))
basicLabel = wx.StaticText(panel,-1,"SSID:",pos=(65,50))
self.basicText = wx.TextCtrl(panel,-1,"Input ssid...",pos=(100,50),size=(175,-1))
button = wx.Button(panel,label="Write",pos=(100,80),size=(175,-1))
self.Bind(wx.EVT_BUTTON,self.OnWriteSsid,button)
#radio button
radio1 = wx.RadioButton(panel,-1,"cache",pos=(100,120),style=wx.RB_GROUP)
radio2 = wx.RadioButton(panel,-1,"data",pos=(100,140))
for rad in [radio1,radio2]:
self.Bind(wx.EVT_RADIOBUTTON,self.onRadio,rad)
#
self.GETERR = "Execution cmd fail!"
self.GETSUCC = "Cmd run success,not return code!"
self.GETRET = "get return code"
def onRadio(self,event):
radioselect = event.GetEventObject()
seltext = radioselect.GetLabel()
print seltext
if ("cache" == seltext):
self.strSSIDFilePath = "/cache/pv_wifi_switch_ssid.cfg"
self.strSSIDFilePath = "/data/pv_wifi_switch_ssid.cfg"
def MySendCmdFun(self,strCmd):
pipe = subprocess.Popen(strCmd,shell=True,stdout=subprocess.PIPE,stderr=subprocess.STDOUT)
print strCmd
if (-1 == pipe.wait()):
print 'write cmd fail!'
return self.GETERR
elif 0 == pipe.returncode:
ret = pipe.stdout.read()
print "stdout.read:",ret
if (0 == len(ret)):
return self.GETSUCC
return ret
return self.GETSUCC
def OnWriteSsid(self,event):
self.basicLabel.SetLabel("...")
ssidline = self.basicText.GetValue()
if "Input ssid..." == ssidline:
self.basicLabel.SetLabel("None input...")
return;
WriteCmd = 'adb shell \"echo -n %s > %s\"' % (ssidline,self.strSSIDFilePath)
#WriteCmd = "adb shell cat /cache/pv_wifi_switch_ssid.cfg"
#Write cmd
print "begin write..."
ret = self.MySendCmdFun(WriteCmd)
if self.GETSUCC != ret:
self.basicLabel.SetOwnForegroundColour("Red")
self.basicLabel.SetLabel(ret)
return
#check data
getdat = "adb shell cat %s" % self.strSSIDFilePath
ret = self.MySendCmdFun(getdat)
if (ssidline != ret):
self.basicLabel.SetOwnForegroundColour("Red")
self.basicLabel.SetLabel(ret)
return
self.basicLabel.SetOwnForegroundColour("Blue")
self.basicLabel.SetLabel("Write success")
if __name__ == '__main__':
app = wx.PySimpleApp();
frame = TextFrame()
frame.Show()
app.MainLoop()
import wx
import subprocess
def ShowLog(text = "..."):
dlg = wx.TextEntryDialog(None, text)
if dlg.ShowModal() == wx.ID_OK:
res = dlg.GetValue
print (res)
class TextFrame(wx.Frame):
def __init__(self):
wx.Frame.__init__(self,None,-1,"Write SSID Tool",size=(300,250))
panel = wx.Panel(self,-1)
self.strSSIDFilePath = "/cache/pv_wifi_switch_ssid.cfg"
self.basicLabel = wx.StaticText(panel, -1, "...", pos=(100, 10))
basicLabel = wx.StaticText(panel,-1,"SSID:",pos=(65,50))
self.basicText = wx.TextCtrl(panel,-1,"Input ssid...",pos=(100,50),size=(175,-1))
button = wx.Button(panel,label="Write",pos=(100,80),size=(175,-1))
self.Bind(wx.EVT_BUTTON,self.OnWriteSsid,button)
#radio button
radio1 = wx.RadioButton(panel,-1,"cache",pos=(100,120),style=wx.RB_GROUP)
radio2 = wx.RadioButton(panel,-1,"data",pos=(100,140))
for rad in [radio1,radio2]:
self.Bind(wx.EVT_RADIOBUTTON,self.onRadio,rad)
#
self.GETERR = "Execution cmd fail!"
self.GETSUCC = "Cmd run success,not return code!"
self.GETRET = "get return code"
def onRadio(self,event):
radioselect = event.GetEventObject()
seltext = radioselect.GetLabel()
print seltext
if ("cache" == seltext):
self.strSSIDFilePath = "/cache/pv_wifi_switch_ssid.cfg"
self.strSSIDFilePath = "/data/pv_wifi_switch_ssid.cfg"
def MySendCmdFun(self,strCmd):
pipe = subprocess.Popen(strCmd,shell=True,stdout=subprocess.PIPE,stderr=subprocess.STDOUT)
print strCmd
if (-1 == pipe.wait()):
print 'write cmd fail!'
return self.GETERR
elif 0 == pipe.returncode:
ret = pipe.stdout.read()
print "stdout.read:",ret
if (0 == len(ret)):
return self.GETSUCC
return ret
return self.GETSUCC
def OnWriteSsid(self,event):
self.basicLabel.SetLabel("...")
ssidline = self.basicText.GetValue()
if "Input ssid..." == ssidline:
self.basicLabel.SetLabel("None input...")
return;
WriteCmd = 'adb shell \"echo -n %s > %s\"' % (ssidline,self.strSSIDFilePath)
#WriteCmd = "adb shell cat /cache/pv_wifi_switch_ssid.cfg"
#Write cmd
print "begin write..."
ret = self.MySendCmdFun(WriteCmd)
if self.GETSUCC != ret:
self.basicLabel.SetOwnForegroundColour("Red")
self.basicLabel.SetLabel(ret)
return
#check data
getdat = "adb shell cat %s" % self.strSSIDFilePath
ret = self.MySendCmdFun(getdat)
if (ssidline != ret):
self.basicLabel.SetOwnForegroundColour("Red")
self.basicLabel.SetLabel(ret)
return
self.basicLabel.SetOwnForegroundColour("Blue")
self.basicLabel.SetLabel("Write success")
if __name__ == '__main__':
app = wx.PySimpleApp();
frame = TextFrame()
frame.Show()
app.MainLoop()