简单的筛选格式 python工具,筛选python工具,自己写的简单的筛选格式
简单的筛选格式 python工具,筛选python工具,自己写的简单的筛选格式
自己写的简单的筛选格式 python工具,第一个版本只可以扫描文件,第二个版本扫描出来之后双击就能运行程序了。1.[代码]这个版本只能扫描文件
import wximport osimport timeclass Filter(wx.Frame): def __init__(self, parent, id): wx.Frame.__init__(self, parent, id, 'Filter', size=(310,400), style=wx.DEFAULT_FRAME_STYLE^(wx.MAXIMIZE_BOX)) self.panel = wx.Panel(self) #Icon self.icon = wx.Icon('icon.ico',wx.BITMAP_TYPE_ICO) self.SetIcon(self.icon) #dirButton self.dirButton = wx.Button(self.panel, -1, 'Choose Your Directory', pos=(20, 20)) self.dirButton.Bind(wx.EVT_BUTTON, self.onDirButton) self.tips = wx.StaticText(self.panel, -1, 'Your Directory:', pos=(20,55)) #outPut self.outPut = wx.TextCtrl(self.panel, -1, pos=(20, 100), size=(250, 200),style=wx.TE_MULTILINE|wx.HSCROLL) #List self.List = ['jpg', 'png', 'avi', 'mp4', 'rmvb', 'rar', 'zip', 'torrent'] self.formatList = wx.Choice(self.panel, -1, pos=(200,20), choices=self.List) self.formatList.Bind(wx.EVT_CHOICE, self.onFormatList) #Start and Quit self.startButton = wx.Button(self.panel, -1, 'Start', pos=(90,310)) self.startButton.Bind(wx.EVT_BUTTON, self.onStartButton) self.QuitButton = wx.Button(self.panel, -1, 'Quit', pos=(180,310)) self.QuitButton.Bind(wx.EVT_BUTTON, self.onQuitButton) def onDirButton(self, event): self.dirDialog = wx.DirDialog(None) if self.dirDialog.ShowModal() == wx.ID_OK: self.path = self.dirDialog.GetPath() else: self.path = '' self.dirDialog.Destroy() self.dirDialog.Destroy() self.directory = wx.StaticText(self.panel, -1, self.path, pos=(20,75)) def onFormatList(self, event): choice=self.formatList.GetSelection() self.yourFormat = self.List[choice] def onStartButton(self, event): try: startTime = time.clock() self.outPut.Clear() for root,dirs,files in os.walk(self.path): for file in files: if os.path.splitext(file)[1][1:] == self.yourFormat: self.outPut.AppendText(file +'\n') if self.outPut.GetValue() == '': self.outPut.SetValue('No %s File! \n' % self.yourFormat) endTime = time.clock() self.outPut.AppendText('Finished! Used %.3f s' % (endTime - startTime)) except AttributeError: retCode = wx.MessageBox('Choose Your Directory & Format!', 'FormatError', wx.OK | wx.ICON_ERROR) def onQuitButton(self, event): self.Destroy()app = wx.PySimpleApp()frame = Filter(parent=None, id=-1)frame.Show()app.MainLoop()
2.[代码]修改版,筛选了之后双击可以打开文件
import wximport os, sysimport time, win32apireload(sys)sys.setdefaultencoding('utf-8')class Filter(wx.Frame): def __init__(self, parent, id): wx.Frame.__init__(self, parent, id, 'Filter', size=(310,400), style=wx.DEFAULT_FRAME_STYLE^(wx.MAXIMIZE_BOX | wx.RESIZE_BORDER)) self.panel = wx.Panel(self) #Icon self.icon = wx.Icon('icon.ico',wx.BITMAP_TYPE_ICO) self.SetIcon(self.icon) #dirButton self.dirButton = wx.Button(self.panel, -1, 'Choose Your Directory', pos=(20, 20)) self.dirButton.Bind(wx.EVT_BUTTON, self.onDirButton) self.tips = wx.StaticText(self.panel, -1, 'Your Directory:', pos=(20,55)) #outPut self.outPut = wx.ListCtrl(self.panel, -1, pos=(20, 100),size=(250, 200), style=wx.LC_REPORT | wx.LC_VRULES | wx.LC_HRULES) self.outPut.Bind(wx.EVT_LIST_ITEM_ACTIVATED, self.DConLCItem) self.outPut.InsertColumn(0,'File Name', wx.LIST_FORMAT_RIGHT, 100) self.outPut.InsertColumn(1,'Directory', wx.LIST_FORMAT_LEFT, 100) #List self.List = ['jpg', 'png', 'avi', 'wmv', 'mp4', 'rmvb', 'rar', 'zip', 'exe', 'torrent'] self.formatList = wx.Choice(self.panel, -1, pos=(200,20), choices=self.List) self.formatList.Bind(wx.EVT_CHOICE, self.onFormatList) #Start and Quit self.startButton = wx.Button(self.panel, -1, 'Start', pos=(110,325)) self.startButton.Bind(wx.EVT_BUTTON, self.onStartButton) self.QuitButton = wx.Button(self.panel, -1, 'Quit', pos=(195,325)) self.QuitButton.Bind(wx.EVT_BUTTON, self.onQuitButton) def DConLCItem(self, event): #Double Click on ListCtrl Item fileIndex = self.outPut.GetFocusedItem() selectedDir = self.outPut.GetItem(fileIndex, 1).GetText() selectedFile = self.outPut.GetItemText(fileIndex) win32api.ShellExecute(0, 'open', selectedFile, '', selectedDir, 1) def onDirButton(self, event): self.dirDialog = wx.DirDialog(None) if self.dirDialog.ShowModal() == wx.ID_OK: self.path = self.dirDialog.GetPath() else: self.path = '' self.dirDialog.Destroy() self.dirDialog.Destroy() self.directory = wx.StaticText(self.panel, -1, self.path, pos=(20,75)) def onFormatList(self, event): choice=self.formatList.GetSelection() self.yourFormat = self.List[choice] def onStartButton(self, event): try: startTime = time.clock() self.outPut.DeleteAllItems() index = 0 for root, dirs, files in os.walk(self.path): for file in files: if os.path.splitext(file)[1][1:] == self.yourFormat: self.outPut.InsertStringItem(index, file) self.outPut.SetStringItem(index, 1, unicode(root)) index += 1 if self.outPut.GetItemCount() == 0: errorResult = wx.MessageBox('No %s Files!' % self.yourFormat, 'No File', wx.OK | wx.ICON_INFORMATION) endTime = time.clock() usedTime = wx.StaticText(self.panel, -1, 'Finished! Find %d file(s) ! Used %.3f s' % (self.outPut.GetItemCount(), endTime - startTime), pos=(20,305)) except AttributeError: retCode = wx.MessageBox('Choose Your Directory & Format!', 'FormatError', wx.OK | wx.ICON_ERROR) def onQuitButton(self, event): self.Destroy()app = wx.PySimpleApp()frame = Filter(parent=None, id=-1)frame.Show()app.MainLoop()
编橙之家文章,
相关内容
- 使用python重命名指定目录文件,,使用python重命名指
- python数据结构快速排序,python数据结构,<python数据结
- pyton清空当前目录下当前文件以外的所有文件,pyton当前
- 我使用Python计算日志文件中IP的次数,python日志文件,我
- Python方法求水仙花数原码实例,python水仙花,用Python编程
- 数据包分析ascii转码操作方法,ascii操作方法,关于数据
- 下载百度空间文章python源码,百度文章python源码,纯py
- 显示压缩文件内容Python源码,压缩文件python源码,zip压缩
- Python判断统计每个月天数源码示例,python源码,如何利用
- Python方法完成转换英文字符操作,,本文是关于Python方
评论关闭