2010-05-18 30 views
0

任何人都可以告訴我如何在wxPython中實現字幕樣式的進度條?作爲MSDN說:wxPython中的字幕樣式進度條

您可以在顯示 活動,但並不表示什麼任務 比例是完整的方式製作動畫。

謝謝。

alt text http://i.msdn.microsoft.com/dynimg/IC100842.png

我試過,但它似乎並沒有工作。計時器會打勾,但量表不會滾動。任何幫助?

import wx 
import time 

class MyForm(wx.Frame): 

    def __init__(self): 
     wx.Frame.__init__(self, None, wx.ID_ANY, "Timer Tutorial 1", 
            size=(500,500)) 

     # Add a panel so it looks the correct on all platforms 
     panel = wx.Panel(self, wx.ID_ANY) 

     self.timer = wx.Timer(self) 
     self.Bind(wx.EVT_TIMER, self.update, self.timer) 
     self.gauProgress = wx.Gauge(panel, range=1000, pos=(30, 50), size=(440, 20)) 
     self.toggleBtn = wx.Button(panel, wx.ID_ANY, "Start") 
     self.toggleBtn.Bind(wx.EVT_BUTTON, self.onToggle) 

    def onToggle(self, event): 
     btnLabel = self.toggleBtn.GetLabel() 
     if btnLabel == "Start": 
      print "starting timer..." 
      self.timer.Start(1000) 
      self.toggleBtn.SetLabel("Stop") 
     else: 
      print "timer stopped!" 
      self.timer.Stop() 
      self.toggleBtn.SetLabel("Start") 

    def update(self, event): 
     print "\nupdated: ", 
     print time.ctime() 
     self.gauProgress.Pulse() 

# Run the program 
if __name__ == "__main__": 
    app = wx.PySimpleApp() 
    frame = MyForm().Show() 
    app.MainLoop() 
+0

這是Vista還是XP與Vista佈局?我知道XP的一個佈局引擎,其中wxGauge的脈衝顯示不起作用。您發佈的代碼適用於vista。 – Rudi 2010-05-19 05:30:30

+0

這在XP上使用了常規佈局,但不適用於Windows 7.我猜想它也不適用於Windows Vista。有任何解決這個問題的方法嗎? – 2010-05-19 06:58:23

+0

似乎這已經被報告爲wxPython問題跟蹤系統上的一個錯誤。 http://trac.wxwidgets.org/ticket/11357 – 2010-05-21 07:45:22

回答

1

wxGauge具有脈衝()函數

gauge.Pulse() 
+0

正當我想我解決了它的時候,我遇到了更多的問題。 Rudi,你能告訴我一個關於如何使用Pulse功能的例子。我嘗試過谷歌和wxWiki,但無濟於事。謝謝。 – 2010-05-18 18:36:38

1

下面是一個例子:

def loadBallots(self): 
    self.dirtyBallots = Ballots() 
    self.dirtyBallots.exceptionQueue = Queue(1) 
    loadThread = Thread(target=self.dirtyBallots.loadUnknown, args=(self.filename,)) 
    loadThread.start() 

    # Display a progress dialog 
    dlg = wx.ProgressDialog(\ 
     "Loading ballots", 
     "Loading ballots from %s\nNumber of ballots: %d" % 
     (os.path.basename(self.filename), self.dirtyBallots.numBallots), 
     parent=self.frame, style = wx.PD_APP_MODAL | wx.PD_ELAPSED_TIME 
    ) 
    while loadThread.isAlive(): 
     sleep(0.1) 
     dlg.Pulse("Loading ballots from %s\nNumber of ballots: %d" % 
       (os.path.basename(self.filename), self.dirtyBallots.numBallots)) 
    dlg.Destroy() 

    if not self.dirtyBallots.exceptionQueue.empty(): 
     raise RuntimeError(self.dirtyBallots.exceptionQueue.get()) 

這是here

0

這樣的事情呢?

class ProgressDialog(wx.Dialog): 

    def __init__(self, parent, title, to_add=1): 
     """Defines a gauge and a timer which updates the gauge.""" 
     wx.Dialog.__init__(self, parent, title=title, style=wx.CAPTION) 
     self.count = 0 
     self.to_add = to_add 
     self.timer = wx.Timer(self) 
     self.gauge = wx.Gauge(self, range=100, size=(180, 30)) 

     sizer = wx.BoxSizer(wx.VERTICAL) 
     sizer.Add(self.gauge, 0, wx.ALL, 10) 
     self.SetSizer(sizer) 
     sizer.Fit(self) 
     self.SetFocus() 

     self.Bind(wx.EVT_TIMER, self.on_timer, self.timer) 
     self.timer.Start(30) # or however often you want 


    def on_timer(self, event): 
     """Increases the gauge's progress.""" 
     self.count += self.to_add 
     if self.count > 100: 
      self.count = 0 
     self.gauge.SetValue(self.count) 
+0

......這是一種方法。我以前使用過這種方法。我只是認爲使用專門用於顯示無限期過程的進展的東西可能會更好。 – 2010-05-21 07:43:06