1

私はurwidライブラリをいじっていますが、これまでのところかなり素晴らしいものです。しかし、プログレスバーを機能させることができません。次のような簡単なテスト プログラムを作成しました。

import os
import urwid

    # a function that takes some times to complete
def dosomething(steps, bar):
    bar.done = steps
    for i in range(steps + 1):
        bar.set_completion(i)
        os.system('sleep 0.2')

    # make a button to start
task_btn = urwid.Button(u'Task')
    # progressbar object
pbar = urwid.ProgressBar('pg normal', 'pg complete')

    # function called when the task button is clicked
def on_task_clicked(button):
    dosomething(10, pbar)

    # setup signal handler for the button
urwid.connect_signal(task_btn, 'click', on_task_clicked)

    """
     create the interface and the mainloop.
     filler objects are our friend to prevent unpacking errors :D
   """

loop = urwid.MainLoop(urwid.Pile([urwid.Filler(task_btn), urwid.Filler(pbar)]))
loop.run()

私がそれを開始すると、プログレスバーは本来あるべき0%になります。次にボタンを押すと、数秒後にプログレスバーに 100% が表示されます。しかし、0% から 100% の間のステップがありません。彼らは現れないだけです。

また、render 関数の追加呼び出しも機能しません。

私も次のようなことを試しました:

def on_task_clicked(button):
    pbar.set_completion(pbar.current+1)

そして、これはうまく機能します。プログレスバーがループで呼び出されることに満足していないようです。それは奇妙に思えますか?誰かがこれを解決するために何かアイデアを持っていますか?

前もって感謝します :)

PS: 情報: Python 2.6.6、2.7、3.3 でテストされた urwid 1.2.0 はすべて同じです

4

1 に答える 1