質問

I'm working on Rhythmbox plugin and I need to show a dialog pane with a progress bar. Here's my code :

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()

The problem is it stop in dialog.run() instruction. I have also tested some code I found but without success. Can you please help me to fix this?

役に立ちましたか?

解決

dialog.run() starts a main loop which runs until the user has closed the dialog or pressed one of its response buttons. For what you want, it would be better to call dialog.show() instead.

Make sure you run the main loop (while Gtk.events_pending(): Gtk.main_iteration(False)) after each call to change the progress bar; or update the progress bar in an idle function. Otherwise you won't see the changes.

ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top