针对android 7.0系统以上apk的安装 ,monkey ,卸载等操作
# -*- coding: utf-8 -*- # author = hjw ########################################################################### ## Python code generated with wxFormBuilder (version Jun 17 2015) ## http://www.wxformbuilder.org/ ## ## PLEASE DO "NOT" EDIT THIS FILE! ########################################################################### import wx import wx.xrc import os import threading import thread import logging import re import time import csv CMD_ADBINSTALL = "adb install " CMD_MONKEY = "adb shell monkey -p " CMD_UNINSTALL = "adb uninstall " ADB_GET_SERIALNO = "adb get-serialno" # 设备ID VERSION = 1.4 #版本号 LOG_FILE_NAME = "TOP_APK_Logcat.log" #logcat日志文件 import sys # 统一使用utf-8格式 default_encoding = 'utf-8' if sys.getdefaultencoding() != default_encoding: reload(sys) sys.setdefaultencoding(default_encoding) class topapkThread(threading.Thread): def __init__(self, filepath, listname, len, window): # 文件路径, 名称 ,index,self threading.Thread.__init__(self) self.listname = listname self.len = len self.window = window self.filepath = filepath self.timeToQuit = threading.Event() self.timeToQuit.clear() self.index = 0 self.listapkback = [] def stop(self): logging.debug("thread stop") print "stop thread" self.timeToQuit.set() #获取apk的列表 def getpackagenemlist(self): logging.debug('list package get') self.listapkpre = [] m = os.popen('adb shell pm list package ').read() # 安装APK之前得到package的所有包名 del self.listapkpre[:] # 清空列表 strlist = m.split('\n') logging.debug(u'添加到list中') for value in strlist: self.listapkpre.append(value) # 添加到list中 for indexapk in self.listapkpre: print 'apk pre--->' + indexapk # 列表中的文件 print 'apklistpre allcount--> %d' % len(self.listapkpre) self.apkcount =len(self.listapkpre) def run(self): self.getpackagenemlist() #获取package的列表 while (self.index < self.len): if len(self.listapkback) == 0: print 'No compare' else: # retD = list(set(self.listapkpre).difference(set(self.listapkback))) retD =list(set(self.listapkpre)^set(self.listapkback)) print u"新安装的APK is: %s " % retD logging.debug(u"新安装的APK is: %s " % retD) logging.debug('Install apk end ') # 字符串分割 print retD[0] packstring = retD[0] print u"PackageName全名 ----> %s" % packstring logging.debug(u'安装成功的package,并进行分离') u1, u2 = packstring.split(':') print "name --> %s" % u1 print "package-->%s" % u2 message = str(u2) + ' monkey test start \n ' print message logging.debug(message) wx.CallAfter(self.window.UpdateCtrlText, message) # --ignore-crashes cmd_monkey = "adb shell monkey -p " + str(u2)+ " -v --throttle 100 2000" print cmd_monkey outputline = os.popen(cmd_monkey).read() logging.debug(u'在mongkey测试结果中找一个是crash, 另外一个是finish') print outputline #1 crash pattern1 = re.compile(r'crash', re.IGNORECASE) result1 = pattern1.findall(outputline) print u'crash result-------->' + str(result1) if len(result1): logging.debug('crash result-->'+outputline) # # crash 日志文件log日志 # if len(result1) > 0: logging.debug('logcat already create,go home') dt = time.strftime('%Y-%m-%d-%H-%M-%S') logfilename = "Monkey_log_" + dt inpu = open(os.getcwd() + "/" + logfilename + ".log", 'w') inpu.write(str(u2) + " 执行Monkey时间发生crash,日志:") inpu.writelines(outputline) inpu.close() message = "\nHave Crash" wx.CallAfter(self.window.UpdateCtrlText, message) #3 判断是否结束了 pattern_finish = re.compile(r'Monkey finished', re.IGNORECASE) monkey_finish = pattern_finish.findall(outputline) # print u'monkey 执行日志--->' + outputline if len(monkey_finish): msg4 = u"SUCC" print u'monkey 测试成功' else: msg4 = u"FAIL" print u'monkey 测试失败' print 'monkey test end' logging.debug(str(u2)+" monkey test end ") wx.CallAfter(self.window.UpdateCtrlText, str(u2) + ' monkey test end \n') wx.CallAfter(self.window.UpdateCtrlText, str(u2) + ' uninstall apk start \n') # 3卸载 print 'uninstall apk start' cmd_uninstall = CMD_UNINSTALL + str(u2) print cmd_uninstall logging.debug(str(u2)+' uninstall apk start') #unin = os.popen(cmd_uninstall).read() unin = os.system(cmd_uninstall) print 'unistall result %d' %unin if unin == 0: msg6 = 'SUCC' print 'uninstall apk success' # if len(uninstallresultf): else: msg6 = "FAIL" print 'uninstall apk fail' self.listapkpre.append(value) # 添加到list中 print 'uninstall apk end' logging.debug(u2+ ' uninstall apk end') wx.CallAfter(self.window.UpdateCtrlText, u2 + ' uninstall apk finished \n') # 更新UI,msg信息中包含 apkName ,packagename,install ,monkey,unistall,other msg1 ,msg2,msg3,msg4 msg2 = u2 msg3 = 'SUCC' wx.CallAfter(self.window.UpListCtrl, msg1, msg2, msg3, msg4, msg6) time.sleep(10) # ----准备安装----------------- print u"准备安装 " + str(self.listname[self.index]) print "self.index-->"+str(self.index) logging.debug(u'准备安装:'+str(self.listname[self.index])) print "filepath--->" + self.filepath msg1 = self.listname[self.index] cmd_shell = CMD_ADBINSTALL + self.filepath + '\\' + self.listname[self.index] # instres = os.popen(cmd_shell).read() instres =os.system(cmd_shell) logging.debug('install_result--->%d' %instres) if instres == 0: print u"安装成功" del self.listapkback[:] # 清空列表 ms = " Install apk success \n" wx.CallAfter(self.window.UpdateCtrlText, ms) logging.debug('first apk has install finished ,and wait next ') #成功之后才有更新后的列表 ,失败是咩有更新列表的 n = os.popen('adb shell pm list package').read() # 安装APK之后得到package的所有包名 strlist1 = n.split('\n') for value in strlist1: self.listapkback.append(value) # 更新列表后,得到apk的列表 for indexapk in self.listapkback: print 'apkback--->' + indexapk print 'apklistback count %d' % len(self.listapkback) retDiff =list(set(self.listapkpre)^set(self.listapkback)) if len(retDiff) ==0 : print "安装系统了自带的apk了" #执行策略 ,这里直接跳过,更新到列表中,安装卸载,monkey都不执行, 直接绿灯通过 msg2 ="XXXXXXXXXX.package" msg3 ='SUCC' msg4 ='SUCC' msg5 ='SUCC' msg6 ='SUCC' wx.CallAfter(self.window.UpListCtrl, msg1, msg2, msg3, msg4, msg6) #清空 listapkback del self.listapkback[:] # else: # if instres ==1 or instres ==2: print u"安装失败" msf = " Install apk failure \n" wx.CallAfter(self.window.UpdateCtrlText, msf) msg1 = self.listname[self.index] msg2 = '' msg3 = 'FAIL' msg4 = 'FAIL' msg5 = 'FAIL' logging.error('install apk failed or has already install') wx.CallAfter(self.window.UpListCtrl, msg1, msg2, msg3, msg4, msg5) #更新UI界面 time.sleep(10) # print "执行安装 " + str(self.listname[self.index]) print 'self.index --->%d',self.index self.index += 1 # 等待30S print "wait 10" self.timeToQuit.wait(20) # 继续执行 print "go on" if self.timeToQuit.isSet(): print u"手动停止线程运行" logging.debug('handler stop ') wx.CallAfter(self.window.UpdateCtrlText, 'handler stop \n') break else: print u"执行完成---over " logging.debug('thread finish') wx.CallAfter(self.window.UpdateCtrlText, 'thread finish') wx.CallAfter(self.window.ThreadFinished, self) dict={} #字典 data =[] #数组 tup=() #元组 ########################################################################### ## Class MyFrame1 ########################################################################### class MyFrame1(wx.Frame): def __init__(self, parent): wx.Frame.__init__(self, parent, id=wx.ID_ANY, title=u"TOP_APK_7.0", pos=wx.DefaultPosition, size=wx.Size(1100, 600), style=wx.CLOSE_BOX | wx.DEFAULT_FRAME_STYLE | wx.TAB_TRAVERSAL) # self.icon = wx.Icon('rocket.ico', wx.BITMAP_TYPE_ICO) # title 图标 # self.SetIcon(self.icon) self.SetSizeHintsSz(wx.DefaultSize, wx.DefaultSize) self.INITMENU() self.m_splitter2 = wx.SplitterWindow(self, wx.ID_ANY, wx.DefaultPosition, wx.DefaultSize, wx.SP_3D) self.m_splitter2.SetSashGravity(0.2) self.m_splitter2.Bind(wx.EVT_IDLE, self.m_splitter2OnIdle) self.m_splitter2.SetMinimumPaneSize(20) self.initpanel() # parment self.threads = [] # 线程池 self.ischose = False # 是否选择了应用程序 self.filepath = "" #文件路径 self.id_index = 0 self.isConnect = False #手机是否连接 self.count = 0 #gauage 计数 self.isGauage = False #进度条是否执行 self.BTNBIND() self.INITSTATUBAR() self.logcat() def initpanel(self): bSizer7 = wx.BoxSizer(wx.HORIZONTAL) self.m_panel1 = wx.Panel(self.m_splitter2, wx.ID_ANY, wx.DefaultPosition, wx.DefaultSize, wx.TAB_TRAVERSAL) bSizer121 = wx.BoxSizer(wx.VERTICAL) bSizer10 = wx.BoxSizer(wx.HORIZONTAL) sbSizer2 = wx.StaticBoxSizer(wx.StaticBox(self.m_panel1, wx.ID_ANY, u"APK路径"), wx.HORIZONTAL) self.m_staticText5 = wx.StaticText(sbSizer2.GetStaticBox(), wx.ID_ANY, u"APK文件夹", wx.DefaultPosition, wx.DefaultSize, 0) self.m_staticText5.Wrap(-1) sbSizer2.Add(self.m_staticText5, 0, wx.ALL | wx.ALIGN_CENTER_VERTICAL, 5) self.m_textCtrl1 = wx.TextCtrl(sbSizer2.GetStaticBox(), wx.ID_ANY, wx.EmptyString, wx.DefaultPosition, wx.DefaultSize, 0) sbSizer2.Add(self.m_textCtrl1, 1, wx.ALL, 5) self.m_button1 = wx.Button(sbSizer2.GetStaticBox(), wx.ID_ANY, u"...", wx.DefaultPosition, wx.DefaultSize, 0) sbSizer2.Add(self.m_button1, 0, wx.ALL, 5) bSizer10.Add(sbSizer2, 1, wx.EXPAND, 5) bSizer121.Add(bSizer10, 0, wx.EXPAND, 5) m_checkList2Choices = [] self.m_checkList2 = wx.CheckListBox(self.m_panel1, wx.ID_ANY, wx.DefaultPosition, wx.DefaultSize, m_checkList2Choices, 0) bSizer121.Add(self.m_checkList2, 1, wx.ALL | wx.ALIGN_CENTER_HORIZONTAL | wx.EXPAND, 5) m_radioBox3Choices = [u"全选", u"全不选"] self.m_radioBox3 = wx.RadioBox(self.m_panel1, wx.ID_ANY, u"选择类型", wx.DefaultPosition, wx.DefaultSize, m_radioBox3Choices, 1, wx.RA_SPECIFY_ROWS) self.m_radioBox3.SetSelection(1) bSizer121.Add(self.m_radioBox3, 0, wx.ALL | wx.EXPAND | wx.ALIGN_RIGHT, 5) bSizer14 = wx.BoxSizer(wx.HORIZONTAL) self.m_button7 = wx.Button(self.m_panel1, wx.ID_ANY, u"确定", wx.DefaultPosition, wx.DefaultSize, 0) bSizer14.Add(self.m_button7, 0, wx.ALL | wx.ALIGN_CENTER_VERTICAL, 5) self.m_button8 = wx.Button(self.m_panel1, wx.ID_ANY, u"取消", wx.DefaultPosition, wx.DefaultSize, 0) bSizer14.Add(self.m_button8, 0, wx.ALL | wx.EXPAND | wx.ALIGN_BOTTOM, 5) bSizer121.Add(bSizer14, 0, wx.ALIGN_CENTER_HORIZONTAL, 5) self.m_panel1.SetSizer(bSizer121) self.m_panel1.Layout() bSizer121.Fit(self.m_panel1) self.m_panel2 = wx.Panel(self.m_splitter2, wx.ID_ANY, wx.DefaultPosition, wx.DefaultSize, wx.TAB_TRAVERSAL) bSizer131 = wx.BoxSizer(wx.VERTICAL) bSizer11 = wx.BoxSizer(wx.VERTICAL) sbSizer3 = wx.StaticBoxSizer(wx.StaticBox(self.m_panel2, wx.ID_ANY, u"结果输出"), wx.VERTICAL) self.m_listCtrl1 = wx.ListCtrl(sbSizer3.GetStaticBox(), wx.ID_ANY, wx.DefaultPosition, wx.DefaultSize, wx.LC_HRULES | wx.LC_REPORT | wx.LC_VRULES) self.m_listCtrl1.InsertColumn(0, "Id", width=80) self.m_listCtrl1.InsertColumn(1, "ApkName", width=80) self.m_listCtrl1.InsertColumn(2, "PackageName", width=150) self.m_listCtrl1.InsertColumn(3, "Install", width=100) self.m_listCtrl1.InsertColumn(4, "Monkey", width=100) self.m_listCtrl1.InsertColumn(5, "Uninstall", width=100) self.m_listCtrl1.DeleteAllItems() sbSizer3.Add(self.m_listCtrl1, 1, wx.ALL | wx.EXPAND, 5) bSizer11.Add(sbSizer3, 1, wx.EXPAND, 5) self.m_staticline1 = wx.StaticLine(self.m_panel2, wx.ID_ANY, wx.DefaultPosition, wx.DefaultSize, wx.LI_HORIZONTAL) bSizer11.Add(self.m_staticline1, 0, wx.EXPAND | wx.ALL, 5) self.m_textCtrl3 = wx.TextCtrl(self.m_panel2, wx.ID_ANY, wx.EmptyString, wx.DefaultPosition, wx.DefaultSize, wx.TE_MULTILINE) bSizer11.Add(self.m_textCtrl3, 1, wx.ALL | wx.EXPAND, 5) self.m_gauge2 = wx.Gauge(self.m_panel2, wx.ID_ANY, 100, wx.DefaultPosition, wx.DefaultSize, wx.GA_HORIZONTAL) self.m_gauge2.SetBezelFace(3) self.m_gauge2.SetShadowWidth(3) # bSizer11.Add(self.m_gauge2, 0, wx.ALL | wx.EXPAND, 5) bSizer131.Add(bSizer11, 6, wx.EXPAND, 5) bSizer12 = wx.BoxSizer(wx.HORIZONTAL) self.m_startBtn = wx.Button(self.m_panel2, wx.ID_ANY, u"开始", wx.DefaultPosition, wx.DefaultSize, 0) bSizer12.Add(self.m_startBtn, 0, wx.ALL | wx.ALIGN_CENTER_VERTICAL, 5) self.m_stopbtn = wx.Button(self.m_panel2, wx.ID_ANY, u"停止", wx.DefaultPosition, wx.DefaultSize, 0) bSizer12.Add(self.m_stopbtn, 0, wx.ALL | wx.ALIGN_CENTER_VERTICAL, 5) bSizer131.Add(bSizer12, 0, wx.ALIGN_CENTER_HORIZONTAL, 5) self.m_panel2.SetSizer(bSizer131) self.m_panel2.Layout() bSizer131.Fit(self.m_panel2) self.m_splitter2.SplitVertically(self.m_panel1, self.m_panel2, 304) bSizer7.Add(self.m_splitter2, 20, wx.EXPAND, 10) self.SetSizer(bSizer7) self.Layout() self.Centre(wx.BOTH) #进度条 def OnGauge(self): self.count =self.count+1 time.sleep(1) if self.count>=99: self.count = 0 self.m_gauge2.SetValue(self.count) # menu菜单 def INITMENU(self): self.m_menubar1 = wx.MenuBar(0) self.m_menu1 = wx.Menu() self.m_menuItem1 = wx.MenuItem(self.m_menu1, wx.ID_ANY, u"退出", wx.EmptyString, wx.ITEM_NORMAL) self.m_menu1.AppendItem(self.m_menuItem1) self.m_menubar1.Append(self.m_menu1, u" 文件 ") self.m_menu2 = wx.Menu() self.m_menuItem4 = wx.MenuItem(self.m_menu2, wx.ID_ANY, u"更改文件名称", wx.EmptyString, wx.ITEM_NORMAL) self.m_menuItem5 = wx.MenuItem(self.m_menu2, wx.ID_ANY, u"导出结果", wx.EmptyString, wx.ITEM_NORMAL) self.m_menu2.AppendItem(self.m_menuItem5) self.m_menu2.AppendItem(self.m_menuItem4) self.m_menubar1.Append(self.m_menu2, u" 配置 ") self.m_menu4 = wx.Menu() self.m_menuItem3 = wx.MenuItem(self.m_menu4, wx.ID_ANY, u"关于", wx.EmptyString, wx.ITEM_NORMAL) self.m_menu4.AppendItem(self.m_menuItem3) self.m_menubar1.Append(self.m_menu4, u" 帮助 ") self.SetMenuBar(self.m_menubar1) #按键的绑定 def BTNBIND(self): # Connect Events self.Bind(wx.EVT_CLOSE, self.OnWindowClose) self.Bind(wx.EVT_MENU, self.OnClose, id=self.m_menuItem1.GetId()) self.Bind(wx.EVT_MENU, self.Export, id=self.m_menuItem5.GetId()) self.Bind(wx.EVT_MENU, self.OnAbout, id=self.m_menuItem3.GetId()) self.Bind(wx.EVT_MENU, self.ReName, id=self.m_menuItem4.GetId()) self.m_button1.Bind(wx.EVT_BUTTON, self.OnOpen) self.m_button7.Bind(wx.EVT_BUTTON, self.OnSave) self.m_button8.Bind(wx.EVT_BUTTON, self.OnCancle) self.m_startBtn.Bind(wx.EVT_BUTTON, self.OnStart) self.m_stopbtn.Bind(wx.EVT_BUTTON, self.OnStop) self.m_stopbtn.Disable() self.m_radioBox3.Bind(wx.EVT_RADIOBOX, self.OnRadioBoxChose) # self.m_checkList2.Bind(wx.EVT_CHECKLISTBOX, self.OnCheckList) #状态栏 def INITSTATUBAR(self): self.m_statusBar1 = self.CreateStatusBar(2, wx.ST_SIZEGRIP, wx.ID_ANY) # 将状态栏分割为3个区域,比例为1:2:3 self.m_statusBar1.SetFieldsCount(4) self.m_statusBar1.SetStatusWidths([-1, -1, -1,-1]) # everage # 创建定时器 self.timer = wx.Timer(self) # 创建定时器,在OnTimer1中启动 self.Bind(wx.EVT_TIMER, self.OnTimer, self.timer) # 状态栏手机连接状态和当前时间 self.timer.Start(5000) # 启动执行一次 self.timer3 = wx.Timer(self) # 当前时间计时器 self.Bind(wx.EVT_TIMER, self.dataTime, self.timer3) self.timer3.Start(1000) # 启动执行一次 self.SetStatusText("Phone State : "+u'等待连接...', 0) self.SetStatusText(u'Monkey日志:'+os.getcwd(), 2) # crash 日志文件 self.SetStatusText(u'LogCat:'+os.getcwd()+'\\'+LOG_FILE_NAME, 3) # crash 日志文件 def logcat(self): logging.basicConfig(level=logging.DEBUG, format='%(asctime)s %(filename)s[line:%(lineno)d] %(levelname)s %(message)s', datefmt='%a, %d %b %Y %H:%M:%S', filename='LogCat_'+time.strftime('%Y-%m-%d-%H-%M-%S')+'.log', filemode='w') # Virtual event handlers, overide them in your derived class def OnTimer(self, event): # 状态栏手机连接状态 phoneName = os.popen(ADB_GET_SERIALNO).read() if phoneName: self.isConnect = True self.SetStatusText("Phone State : " + phoneName + u" 已连接", 0) # logging.debug('phone state already connect') if self.isGauage: self.OnGauge() else: self.SetStatusText(u"Phone State : 未连接,等待连接...", 0) self.isConnect = False self.m_startBtn.Enable() self.m_stopbtn.Disable() # 显示时间 def dataTime(self, event): t = time.localtime(time.time()) StrIMSt = "Time :" + time.strftime(" %I:%M:%S", t) self.SetStatusText(StrIMSt, 1) # 显示时间 # 更新listctrl def UpListCtrl(self, msg1, msg2, msg3, msg4, msg5): # pass line = "%s" % self.id_index self.m_listCtrl1.InsertStringItem(self.id_index, line) #id self.m_listCtrl1.SetStringItem(self.id_index, 1, msg1) #name self.m_listCtrl1.SetStringItem(self.id_index, 2, msg2) #pkagename self.m_listCtrl1.SetStringItem(self.id_index, 3, msg3) #install self.m_listCtrl1.SetStringItem(self.id_index, 4, msg4) #monkey self.m_listCtrl1.SetStringItem(self.id_index, 5, msg5) #uninstall self.id_index += 1 tup =(self.id_index,msg1,msg2,msg3,msg4,msg5) data.append(tup) print msg1,msg2,msg3,msg4,msg5 #更新文本信息 def UpdateCtrlText(self, message): self.m_textCtrl3.AppendText(message) #关闭 def OnClose(self, event): logging.debug('oclose') self.Destroy() #导出数据 def Export(self,event): logging.debug('Export result') print 'Export result' # csvfile =file('Result.csv','wb') # writer = csv.writer(csvfile) # writer.writerow(['id','apk_name','packagename','install_result','monkey_result','uninstall_result']) # self.createListCSV("FinalResult.csv",self.m_listCtrl1) # for inname in len(item): # # writer.writerow(item[inname]) # csvfile.close() with open("Result.csv","w") as csvfile: writer = csv.writer(csvfile) #先写入columns_name writer.writerow(['id','apk_name','packagename','install_result','monkey_result','uninstall_result']) for item in data: logging.debug(item) print item #写入多行用writerows writer.writerow(item) #重命名文件 def ReName(self,event): print u'rename' logging.debug('rename') """ Create and show the Open FileDialog """ cdlg = wx.DirDialog(self, u"选择重命名的文件夹", style=wx.DD_DEFAULT_STYLE) if cdlg.ShowModal() == wx.ID_OK: print cdlg.GetPath() self.remepath =cdlg.GetPath() renamelist = os.listdir(cdlg.GetPath()) renamelist.sort() self.renamesave =[] #修改名字之前 ,apk名称 i = 0 for rename_index in renamelist: print rename_index oldname = rename_index logging.debug('add apkname in list') self.renamesave.append(rename_index) os.rename(cdlg.GetPath()+"\\"+oldname,cdlg.GetPath()+"\\"+str(i)+".apk") dict[rename_index]=str(i)+".apk" i =i+1 for d_index in self.renamesave: logging.debug(u'字典对应,修改前的apk name 对应修改后的name') print d_index+"<--->"+ dict[d_index] logging.debug(u"写入到csv文件中") self.createDictCSV("dictfile.csv",dict) cdlg.Destroy() # 功能:将一个二重列表写入到csv文件中 # 输入:文件名称,数据列表 def createListCSV(self,fileName="", dataList=[]): with open(fileName, "wb") as csvFile: csvWriter = csv.writer(csvFile) for data in dataList: csvWriter.writerow(data) csvFile.close # 功能:将一个字典写入到csv文件中 def createDictCSV(self,fileName="", dataDict={}): with open(fileName, "wb") as csvFile: logging.debug(u"具体写入文件中") csvWriter = csv.writer(csvFile) for k,v in dataDict.iteritems(): csvWriter.writerow([k,v]) csvFile.close() # 关于 def OnAbout(self, event): description = """The tool is made for better execution of android automaiton ,the code is python and the current version is """ + str( VERSION) + """ and will be updatad slowly,if there is a problem is exuecution ,contact me ,My name is toby""" info = wx.AboutDialogInfo() info.SetVersion(str(VERSION)) info.SetDescription(description) info.AddDeveloper('JUNWANG He,Email: hejunwang@qiku.com') wx.AboutBox(info) # 打开 def OnOpen(self, event): dlg = wx.DirDialog(self, u"选择文件夹", style=wx.DD_DEFAULT_STYLE) if dlg.ShowModal() == wx.ID_OK: print dlg.GetPath() self.filepath = dlg.GetPath() print "filepath -->%s" % self.filepath # 文件路径 logging.debug("filepath -->%s" % self.filepath) self.m_textCtrl3.AppendText(u"APK文件路径--->%s" % self.filepath + "\n") self.m_textCtrl1.SetValue(dlg.GetPath()) l = os.listdir(dlg.GetPath()) #获取文件夹下的文件,并进行排序 l.sort() print l print u"文件列表长度%d" % len(l) self.filelen = len(l) self.listname = [] #apk的名称 self.m_checkList2.Clear() # 清空列表中的文件 for index in l: self.m_checkList2.Append(index) # 文件填充到单选列表中 print index self.listname.append(index) # #添加到listname[]中 # print self.m_checkList1.GetSelection() for n in self.listname: print "listname-->" + n self.splitname = n print n.split('.')[0] print self.splitname self.m_button7.Enable() dlg.Destroy() def ThreadFinished(self, thread): # 停止线程执行 print '移除线程' self.threads.remove(thread) self.m_startBtn.Enable() self.m_stopbtn.Disable() self.isGauage =False # 保存 def OnSave(self, event): self.ischose = True # 是否选择了应用程序 print "Set ischose =true" self.m_textCtrl3.AppendText("OnSave\n") # 取消 def OnCancle(self, event): # event.Skip() self.ischose = False # 是否选择了应用程序 print "Set ischose =fale" self.m_textCtrl3.AppendText("取消保存\n") # 开始按钮 def OnStart(self, event): logging.debug('onstart clicked') if self.ischose and (self.filepath != "") and self.isConnect: # 文件路径 文件列表名称 列表文件大小 thread = topapkThread(self.filepath, self.listname, self.filelen, self) self.threads.append(thread) thread.start() print 'All Select' self.m_startBtn.Disable() self.m_stopbtn.Enable() self.isGauage = True else: print 'Nothing Selected, Please chose testfile' self.m_startBtn.Enable() self.m_stopbtn.Disable() #停止按钮 def OnStop(self, event): self.m_startBtn.Enable() self.m_stopbtn.Disable() self.topapk_StopThread() self.m_textCtrl3.AppendText(u'手动停止\n') self.isGauage =False def topapk_StopThread(self): # 线程停止 while self.threads: thread = self.threads[0] # print "thread is -->"+thread thread.stop() self.threads.remove(thread) #分割线 def m_splitter2OnIdle(self, event): self.m_splitter2.SetSashPosition(343) self.m_splitter2.Unbind(wx.EVT_IDLE) # 选择框 def OnRadioBoxChose(self, event): rb = self.m_radioBox3.GetSelection() print rb if rb == 0: self.filecount = self.m_checkList2.GetCount() self.findcheck = self.m_checkList2.GetChecked() print "全部选择 " + str(self.filecount) + "\nfindcheck --" + str(len(self.findcheck)) # 全选 for n in range(self.filecount): self.m_checkList2.Check(n, check=True) # self.ischose = True else: print "全不选" for n in range(self.filecount): self.m_checkList2.Check(n, check=False) # self.ischose = False # event.Skip() def OnCheckList(self, event): index = self.m_checkList2.GetSelection() print "onChecklist---->index %d" % index #关闭窗口 def OnWindowClose(self, event): self.Destroy() if __name__ == '__main__': app = wx.App() MyFrame1(None).Show() app.MainLoop()