Skip to content

Commit

Permalink
fix ui freezes
Browse files Browse the repository at this point in the history
  • Loading branch information
timoloewe committed Apr 22, 2014
1 parent 2e482d6 commit eba0a49
Showing 1 changed file with 13 additions and 9 deletions.
22 changes: 13 additions & 9 deletions lLyrics/lLyrics.py
Original file line number Diff line number Diff line change
Expand Up @@ -569,7 +569,7 @@ def build_cache_path(self, artist, title):
def scan_selected_source_callback(self, action, activated_action):
if not action.get_active():
return

source = activated_action
if source == "SelectNothing" or source == self.current_source:
return
Expand Down Expand Up @@ -607,10 +607,8 @@ def search_online_action_callback(self, action):
def instrumental_action_callback(self, action):
lyrics = "-- Instrumental --"
self.write_lyrics_to_cache(self.path, lyrics)
Gdk.threads_add_idle(GLib.PRIORITY_DEFAULT_IDLE, self.show_lyrics, lyrics)

self.set_radio_menu_item_active("SelectNothing")
self.current_source = None
Gdk.threads_add_idle(GLib.PRIORITY_DEFAULT_IDLE, self.show_lyrics, lyrics)



Expand Down Expand Up @@ -854,7 +852,6 @@ def _scan_all_sources_thread(self, artist, title, cache):
self._scan_all_sources_thread(self.clean_artist, self.clean_title, False)
return

Gdk.threads_add_idle(GLib.PRIORITY_DEFAULT_IDLE, self.set_radio_menu_item_active, "SelectNothing")
self.current_source = None

Gdk.threads_add_idle(GLib.PRIORITY_DEFAULT_IDLE, self.set_menu_sensitive, True)
Expand All @@ -863,7 +860,9 @@ def _scan_all_sources_thread(self, artist, title, cache):



def get_lyrics_from_cache(self, path):
def get_lyrics_from_cache(self, path):
self.current_source = "From cache file"

# try to load lyrics from cache
if os.path.exists (path):
try:
Expand All @@ -872,10 +871,9 @@ def get_lyrics_from_cache(self, path):
cachefile.close()
except:
print("error reading cache file")
return ""

print("got lyrics from cache")
self.current_source = "From cache file"
Gdk.threads_add_idle(GLib.PRIORITY_DEFAULT_IDLE, self.set_radio_menu_item_active, _("From cache file"))
return lyrics

return ""
Expand All @@ -900,7 +898,6 @@ def get_lyrics_from_source(self, source, artist, title):

print("source: " + source)
self.current_source = source
Gdk.threads_add_idle(GLib.PRIORITY_DEFAULT_IDLE, self.set_radio_menu_item_active, source)

parser = self.dict[source].Parser(artist, title)
try:
Expand All @@ -923,6 +920,13 @@ def get_lyrics_from_source(self, source, artist, title):


def show_lyrics(self, lyrics):
if self.current_source is None:
self.set_radio_menu_item_active("SelectNothing")
elif self.current_source == "From cache file":
self.set_radio_menu_item_active(_("From cache file"))
else:
self.set_radio_menu_item_active(self.current_source)

if lyrics == "":
print("no lyrics found")
lyrics = _("No lyrics found")
Expand Down

0 comments on commit eba0a49

Please sign in to comment.