diff options
author | jerous <jerous@gmail.com> | 2008-11-16 14:18:27 +0100 |
---|---|---|
committer | jerous <jerous@gmail.com> | 2008-11-16 14:18:27 +0100 |
commit | f617c2aaf67e74e429f3b3b59a714fa282971489 (patch) | |
tree | 0f37de87c958a49fd7bd935ee2ee6348742a0e51 /plugins | |
parent | eda67631660a2b30a1f264384f8e0f9be73e1d40 (diff) |
Lyrics: only use plain text for output
Diffstat (limited to 'plugins')
-rw-r--r-- | plugins/Lyrics.py | 28 |
1 files changed, 19 insertions, 9 deletions
diff --git a/plugins/Lyrics.py b/plugins/Lyrics.py index c5e7cf3..e0d3936 100644 --- a/plugins/Lyrics.py +++ b/plugins/Lyrics.py @@ -21,6 +21,11 @@ class AddHtmlEvent(QtCore.QEvent): def __init__(self,html): QtCore.QEvent.__init__(self,QtCore.QEvent.User) self.html=html +class AddTextEvent(QtCore.QEvent): + text=None + def __init__(self,text): + QtCore.QEvent.__init__(self,QtCore.QEvent.User) + self.text=text LYRICS_ENGINE_DEFAULT='http://www.google.com/search?q=lyrics+"$artist"+"$title"' LYRICS_SITES_DEFAULT='azlyrics.com <br><br>.*?<br><br>(.*?)<br><br>\n'\ @@ -80,12 +85,13 @@ class wgLyrics(QtGui.QWidget): def onBtnEditClick(self): self.setMode(True) - self.txtView.setText(self.curLyrics) + self.txtView.setPlainText(self.curLyrics) def onBtnSaveClick(self): self.setMode(False) + self.curLyrics=self.txtView.toPlainText() file=open(self.getLyricsFilePath(monty.getCurrentSong()), 'w') - file.write(self.txtView.toHtml()) + file.write(self.curLyrics) file.close() # just to test if everything's still fine @@ -118,6 +124,8 @@ class wgLyrics(QtGui.QWidget): def customEvent(self, event): if isinstance(event,ResetEvent): self.resetTxt(event.song) + elif isinstance(event,AddTextEvent): + self.txtView.insertPlainText(event.text) elif isinstance(event,AddHtmlEvent): self.txtView.insertHtml(event.html) @@ -151,13 +159,12 @@ class wgLyrics(QtGui.QWidget): file=open(lyFName, 'r') self.curLyrics=file.read() file.close() - QtCore.QCoreApplication.postEvent(self, AddHtmlEvent(self.curLyrics.replace('\n', '<br />'))) + QtCore.QCoreApplication.postEvent(self, AddTextEvent(self.curLyrics)) self._fetchCnt=0 self.p.extended("Fetch lyrics from file") return except Exception, e: self.p.debug("fail - %s"%(str(e))) - pass # fetch from inet QtCore.QCoreApplication.postEvent(self, AddHtmlEvent('<i>Searching lyrics ...</i>')) @@ -172,27 +179,30 @@ class wgLyrics(QtGui.QWidget): SE=self.p.getSetting('engine') try: ret=fetch(SE, sites, song, {}) + QtCore.QCoreApplication.postEvent(self, ResetEvent(song)) if ret: self.p.extended("Success!") - txt='%s<br /><br /><a href="%s">%s</a>'%(ret[0],ret[1],ret[1]) self.curLyrics=ret[0] # save for later use! if lyFName: # we can't save if the path isn't correct try: file=open(lyFName, 'w') - file.write(ret[0]) + file.write(self.curLyrics) file.close() except: # probably a wrong path! pass else: + self.curLyrics="" txt="No lyrics found :'(" self.p.extended("Lyrics not found!") - self.curLyrics="" + QtCore.QCoreApplication.postEvent(self, AddTextEvent(txt)) + + QtCore.QCoreApplication.postEvent(self, AddTextEvent(self.curLyrics)) + if ret: + QtCore.QCoreApplication.postEvent(self, AddHtmlEvent('<br /><br /><a href="%s">%s</a>'%(ret[1],ret[1]))) - QtCore.QCoreApplication.postEvent(self, ResetEvent(song)) - QtCore.QCoreApplication.postEvent(self, AddHtmlEvent(txt.replace('\n', '<br />'))) except Exception, e: QtCore.QCoreApplication.postEvent(self, ResetEvent(song)) QtCore.QCoreApplication.postEvent(self, AddHtmlEvent('Woops, error! Possible causes:'\ |