0

我正在开发 Rhythmbox 插件,我需要显示一个带有进度条的对话框窗格。这是我的代码:

def download_all_lyrics_action_callback(self, action):
        progressbar = Gtk.ProgressBar();

        dialog = Gtk.Dialog(_('lLyrics Preferences'), self.shell.get_property('window'),
                Gtk.DialogFlags.MODAL | Gtk.DialogFlags.DESTROY_WITH_PARENT, (Gtk.STOCK_OK, Gtk.ResponseType.OK))

        content_area = dialog.get_content_area()
        content_area.pack_start(progressbar, True, True, 0)

        dialog.show_all()

        dialog.run()

        total = len(self.shell.props.library_source.props.query_model)
        i = 1;
        for row in self.shell.props.library_source.props.query_model:
            entry = row[0]
            title = entry.get_string(RB.RhythmDBPropType.TITLE)
            artist = entry.get_string(RB.RhythmDBPropType.ARTIST)
            print(title + " - " + artist)

            self.get_lyrics_for_song(title, artist)
            progressbar.set_fraction(i/total) 
        dialog.hide()

问题是它停止在dialog.run()指令中。我还测试了一些我发现但没有成功的代码。你能帮我解决这个问题吗?

4

1 回答 1

1

dialog.run()启动一个主循环,该循环一直运行到用户关闭对话框或按下其中一个响应按钮。对于你想要的,最好打电话dialog.show()来代替。

确保在每次调用后运行主循环 ( while Gtk.events_pending(): Gtk.main_iteration(False)) 以更改进度条;或在空闲函数中更新进度条。否则您将看不到更改。

于 2014-03-29T20:36:06.463 回答