wx.ProgressDialog の update メソッドには newmsg 引数があり、プロセスの各ステップで何が起こっているかをテキストで更新するはずですが、私のコードはこれを適切に行っていません。
wx.ProgressDialog http://www.wxpython.org/docs/api/wx.ProgressDialog-class.htmlのドキュメントへのリンクは次のとおりです。
また、コードを実行すると、約 50% 完了しているように見えると、プログレス バー自体の更新が停止します。
これら2つの問題を解決する方法を教えてもらえますか?
これが私のコードです:
import wx
import time
class Frame(wx.Frame):
def __init__(self, parent):
wx.Frame.__init__(self, parent, title="ProgressDialog sample")
self.progressMax = 4
self.count = 0
self.newstep='step '+str(self.count)
self.dialog = None
self.OnTimer(self.count)
def OnTimer(self, evt):
if not self.dialog:
self.dialog = wx.ProgressDialog("Progress in processing your data.",
self.newstep,
self.progressMax,
style=wx.PD_CAN_ABORT
| wx.PD_APP_MODAL
| wx.PD_SMOOTH
| wx.PD_AUTO_HIDE)
# Do Step One
print '----------------------------'
print 'Starting Step One now.'
self.count += 1
self.newstep='step '+str(self.count)
print 'self.count is: ',self.count
print 'self.newstep is: ',self.newstep
keepGoing = self.dialog.Update(self.count,self.newstep)
print '----------------------------'
time.sleep(5)
# Do Step Two
print '----------------------------'
print 'Starting Step Two now.'
self.count += 1
self.newstep='step '+str(self.count)
print 'self.count is: ',self.count
print 'self.newstep is: ',self.newstep
keepGoing = self.dialog.Update(self.count,self.newstep)
print '----------------------------'
time.sleep(5)
# Do Step Three
print '----------------------------'
print 'Starting Step Three now.'
self.count += 1
self.newstep='step '+str(self.count)
print 'self.count is: ',self.count
print 'self.newstep is: ',self.newstep
keepGoing = self.dialog.Update(self.count,self.newstep)
print '----------------------------'
time.sleep(5)
# Do Step Four
print '----------------------------'
print 'Starting Step Four now.'
self.count += 1
self.newstep='step '+str(self.count)
print 'self.count is: ',self.count
print 'self.newstep is: ',self.newstep
keepGoing = self.dialog.Update(self.count,self.newstep)
print '----------------------------'
time.sleep(5)
# Delete the progress bar when it is full
self.dialog.Update(self.progressMax)
time.sleep(3)
self.dialog.Destroy()
if __name__ == "__main__":
app = wx.PySimpleApp()
frame = Frame(None)
frame.Show()
app.MainLoop()
進行状況を確認するためにすべてを印刷していることに注意してください。印刷コマンドの結果は、進行状況ダイアログに表示されるものとは異なります。印刷コマンドはコードが指示していることを実行しているように見えますが、進行状況ダイアログはコードが指示していることを実行していないようであり、進行状況ダイアログは印刷コマンドの結果と一致していません。 .
これは Python のバージョン 2.6 にあります。
編集1:
-------------------------------------------------- ------------------------------
adw の提案に合わせて上記のコードを編集しました。newmsg を更新しないという問題は解消されたようですが、プログレス バー自体はまだ 50% しか表示されていないようで、ダイアログ ボックスの newmsg の出力に「ステップ 3」と表示されている場合に発生します。その後、進行状況バーが消えます。このソフトウェアを使用していないコンピュータ関係者は、プロセスが作業の約 50% しか完了していないと現実的に考えるかもしれません。ステップ 3 の早い段階で終了します。 ダイアログ ボックスに「ステップ 4」が表示されるようにコードを編集するにはどうすればよいですか? ProgressDialog が強制終了される前に、進行状況バーが実際に 1 秒または 2 秒間 100% までいっぱいになるようにするには?
編集 2:
-------------------------------------------------- ----------------------------
ご覧のとおり、ChrisC が提案した変更を上記のコードに追加しました。しかし、この新しく変更されたコードを実行しても、同じ問題が発生します。 したがって、上記のコードを編集したときに理解した形では、提案は機能しないようです。上記のコードに対して私ができる具体的なことを提案できますか? あなたのコンピュータで動作させるものはありますか?