1

ユーザーがログインする必要がある UI を作成しています。ログイン自体には最大 10 秒かかります。ログイン後、TreeView をダウンロードして設定する関数への長い呼び出しが行われます。glib.timeout_add()ログインと関数が呼び出されている間、UI をロックしないように使用しようとしましpopulatelist()たが、gtk.main() はまだそれをロックしています。

def connect(self, widget, data):
    self.debug("Logging in")
    glib.timeout_add(500, self.login)
    self.debug("Logged in")

def login(self):
    self.debug("Starting self.gm.doLogin")
    logged_in = self.gm.doLogin(self.email, self.password)
    self.debug("Finsished self.gm.doLogin")
    if self.gm.logged_in:
        if self.connect_button.get_label() == "Connecting":
            self.debug("Getting SongWin")
            glib.timeout_add(500, self.populateSongWin)
            self.debug("Getting playLists")
            glib.timeout_add(500, self.populatePlaylists)
            self.action = "Getting songs"
            self.status_label.set_label("Status: %s; Songs: %s; Playlists: %s" %\
                                        (self.gm.logged_in, 
                                         len(self.gm.library),
                                         len(self.gm.playlists)))
            self.connect_button.set_label("Disconnect")
            self.connect_button.set_sensitive(True)
    self.action = "None"
    return False

私は見ることができるので、これが何らかの形で機能していることを知っています:

DEBUG: Logging in
DEBUG: Logged in
DEBUG: Starting self.gm.doLogin

誰が私が間違っているのか教えてもらえますか? 基本的に、アプリケーションは次の順序で実行する必要があります。

  1. self.gm.doLogin()
  2. self.populateSongWin()
  3. self.populatePlaylists()

3 つすべてが時間がかかり、順番に実行する必要があり、UI をブロックしません。

4

1 に答える 1

3

It looks like the application is blocked, but it is processing events. One of the events has to terminate the loop. You can check the idea behind the event loops in Wikipedia.

Nevertheless, in your code, you are using a local variable to get the login status, but you are using an instance variable to verify the status.

def login(self):
    self.debug("Starting self.gm.doLogin")
    logged_in = self.gm.doLogin(self.email, self.password)
    self.debug("Finsished self.gm.doLogin")
    if self.gm.logged_in:                                   <=
        [...]

Instead of self.gm.logged_in you should use logged_in in the condition for the if statement.

于 2012-10-17T07:35:26.763 に答える