Damián Nohales avatar Damián Nohales committed 62bc781

Thread paranoia mode activated!

Also I guess that I'm merging vkolev changes but not sure, you really fuck me Mercurial.

Comments (0)

Files changed (5)

     else:
         app = SharkDown()
         env().set_app(app)
-        service = SingleService(app, env)
+        service = SingleService(app)
         gtk.main()
         self.window.show_all()
  
         
-    def on_init_thread_end(self):
+    def on_init_thread_success(self):
         self.window.set_sensitive(True)
         if os.path.exists("%s/.gsharkdown/downqueue.pkl" % os.environ.get("HOME")):
             self.load_downqueue_list("%s/.gsharkdown/downqueue.pkl" % os.environ.get("HOME"))
-
+            
+    def on_init_thread_failed(self):
+        error = guihelpers.ErrorMessage(None,
+                        "GrooveShark service has probably changed!\n" +
+                        "gSharkDown will not function propperly, so please" +
+                        "be patient until we find a solution.")
+        error.show_all()
 
     def get_iter_last(self, model):
         """
         """
         Tries to retrieve lyrics for selected song from the playlist.
         """
-        if self.playlist.playing_song != None:
-            self.lyrics_button.set_sensitive(False)
-            self.lyrics_button.set_label(_("Loading lyrics..."))
-            t = LyricsThread(self, self.playlist.playing_song)
+        if self.get_playing_song() != None:
+            t = LyricsThread(self, self.get_playing_song())
             t.start()
         else:
             info = guihelpers.InfoDialog(self.window,
                 _("There should be a playing song to view\nthe lyrics for it."))
             info.show_all()
-            
-    def open_lyrics_viewer(self, lyrics):
-        self.lyrics_button.set_sensitive(True)
-        self.lyrics_button.set_label(_("Lyrics"))
-        if "ERROR:" in lyrics:
-            error = guihelpers.ErrorMessage(self.window, lyrics)
-            error.run()
-        else:
-            lyrdiag = guihelpers.LyricsDialog(self.get_playing_song(), lyrics)
-            lyrdiag.show_all()
 
     def on_show_about(self, widget, data = None):
         """
             self.downloads.get_song(path).resume_download()
 
     def on_love_song(self, button):
-        if self.playlist.playing_song == None:
+        if self.get_playing_song() == None:
             info = guihelpers.InfoDialog(self.window,
                     _("There is no song to be loved.\n A song should be playing"))
             info.show_all()
         else:
             try:
-                track = self.lastfm.get_track(self.playlist.playing_song.get_artist(),
-                                          self.playlist.playing_song.get_title())
+                track = self.lastfm.get_track(self.get_playing_song().get_artist(),
+                                          self.get_playing_song().get_title())
                 track.love()
             except pylast.MalformedResponseError, e:
                 pass

lib/SingleService.py

+from enviroment import env 
 import dbus
 import dbus.service
 import dbus.glib
     and allow command line arguments to be passed to the application
     """
 
-    def __init__(self, app, env):
+    def __init__(self, app):
         self.app = app
-        self.env = env()
         bus_name = dbus.service.BusName('org.gsharkdown.Single',
                                        bus = dbus.SessionBus())
         dbus.service.Object.__init__(self, bus_name, '/org/gsharkdown/Single')
         Method to get the current playing song used in the
         commandline interface.
         """
-        if self.app.playlist.playing_song == None:
+        if self.app.get_playing_song() == None:
             return "gSharkDown is not playing"
         else:
-            song = self.app.playlist.playing_song.get_artist()
+            song = self.app.get_playing_song().get_artist()
             song = song + " - "
-            song = song + self.app.playlist.playing_song.get_title()
+            song = song + self.app.get_playing_song().get_title()
             return song
 
     @dbus.service.method(dbus_interface = 'org.gsharkdown.Single')
         """
         Method to get the player state used in the commandline interface
         """
-        if self.app.playlist.playing_song == None:
+        if self.app.get_playing_song() == None:
             return "Stopped"
         else:
             return "Playing"
         Method to get information about the current playing song
         artist, song, album, year. Used in the commandline interface
         """
-        if self.app.playlist.playing_song == None:
+        if self.app.get_playing_song() == None:
             return ""
         else:
-            song = self.app.playlist.playing_song
+            song = self.app.get_playing_song()
             info = "Artist: " + glib.markup_escape_text(song.get_artist()) + "\n"
             info += "Song:" + glib.markup_escape_text(song.get_title()) + "\n"
             info += "Album:" + glib.markup_escape_text(song.get_album()) + "\n"
         """
         Method to return the current version of gSharkDown.
         """
-        f = open("%s/VERSION" % self.env.BASEPATH, 'r')
+        f = open("%s/VERSION" % env().BASEPATH, 'r')
         version = f.read()
         f.close()
         return version
         Method to read the HELP file and display the help message
         when using the commandline interface.
         """
-        return open("%s/HELP" % self.env().BASEPATH, 'r').read()
+        return open("%s/HELP" % env().BASEPATH, 'r').read()

lib/guihelpers.py

