2011-10-27 16 views
1

我正在使用wxPython來搜索特定目錄中的所有文件。當它搜索文件時,進度(文件數量)被髮送到進度條,只是爲了給出一點背景。我想要做的是將進度條向下移動到SetStatusText通常顯示名稱的框架底部。但是,當開始搜索時,我希望名稱/文本被進度條替換。目前,當我嘗試更改進度條的位置時,它只能在進度條上方看到。如何在狀態欄區域放置進度條(guage)並鎖定GUI大小

其次,我想鎖定它的當前大小,所以窗口不能調整大小。我看了幾個例子,但每個例子都以默認大小開始。我希望我的gui保持在我給它的大小,因爲按鈕的顯示方式保證。這裏是GUI代碼的樣子:

class MyApp(wx.App): 
    def OnInit(self): 
     frame = MainWindow("ST v2.0.0", (50, 60), (458, 332)) 
     frame.Show() 
     self.SetTopWindow(frame) 
     return True 



class MainWindow(wx.Frame): 
    def __init__(self, pos, size, title): 
     wx.Frame.__init__(self, None, -1, pos, size, title) 


     panel = wx.Panel(self, wx.ID_ANY) 
     panel.SetBackgroundColour('LIGHT GREY') 
     toolbar = self.CreateToolBar() 
     toolbar.Realize() 
     menuFile = wx.Menu() 
     menuFile.Append(1, "&About...") 
     menuFile.AppendSeparator() 
     menuFile.Append(2, "E&xit") 
     menuBar = wx.MenuBar() 
     menuBar.Append(menuFile, "&File") 
     menu2 = wx.Menu() 
     menu2.Append(wx.NewId(), "&Copy", "Copy in status bar") 
     menu2.AppendSeparator() 
     menu2.Append(wx.NewId(), "C&ut", "") 
     menu2.AppendSeparator() 
     menu2.Append(wx.NewId(), "Paste", "") 
     menu2.AppendSeparator() 
     menu2.Append(wx.NewId(), "&Options...", "Display Options") 
     menuBar.Append(menu2, "&Edit") 

     self.SetMenuBar(menuBar) 
     self.CreateStatusBar() 
     self.SetStatusText("Welcome to sQAST!")#can put connected here when logged in 
     self.Bind(wx.EVT_MENU, self.OnAbout, id=1) 
     self.Bind(wx.EVT_MENU, self.OnQuit, id=2) 

     x = 100 

     #Progress Gauge 
     self.gauge = wx.Gauge(panel, -1, x ,pos=(180, 0), size=(-1, 20)) 



     #Close button 
     self.button = wx.Button(panel, label="EXIT", pos=(229, 160), size=(229, 80)) 
     self.Bind(wx.EVT_BUTTON, self.OnQuit, self.button) 
     self.Bind(wx.EVT_CLOSE, self.OnCloseWindow) 
     #Dispenser button 
     self.button2 = wx.Button(panel, label="Serv 1", pos=(0, 160), size=(229, 80)) 
     self.Bind(wx.EVT_BUTTON, self.OnStartButton, self.button2) 
     #Site Server 
     self.button3 = wx.Button(panel, label="SERV 2", pos=(0, 80), size=(229, 80)) 
     self.Bind(wx.EVT_BUTTON, self.OnSiteservButton, self.button3) 
     #Local Search 
     self.button4 = wx.Button(panel, label="ABORT", pos=(229, 80), size=(229, 80)) 
     self.Bind(wx.EVT_BUTTON, self.OnAbortButton, self.button4) 
     self.button4.Disable() 
     self.shouldAbort = False 

這爲我工作:

count = 0 
    count2 = 0 
    for afile in filelist: 
     (head, filename) = os.path.split(afile) 
     if afile.endswith(".log") or afile.endswith(".txt"): 
      count2 += 1 
      self.progress_bar.Show() 
      wx.CallAfter(self.progress_bar.SetValue, count2)# This works .... 

      f=ftp.open(afile, 'r') 
      for i, line in enumerate(f.readlines()): 
       result = regex.search(line) 
       if self.shouldAbort: 
        return self.shouldAbort 
        break 

回答

4

有幾種不同的方法來做到這一點。我認爲,最簡單的是隻使用EnhancedStatusBar部件:http://wiki.wxpython.org/EnhancedStatusBar

然而,這個線程還提到一種方式與正常狀態欄來做到這一點:http://wxpython-users.1045709.n5.nabble.com/Add-a-progressbar-in-a-statusbar-td2365269.html

至於製作相框的尺寸「固定」,嘗試設置它的SetSizeHints達到了你想要的大小。

+0

EnhancedStatusBar的鏈接已損壞。 – suffa

+0

基於我在網站上看到的代碼嘗試實現EnhancedStatusBar後,我添加了一些代碼。我可以像以前一樣撥打電話嗎? – suffa

+0

我想通了! – suffa