From 1afb7afe825416e7b5f345c095030882ca630518 Mon Sep 17 00:00:00 2001 From: Anton Khirnov Date: Thu, 22 Jan 2009 17:21:23 +0100 Subject: [PATCH] Tabs: remove. i'm not using it -> no motivation to maintain. --- plugins/Tabs.py | 164 -------------------------------------------------------- 1 file changed, 164 deletions(-) delete mode 100644 plugins/Tabs.py diff --git a/plugins/Tabs.py b/plugins/Tabs.py deleted file mode 100644 index 48a2a50..0000000 --- a/plugins/Tabs.py +++ /dev/null @@ -1,164 +0,0 @@ -from PyQt4 import QtGui,QtCore - -import re -from thread import start_new_thread -from traceback import print_exc - -from misc import * -from clPlugin import * - -class ResetEvent(QtCore.QEvent): - song=None - def __init__(self, song=None): - QtCore.QEvent.__init__(self,QtCore.QEvent.User) - self.song=song -class AddHtmlEvent(QtCore.QEvent): - html=None - def __init__(self,html): - QtCore.QEvent.__init__(self,QtCore.QEvent.User) - self.html=html - -TABS_DIR_DEFAULT='/jammin' -TABS_ENGINE_DEFAULT='http://www.google.com/search?q=tabs|chords+"$artist"+"$title"' -TABS_SITES_DEFAULT='azchords.com
(.*?)
\n'\ - 'fretplay.com

(.*?)

\n'\ - 'guitaretab.com
(.*)?
'\ - -class wgTabs(QtGui.QWidget): - " contains the tabs" - txt=None - p=None # plugin - def __init__(self, p, parent=None): - QtGui.QWidget.__init__(self, parent) - self.p=p - self.txt=QtGui.QTextEdit(parent) - self.txt.setReadOnly(True) - - layout=QtGui.QVBoxLayout() - layout.addWidget(self.txt) - self.setLayout(layout) - - - def refresh(self): - song=self.p.monty.getCurrentSong() - try: - song._data['file'] - except: - self.resetTxt() - return - - self.resetTxt(song) - start_new_thread(self.fetchTabs, (song,)) - - def customEvent(self, event): - if isinstance(event,ResetEvent): - self.resetTxt(event.song) - elif isinstance(event,AddHtmlEvent): - self.txt.insertHtml(event.html) - - _mutex=QtCore.QMutex() - _fetchCnt=0 - def fetchTabs(self, song): - # only allow 1 instance to look tabs! - self._mutex.lock() - if self._fetchCnt: - self._mutex.unlock() - return - self._fetchCnt=1 - self._mutex.unlock() - - QtCore.QCoreApplication.postEvent(self, ResetEvent(song)) - - # save the data to file! - save_dir=self.p.getSetting('dir') - fInfo=QtCore.QFileInfo(save_dir) - if fInfo.isDir(): - tabsFName=toAscii('%s/%s - %s.txt'%(save_dir,song.getArtist(),song.getTitle())) - else: - tabsFName=None - # does the file exist? if yes, read that one! - try: - # we have it: load, and return! - file=open(tabsFName, 'r') - QtCore.QCoreApplication.postEvent(self, AddHtmlEvent(file.read())) - file.close() - self._fetchCnt=0 - return - except: - pass - - # fetch from inet - QtCore.QCoreApplication.postEvent(self, AddHtmlEvent('Searching tabs ...')) - - lines=self.p.getSetting('sites').split('\n') - sites={} - for line in lines: - if line.strip(): - sites[line[0:line.find('\t')]]=line[line.find('\t'):].strip() - # construct URL to search! - SE=self.p.getSetting('engine') - try: - ret=fetch(SE, sites, song, {}, stripHTML=False) - if ret: - txt='
%s

%s
'%(ret[0],ret[1],ret[1]) - # save for later use! - if tabsFName: - # we can't save if the path isn't correct - try: - file=open(tabsFName, 'w') - file.write(ret[0]) - file.close() - except: - pass - else: - txt="No tabs found :'(" - - QtCore.QCoreApplication.postEvent(self, ResetEvent(song)) - QtCore.QCoreApplication.postEvent(self, AddHtmlEvent(txt)) - except: - print_exc() - QtCore.QCoreApplication.postEvent(self, ResetEvent(song)) - QtCore.QCoreApplication.postEvent(self, AddHtmlEvent('Woops, site unavailable!'\ - '
You have an internet connection?')) - self._fetchCnt=0 - - def resetTxt(self, song=None): - self.txt.clear() - if song: - self.txt.insertHtml('%s\n
%s
'\ - '
\n\n'%(song.getTitle(), song.getArtist())) - - -class pluginTabs(Plugin): - o=None - def __init__(self, winMain): - Plugin.__init__(self, winMain, 'Tabs') - self.addMontyListener('onSongChange', self.refresh) - self.addMontyListener('onReady', self.refresh) - self.addMontyListener('onDisconnect', self.onDisconnect) - def _load(self): - self.o=wgTabs(self, None) - self.refresh(None) - def _unload(self): - self.o=None - def getInfo(self): - return "Show (and fetch) the tabs of the currently playing song." - - def _getDockWidget(self): - return self._createDock(self.o) - - def refresh(self, params): - self.o.refresh() - def onDisconnect(self, params): - self.o.resetTxt() - - def _getSettings(self): - sites=QtGui.QTextEdit() - sites.insertPlainText(self.getSetting('sites')) - return [ - ['engine', 'Search engine', 'The URL that is used to search. $artist, $title and $album are replaced in the URL.', QtGui.QLineEdit(self.getSetting('engine'))], - ['sites', 'Sites & regexes', 'This field contains all sites, together with the regex needed to fetch the tabs.\nEvery line must look like this: $domain $regex-start(.*?)$regex-end\n$domain is the domain of the tabs website, $regex-start is the regex indicating the start of the tabs, $regex-end indicates the end. E.g. footabs.org (.*?)', sites], - ['dir', 'Tabs directory', 'Directory where tabs should be stored and retrieved.', QtGui.QLineEdit(self.getSetting('dir'))], - ] - def afterSaveSettings(self): - self.o.onSongChange(None) -- 2.11.4.GIT