wxPython实现everything的GUI

 1 #/usr/bin/python

 2 #-*-<coding=UTF-8>-*-

 3 

 4 """

 5 本例为windows下everything程序的linux版本的GUI.后端基于locate实现.

 6 """

 7 

 8 import wx

 9 

10 class GuiMainFrame(wx.Frame):

11     

12     def __init__(self):

13         wx.Frame.__init__(self,parent=None,id=-1,title="",pos=wx.DefaultPosition,size=wx.DefaultSize)

14         

15         #添加面板.

16         panel = wx.Panel(self)

17         

18         menubar = wx.MenuBar()

19         

20         fileMenu = wx.Menu()

21         fileMenu.Append(-1,"&Open","")

22         menubar.Append(fileMenu,"&File")

23 

24         #Edit menu

25         editMenu = wx.Menu()

26         editMenu.Append(-1,"&Copy","")

27         menubar.Append(editMenu,"&Edit")

28 

29         #Help/About menu

30         helpMenu = wx.Menu()

31         helpMenu.Append(-1,"About","")

32         menubar.Append(helpMenu,"&Help")

33         

34         #调用SetMenuBar,使其在框架中显示出来

35         self.SetMenuBar(menubar)

36         

37         #在面板中添加文本输入框

38         filterInput = wx.TextCtrl(panel,-1,"")

39         self.filter = wx.SearchCtrl(panel,style=wx.TE_PROCESS_ENTER)

40         self.filter.ShowCanelButton(True)

41         self.filter.Bind(wx.EVT_TEXT,self.RefeshText)

42         self.filter.Bind(wx.EVT_TEXT_ENTER,self.DoSearch)

43         fileType = wx.TextCtrl(panel,-1,"")

44         #输出结果显示框

45         mutiText = wx.TextCtrl(panel,-1,"",style=wx.TE_MULTILINE|wx.TE_PROCESS_ENTER)

46         mutiText.SetMinSize((800,600))

47 

48         #添加状态栏,是否要加入到sizer中管理.

49         statusbar = self.CreateStatusBar()

50     

51         #管理布局.

52         mainSizer = wx.BoxSizer(wx.VERTICAL)

53         

54         filterSizer = wx.GridSizer(rows=1,cols=2)

55         filterSizer.Add(filterInput,0,wx.EXPAND)

56         filterSizer.Add(fileType,0,wx.EXPAND)

57 

58         #这句话导致文本框显示有空隙. 为什么不能这样用? menubar是否不需要添加进mainSizer

59         #mainSizer.Add(menubar)

60         mainSizer.Add(filterSizer,0,wx.EXPAND)

61         mainSizer.Add(mutiText,2,wx.EXPAND|wx.ALL)

62         #frame中创建的statusbar,不需要添加到sizer中进行管理.

63         #mainSizer.Add(statusbar,0,wx.EXPAND)

64         

65         #这个是关键之处,将sizer与frame关联起来.

66         panel.SetSizer(mainSizer)

67         mainSizer.Fit(self)

68 

69 

70 if __name__ == "__main__":

71     app = wx.PySimpleApp()

72     frame = GuiMainFrame()

73     frame.Show()

74     app.MainLoop()

你可能感兴趣的:(wxPython)