2011-10-27 13 views
1

私はwxPythonを使って特定のディレクトリ内のすべてのファイルを検索しています。ファイルを検索すると、進行状況(ファイル数)がプログレスバーに表示され、ちょっとした背景が得られます。私がしたいのは、SetStatusTextが通常名前を表示するフレームの下部に進捗バーを移動することです。しかし、検索が開始されたら、名前/テキストを進捗バーに置き換えてください。現在、進行状況バーの位置を変更しようとすると、進行状況バーのすぐ上にしか表示されません。ステータスバー領域にプログレスバー(ゲージ)を入れてguiサイズをロックする方法

第2に、現在のサイズで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

関連する問題