zoukankan      html  css  js  c++  java
  • Everything:速度最快的文件名搜索工具(Linux版本) 转

     

    Everything是windows的一个快速搜索工具. 基本上转移到Linux上来后,没有怎么用过. 一直在用Gnome-Do,感觉还可以. 这个程序只是用来练习wxPython用的,目前还只是一个很简单的版本. 当然,后端用的是mlocate, 这个在Linux查找原理与everything基本一样,不过命令行. 而我只是写了一个前端GUI而已.

    以下是初步代码, 后续会一直完完善. 

    复制代码
     1 #/usr/bin/python
     2 #-*-<coding=UTF-8>-*-
     3 
     4 """
     5 本例为windows下everything程序的linux版本.后端基于locate实现.
     6 """
     7 
     8 import wx
     9 import os
    10 import subprocess
    11 
    12 class GuiMainFrame(wx.Frame):
    13     
    14     def __init__(self):
    15         wx.Frame.__init__(self,parent=None,id=-1,title="",pos=wx.DefaultPosition,size=wx.DefaultSize)
    16         
    17         #添加面板.
    18         panel = wx.Panel(self)
    19         
    20         #创建菜单栏
    21         menubar = wx.MenuBar()
    22         
    23         #File menu
    24         fileMenu = wx.Menu()
    25         fileMenu.Append(-1,"&Open","")
    26         menubar.Append(fileMenu,"&File")
    27 
    28         #Edit menu
    29         editMenu = wx.Menu()
    30         editMenu.Append(-1,"&Copy","")
    31         menubar.Append(editMenu,"&Edit")
    32 
    33         #Help/About menu
    34         helpMenu = wx.Menu()
    35         helpMenu.Append(-1,"About","")
    36         menubar.Append(helpMenu,"&Help")
    37         
    38         #调用SetMenuBar,使其在框架中显示出来
    39         self.SetMenuBar(menubar)
    40         
    41         #在面板中添加查找输入框
    42         #filterInput = wx.TextCtrl(panel,-1,"")
    43         self.filter = wx.SearchCtrl(panel,style=wx.TE_PROCESS_ENTER)
    44         self.filter.Bind(wx.EVT_TEXT_ENTER,self.DoSearch)
    45         #self.filter.Bind(wx.EVT_TEXT,self.DoSearch)  #这个会导致程序长时间无响应,所以还在找更有效率的方法.
    46         
    47         #在面板中添加类型选择框
    48         typeList=["all:*.*","document:*.doc,*.xls,*.ppt","audio:*.mp3","vedio:*.rmvb,*.mkv","application:*.exe"]
    49         fileType = wx.ComboBox(panel,-1,"",choices=typeList)
    50 
    51         #在面板中添加输出结果显示框
    52         self.multiText = wx.TextCtrl(panel,-1,"",style=wx.TE_MULTILINE|wx.TE_PROCESS_ENTER)
    53         self.multiText.SetMinSize((800,600))
    54 
    55         #添加状态栏,是否要加入到sizer中管理.
    56         statusbar = self.CreateStatusBar()
    57     
    58         #管理布局.创建两个sizer,主sizer管理filterSizer,结果显示框两个控件
    59         #filterSizer管理查找输入框和类型选择框
    60         mainSizer = wx.BoxSizer(wx.VERTICAL)
    61         
    62         filterSizer = wx.GridSizer(rows=1,cols=2)
    63         filterSizer.Add(self.filter,0,wx.EXPAND)
    64         filterSizer.Add(fileType,0,wx.EXPAND)
    65 
    66         #这句话导致文本框显示有空隙. 为什么不能这样用? menubar是否不需要添加进mainSizer
    67         #mainSizer.Add(menubar)
    68         mainSizer.Add(filterSizer,0,wx.EXPAND)
    69         mainSizer.Add(self.multiText,2,wx.EXPAND|wx.ALL)
    70         #frame中创建的statusbar,不需要添加到sizer中进行管理.
    71         #mainSizer.Add(statusbar,0,wx.EXPAND)
    72         
    73         #这个是关键之处,将sizer与frame关联起来.
    74         panel.SetSizer(mainSizer)
    75         mainSizer.Fit(self)
    76 
    77     def DoSearch(self,event):
    78         pattern = self.filter.GetValue()
    79         print pattern
    80         cmd = "/usr/bin/locate"
    81         arg1 = "-i"
    82         arg2 = "-d"
    83         arg3 = "/var/lib/mlocate/mlocate.db"
    84         arg4 = pattern
    85 
    86         p1=subprocess.Popen([cmd,arg1,arg2,arg3,arg4],shell=False,stdout=subprocess.PIPE,stderr=subprocess.PIPE)
    87         (stdoutdata,stderrdata) = p1.communicate()
    88         #stdoutdata = "Just test"
    89         self.multiText.SetValue(stdoutdata)
    90 
    91 if __name__ == "__main__":
    92     app = wx.PySimpleApp()
    93     frame = GuiMainFrame()
    94     frame.Show()
    95     app.MainLoop()
    复制代码
     
  • 相关阅读:
    【LeetCode】Validate Binary Search Tree
    【LeetCode】Search in Rotated Sorted Array II(转)
    【LeetCode】Search in Rotated Sorted Array
    【LeetCode】Set Matrix Zeroes
    【LeetCode】Sqrt(x) (转载)
    【LeetCode】Integer to Roman
    贪心算法
    【LeetCode】Best Time to Buy and Sell Stock III
    【LeetCode】Best Time to Buy and Sell Stock II
    CentOS 6 上安装 pip、setuptools
  • 原文地址:https://www.cnblogs.com/qiaoyanlin/p/7575218.html
Copyright © 2011-2022 走看看