-from enviroment import env, config
+from enviroment import env, app, config
 import gtk
 import os
 import sys
         @param message : The message of the update dialog
         @param secondary : The secondary message of the update dialog
         """
-        gtk.MessageDialog.__init__(self, None,
+        gtk.MessageDialog.__init__(self, app().window,
                                    gtk.DIALOG_DESTROY_WITH_PARENT,
                                    gtk.MESSAGE_INFO, gtk.BUTTONS_OK)
         self.set_title(title)
                 if e.args[0] == 11004:
                     time.sleep(1)
                 else:
-                    error = guihelpers.ErrorMessage(None,
-                                    "GrooveShark service has probably changed!\n" +
-                                    "gSharkDown will not function propperly, so please" +
-                                    "be patient until we find a solution.")
-                    error.show_all()
+                    gobject.idle_add(self.app.on_init_thread_failed)
                     p = 0
-                    self.stop()
                     
-        gobject.idle_add(self.app.on_init_thread_end)
-        
-    def stop(self):
-        self._stop.set()
-
-    def stopped(self):
-        return self._stop.isSet()
+        gobject.idle_add(self.app.on_init_thread_success)
 
 
 class PlayThread(threading.Thread):
         """
         if what in ['Stop', 'Play', 'Next', 'Previous']:
             if what == 'Stop':
-                self.app.on_play_selected(self.app.play_button)
+                gobject.idle_add(self.app.on_play_selected, self.app.play_button)
             elif what == 'Play':
-                self.app.on_play_selected(self.app.play_button)
+                gobject.idle_add(self.app.on_play_selected, self.app.play_button)
             elif what == 'Next':
-                self.app.play_next()
+                gobject.idle_add(self.app.on_play_next)
             elif what == 'Previous':
-                self.app.play_previous()
+                gobject.idle_add(self.app.on_play_previous)
 
 class SearchThread(threading.Thread):
 
         self.app = app
         self.query = query
         self.type = type
+        self.app.entry.set_sensitive(False)
 
     def run(self):
-        self.app.entry.set_sensitive(False)
         try:
             results = groove.getSearchResultsEx(self.query, self.type)
-            self.app.entry.set_sensitive(True)
-            self.app.result.clear()
-            if results:
-                for song_data in results:
-                    self.app.result.append_song(Song(song_data))
+            gobject.idle_add(self.fill_results, results)
         except Exception, e:
             print e.args
+            
+    def fill_results(self, results):
+        print threading.current_thread()
+        self.app.entry.set_sensitive(True)
+        self.app.result.clear()
+        if results:
+            for song_data in results:
+                self.app.result.append_song(Song(song_data))
 
 
 class UpdateThread(threading.Thread):
         threading.Thread.__init__(self)
 
     def run(self):
-        secondary_text = _("To update to the latest version ")
-        secondary_text += _("you can visit the <a href=\"http://https://bitbucket.org/vkolev/gsharkdown/downloads\"> ")
-        secondary_text += _("download site</a>. If you are using the latest version and want to be ")
-        secondary_text += _("informed about new versions, just enable the option in the <b>Preferences</b> dialog.")
-        new_version_text = _("<b>New version <span fgcolor=\"red\"><i>%s</i></span> is available</b>")
-        no_new_version_text = _("<b>You are using the latest version!</b>")
-        
         local = open("%s/VERSION" % env().BASEPATH, 'r')
         localversion = local.read().replace('\n', '')
         local.close()
         remote = urllib2.urlopen(env().UPDATE_URL)
         remoteversion = remote.read().replace('\n', '')
         
+        if remoteversion > localversion:
+            gobject.idle_add(self.show_update_dialog, True)
+        else:
+            gobject.idle_add(self.show_update_dialog, False)
+            
+    def show_update_dialog(self, is_update):
         config()['update_checked'] = 1
         config().write()
         
-        if remoteversion > localversion:
+        secondary_text = _("To update to the latest version ")
+        secondary_text += _("you can visit the <a href=\"http://https://bitbucket.org/vkolev/gsharkdown/downloads\"> ")
+        secondary_text += _("download site</a>. If you are using the latest version and want to be ")
+        secondary_text += _("informed about new versions, just enable the option in the <b>Preferences</b> dialog.")
+        
+        if is_update:
+            main_text = _("<b>New version <span fgcolor=\"red\"><i>%s</i></span> is available</b>")
+            
             dialog = guihelpers.UpdateDialog(_('New version'),
-                                             new_version_text % remoteversion,
-                                             secondary_text)
+                                                 main_text % remoteversion,
+                                                 secondary_text)
             dialog.show_all()
         else:
+            main_text = _("<b>You are using the latest version!</b>")
+            
             dialog = guihelpers.UpdateDialog(_('Latest version'),
-                                             no_new_version_text,
+                                             main_text,
                                              secondary_text)
             dialog.show_all()
 
         artist and songname.
         """
         threading.Thread.__init__(self)
-        self.parent = app
+        self.app = app
         self.song = song
+        self.app.lyrics_button.set_sensitive(False)
+        self.app.lyrics_button.set_label(_("Loading lyrics..."))
 
     def run(self):
         lyrics = lyrdblib.search(self.song.get_artist(), self.song.get_title())
-        gobject.idle_add(self.parent.open_lyrics_viewer, lyrics)
+        gobject.idle_add(self.open_viewer, lyrics)
+        
+    def open_viewer(self, lyrics):
+        print threading.current_thread()
+        self.app.lyrics_button.set_sensitive(True)
+        self.app.lyrics_button.set_label(_("Lyrics"))
+        if "ERROR:" in lyrics:
+            error = guihelpers.ErrorMessage(self.app.window, lyrics)
+            error.run()
+        else:
+            lyrdiag = guihelpers.LyricsDialog(self.app.get_playing_song(), lyrics)
+            lyrdiag.show_all()
 
 
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.