summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorjerous <jerous@gmail.com>2008-11-01 15:52:16 +0100
committerjerous <jerous@gmail.com>2008-11-01 15:52:16 +0100
commitcbc8bb197eb70c751a8194f8a4d2baadc2aba8e8 (patch)
tree500019ca11a4c47dda69fff5be28918ac15a8054
parent02add72c4afae453702a3e2d93d754bc2b7c3464 (diff)
simplification for getting and setting settings in plugins
-rw-r--r--clPlugin.py26
-rw-r--r--plugins/AlbumCover.py38
-rw-r--r--plugins/Library.py1
-rw-r--r--plugins/Logger.py10
-rw-r--r--plugins/Lyrics.py28
-rw-r--r--plugins/MPD.py7
-rw-r--r--plugins/Notify.py31
-rw-r--r--plugins/PlayControl.py31
-rw-r--r--plugins/Playlist.py1
-rw-r--r--plugins/Scrobbler.py7
-rw-r--r--plugins/SongStatus.py12
-rw-r--r--plugins/Tabs.py24
12 files changed, 130 insertions, 86 deletions
diff --git a/clPlugin.py b/clPlugin.py
index a2522e9..7e82a99 100644
--- a/clPlugin.py
+++ b/clPlugin.py
@@ -1,5 +1,6 @@
from PyQt4 import QtGui, QtSvg, QtCore
+import plugins
from clMonty import monty
from clSettings import settings, mpdSettings
from misc import *
@@ -141,6 +142,31 @@ class Plugin:
return setting[3]
return None
+ def getSetting(self, setting, default=None, pluginClass=None):
+ if pluginClass==None:
+ pluginClass=self.__class__
+
+ # fetch the name
+ pluginClass=str(self.__class__).split('.')[-1].lower()[len('plugin'):]
+
+ if default==None:
+ # what module is this class in?
+ module='.'.join(str(self.__class__).split('.')[0:2])
+ # import the module
+ __import__(module, globals(), locals(), [], -1)
+ # set the default
+ default=eval("%s.%s_%s_DEFAULT"%(module, pluginClass.upper(), setting.upper()))
+
+ return settings.get("%s.%s"%(str(pluginClass).lower(), setting), default)
+
+ def setSetting(self, setting, value, pluginClass=None):
+ if pluginClass==None:
+ pluginClass=self.__class__
+ # fetch the name
+ pluginClass=str(self.__class__).split('.')[-1].lower()[len('plugin'):]
+ settings.set("%s.%s"%(str(pluginClass).lower(), setting), value)
+
+
def afterSaveSettings(self):
"""Override this one."""
diff --git a/plugins/AlbumCover.py b/plugins/AlbumCover.py
index 09c0baf..dfc24a8 100644
--- a/plugins/AlbumCover.py
+++ b/plugins/AlbumCover.py
@@ -6,13 +6,15 @@ import os
import shutil
# FETCH MODES
-AC_NO_FETCH='0'
-AC_FETCH_LOCAL_DIR='1'
-AC_FETCH_INTERNET='2'
+AC_NO_FETCH=0
+AC_FETCH_LOCAL_DIR=1
+AC_FETCH_INTERNET=2
-AC_DEFAULT_GFX_EXTS='jpg,jpeg,bmp,gif,png'
-AC_DEFAULT_FILES='cover,album'
-AC_DEFAULT_DOWNTO='$dirname($file)/$cover'
+ALBUMCOVER_GFX_EXTS_DEFAULT='jpg,jpeg,bmp,gif,png'
+ALBUMCOVER_FILES_DEFAULT='cover,album'
+ALBUMCOVER_DOWNLOADTO_DEFAULT='$dirname($file)/$cover'
+ALBUMCOVER_FETCH0_DEFAULT=1
+ALBUMCOVER_FETCH1_DEFAULT=1
class wgAlbumCover(QtGui.QWidget):
" container for the image"
@@ -20,8 +22,9 @@ class wgAlbumCover(QtGui.QWidget):
imgLoaded=False
p=None # plugin
acFormat=None
- def __init__(self,parent=None):
+ def __init__(self, p, parent=None):
QtGui.QWidget.__init__(self,parent)
+ self.p=p
self.img=QtGui.QImage()
self.setMinimumSize(64,64)
@@ -31,7 +34,7 @@ class wgAlbumCover(QtGui.QWidget):
file=QtGui.QFileDialog.getOpenFileName(self
, "Select album cover for %s - %s"%(song.getArtist(), song.getAlbum())
, ""
- , "Images ("+" ".join(map(lambda ext: "*.%s"%(ext), AC_DEFAULT_GFX_EXTS.split(',')))+")"
+ , "Images ("+" ".join(map(lambda ext: "*.%s"%(ext), ALBUMCOVER_GFX_EXTS_DEFAULT.split(',')))+")"
)
if file:
cur=self.getLocalACPath(monty.getCurrentSong(), True)
@@ -72,9 +75,9 @@ class wgAlbumCover(QtGui.QWidget):
# set default cover
self.imgLoaded=False
self.img.load('gfx/no-cd-cover.png')
- self.acFormat=format.compile(settings.get('albumcover.downloadto', AC_DEFAULT_DOWNTO))
+ self.acFormat=format.compile(self.p.getSetting('downloadto'))
for i in xrange(2):
- src=settings.get('albumcover.fetch%i'%(i), str(i))
+ src=self.p.getSetting('fetch%i'%(i))
if src!=AC_NO_FETCH and self.fetchCoverSrc(song, src):
# ACK!
self.imgLoaded=True
@@ -84,11 +87,11 @@ class wgAlbumCover(QtGui.QWidget):
def getLocalACPath(self, song, probe):
"""Get the local path of an albumcover. If $probe, then try covers*exts for existing file."""
# fetch gfx extensions
- exts=settings.get('albumcover.gfx.ext', AC_DEFAULT_GFX_EXTS).split(',')
+ exts=self.p.getSetting('gfx_exts').split(',')
exts=map(lambda ext: ext.strip(), exts)
# fetch cover album titles
- covers=settings.get('albumcover.files', AC_DEFAULT_FILES).split(',')
+ covers=self.p.getSetting('files').split(',')
covers=map(lambda title: title.strip(), covers)
params={'music_dir': mpdSettings.get('music_directory'), 'cover':'%s.%s'%(covers[0], exts[0])}
@@ -166,8 +169,7 @@ class pluginAlbumCover(Plugin):
self.addMontyListener('onStateChange', self.onEvent)
def _load(self):
- self.o=wgAlbumCover(None)
- self.o.p=self
+ self.o=wgAlbumCover(self, None)
self.o.refresh()
def _unload(self):
self.o=None
@@ -197,15 +199,15 @@ class pluginAlbumCover(Plugin):
nums=['first', 'second']
actions=[QtGui.QComboBox(), QtGui.QComboBox()]
for i,action in enumerate(actions):
- setting='albumcover.fetch%i'%(i)
+ setting='fetch%i'%(i)
action.addItem("On the %s action, Monty rested."%(nums[i]))
action.addItem("Local dir")
action.addItem("Internet")
- action.setCurrentIndex(int(settings.get(setting, str(i+1))))
+ action.setCurrentIndex(int(self.getSetting(setting, str(i+1))))
ret.append([setting, 'Action %i'%(i+1), 'What to do on the %s step.'%(nums[i]), action])
- ret.append(['albumcover.downloadto', 'Local dir', 'Specifies where to save album covers fetched from internet to.\nPossible tags: music_dir, cover, file, artist, title, album', QtGui.QLineEdit(settings.get('albumcover.downloadto', AC_DEFAULT_DOWNTO))])
- ret.append(['albumcover.files', 'Album cover files', 'Comma separated list of titles that are to be considered album covers. E.g. cover,album.', QtGui.QLineEdit(settings.get('albumcover.files', AC_DEFAULT_FILES))])
+ ret.append(['albumcover.downloadto', 'Local dir', 'Specifies where to save album covers fetched from internet to.\nPossible tags: music_dir, cover, file, artist, title, album', QtGui.QLineEdit(self.getSetting('downloadto'))])
+ ret.append(['albumcover.files', 'Album cover files', 'Comma separated list of titles that are to be considered album covers. E.g. cover,album.', QtGui.QLineEdit(self.getSetting('files'))])
return ret
diff --git a/plugins/Library.py b/plugins/Library.py
index 5c2d34d..e366405 100644
--- a/plugins/Library.py
+++ b/plugins/Library.py
@@ -4,7 +4,6 @@ from clPlugin import *
from misc import *
from wgPlaylist import Playlist
from wgSongList import clrRowSel
-from clSettings import settings
class pluginLibrary(Plugin):
o=None
diff --git a/plugins/Logger.py b/plugins/Logger.py
index 8556ecf..d4eaba8 100644
--- a/plugins/Logger.py
+++ b/plugins/Logger.py
@@ -3,13 +3,17 @@ from clPlugin import *
import log
from misc import Button
+LOGGER_LEVEL_DEFAULT=log.LOG_NORMAL
+
class wgLogger(QtGui.QWidget):
"""Shows log information"""
" list containing the log"
log=None
btnClear=None
- def __init__(self, parent=None):
+ p=None
+ def __init__(self, p, parent=None):
QtGui.QWidget.__init__(self, parent)
+ self.p=p
self.log=QtGui.QListWidget(self)
self.btnClear=Button("Clear", self.clear)
@@ -21,7 +25,7 @@ class wgLogger(QtGui.QWidget):
self.cmbLevel.addItem("Extended")
self.cmbLevel.addItem("Debug")
- self.cmbLevel.setCurrentIndex(int(settings.get("logger.level", log.LOG_NORMAL)))
+ self.cmbLevel.setCurrentIndex(int(self.p.getSetting("level")))
self.onCmbLevelChanged(self.cmbLevel.currentIndex())
layout=QtGui.QVBoxLayout()
@@ -51,7 +55,7 @@ class pluginLogger(Plugin):
def __init__(self, winMain):
Plugin.__init__(self, winMain, 'Logger')
def _load(self):
- self.o=wgLogger(None)
+ self.o=wgLogger(self, None)
log.setWriter(self.o.writer)
def _unload(self):
self.o=None
diff --git a/plugins/Lyrics.py b/plugins/Lyrics.py
index 56144aa..fe69b06 100644
--- a/plugins/Lyrics.py
+++ b/plugins/Lyrics.py
@@ -8,7 +8,6 @@ import webbrowser
import urllib
from misc import *
-from clSettings import settings,mpdSettings
from clMonty import monty
from clPlugin import *
@@ -23,10 +22,11 @@ class AddHtmlEvent(QtCore.QEvent):
QtCore.QEvent.__init__(self,QtCore.QEvent.User)
self.html=html
-LY_DEFAULT_ENGINE='http://www.google.com/search?q=lyrics+"$artist"+"$title"'
-LY_DEFAULT_SITES='azlyrics.com <br><br>.*?<br><br>(.*?)<br><br>\n'\
+LYRICS_ENGINE_DEFAULT='http://www.google.com/search?q=lyrics+"$artist"+"$title"'
+LYRICS_SITES_DEFAULT='azlyrics.com <br><br>.*?<br><br>(.*?)<br><br>\n'\
'oldielyrics.com song_in_top2.*?<br><br>(.*?)<script\n'\
- 'lyricstime.com phone-left.gif.*?<p>(.*?)</p>\n'\
+ 'lyricstime.com phone-left.gif.*?<p>(.*?)</p>\n'
+LYRICS_DIR_DEFAULT='/rabbit'
class wgLyrics(QtGui.QWidget):
" contains the lyrics"
@@ -38,8 +38,9 @@ class wgLyrics(QtGui.QWidget):
btnSearch=None
editMode=False
p=None # plugin
- def __init__(self, parent=None):
+ def __init__(self, p, parent=None):
QtGui.QWidget.__init__(self, parent)
+ self.p=p
self.curLyrics=""
self.btnEdit=Button("Edit lyrics", self.onBtnEditClick)
self.btnRefetch=Button("Refetch", self.onBtnRefetchClick)
@@ -70,7 +71,7 @@ class wgLyrics(QtGui.QWidget):
def onBtnSearch(self):
- SE=settings.get('lyrics.engine', LY_DEFAULT_ENGINE)
+ SE=self.p.getSetting('engine')
f=format.compile(SE)
SE_url=toAscii(f(format.params(monty.getCurrentSong())))
webbrowser.open(urllib.quote(SE_url, ":/+?="))
@@ -119,7 +120,7 @@ class wgLyrics(QtGui.QWidget):
self.txtView.insertHtml(event.html)
def getLyricsFilePath(self, song):
- save_dir=settings.get('lyrics.dir', '/holy_grail')
+ save_dir=self.p.getSetting('dir')
fInfo=QtCore.QFileInfo(save_dir)
if fInfo.isDir():
fName="%s - %s.txt"%(song.getArtist(), song.getTitle())
@@ -160,13 +161,13 @@ class wgLyrics(QtGui.QWidget):
QtCore.QCoreApplication.postEvent(self, AddHtmlEvent('<i>Searching lyrics ...</i>'))
self.p.extended("Fetch lyrics from internet")
- lines=settings.get('lyrics.sites', LY_DEFAULT_SITES).split('\n')
+ 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=settings.get('lyrics.engine', LY_DEFAULT_ENGINE)
+ SE=self.p.getSetting('engine')
try:
ret=fetch(SE, sites, song, {})
if ret:
@@ -214,8 +215,7 @@ class pluginLyrics(Plugin):
self.addMontyListener('onReady', self.refresh)
self.addMontyListener('onDisconnect', self.onDisconnect)
def _load(self):
- self.o=wgLyrics(None)
- self.o.p=self
+ self.o=wgLyrics(self, None)
self.o.refresh()
def _unload(self):
self.o=None
@@ -233,11 +233,11 @@ class pluginLyrics(Plugin):
def _getSettings(self):
sites=QtGui.QTextEdit()
- sites.insertPlainText(settings.get('lyrics.sites', LY_DEFAULT_SITES))
+ sites.insertPlainText(self.getSetting('sites'))
return [
- ['lyrics.engine', 'Search engine', 'The URL that is used to search. $artist, $title and $album are replaced in the URL.', QtGui.QLineEdit(settings.get('lyrics.engine', LY_DEFAULT_ENGINE))],
+ ['lyrics.engine', 'Search engine', 'The URL that is used to search. $artist, $title and $album are replaced in the URL.', QtGui.QLineEdit(self.getSetting('engine'))],
['lyrics.sites', 'Sites & regexes', 'This field contains all sites, together with the regex needed to fetch the lyrics.\nEvery line must look like this: $domain $regex-start(.*?)$regex-end\n$domain is the domain of the lyrics website, $regex-start is the regex indicating the start of the lyrics, $regex-end indicates the end. E.g. foolyrics.org <lyrics>(.*?)</lyrics>', sites],
- ['lyrics.dir', 'Lyrics directory', 'Directory where lyrics should be stored and retrieved.', QtGui.QLineEdit(settings.get('lyrics.dir'))],
+ ['lyrics.dir', 'Lyrics directory', 'Directory where lyrics should be stored and retrieved.', QtGui.QLineEdit(self.getSetting('dir'))],
]
def afterSaveSettings(self):
self.o.refresh()
diff --git a/plugins/MPD.py b/plugins/MPD.py
index b6d7d4e..dd41230 100644
--- a/plugins/MPD.py
+++ b/plugins/MPD.py
@@ -4,6 +4,9 @@ from clPlugin import *
from misc import *
from clSettings import settings, mpdSettings
+MPD_HOST_DEFAULT='localhost'
+MPD_PORT_DEFAULT='6600'
+
class pluginMPD(Plugin):
def __init__(self, winMain):
Plugin.__init__(self, winMain, 'MPD')
@@ -13,8 +16,8 @@ class pluginMPD(Plugin):
def _getSettings(self):
return [
- ['host', 'Host', 'Host where mpd resides.', QtGui.QLineEdit(settings.get('host', 'localhost'))],
- ['port', 'Port', 'Port of mpd.', QtGui.QLineEdit(settings.get('port', '6600'))],
+ ['host', 'Host', 'Host where mpd resides.', QtGui.QLineEdit(self.getSetting('host'))],
+ ['port', 'Port', 'Port of mpd.', QtGui.QLineEdit(self.getSetting('port'))],
['music_directory', 'Music directory', 'Root directory where all music is located.', QtGui.QLineEdit(mpdSettings.get('music_directory')), mpdSettings],
['', 'Update database', 'Updates the database.\nUse this if you have changed the music_directory. Updating will save all entries on the MPD tab.', Button('Update db', self.onBtnUpdateDBClick)],
]
diff --git a/plugins/Notify.py b/plugins/Notify.py
index 56f1175..85c1a92 100644
--- a/plugins/Notify.py
+++ b/plugins/Notify.py
@@ -4,17 +4,17 @@ from traceback import print_exc
import format
from misc import *
-from clSettings import settings,mpdSettings
from clMonty import monty
from clPlugin import *
-NOTIFY_DEFAULT_SONGFORMAT='$if($artist,$artist)$if($album, - [$album #$track])\n$title ($timems)';
-NOTIFY_DEFAULT_TIMER=3
+NOTIFY_SONGFORMAT_DEFAULT='$if($artist,$artist)$if($album, - [$album #$track])\n$title ($timems)';
+NOTIFY_TIMER_DEFAULT=3
class winNotify(QtGui.QWidget):
_timerID=None
resizeWindow=True
winMain=None
+ p=None
# data used for showing off
timer=None
@@ -22,8 +22,9 @@ class winNotify(QtGui.QWidget):
song=None
xtra_tags=None
- def __init__(self, winMain, parent=None):
+ def __init__(self, p, winMain, parent=None):
QtGui.QWidget.__init__(self, parent)
+ self.p=p
self.winMain=winMain
self.setWindowFlags(QtCore.Qt.ToolTip)
@@ -127,39 +128,39 @@ class pluginNotify(Plugin):
self.addMontyListener('onVolumeChange', self.onVolumeChange)
def _load(self):
- self.o=winNotify(self.winMain)
+ self.o=winNotify(self, self.winMain)
def _unload(self):
self.o=None
def getInfo(self):
return "Show interesting events in a popup window."
def onSongChange(self, params):
- self.o.show(settings.get('notify.songformat', NOTIFY_DEFAULT_SONGFORMAT).replace("\n", "\\n"), monty.getCurrentSong()
- , time=settings.get('notify.timer', NOTIFY_DEFAULT_TIMER))
+ self.o.show(self.getSetting('songformat').replace("\n", "\\n"), monty.getCurrentSong()
+ , time=self.getSetting('timer'))
def onReady(self, params):
- self.o.show('montypc loaded!', monty.getCurrentSong(), time=settings.get('notify.timer', NOTIFY_DEFAULT_TIMER))
+ self.o.show('montypc loaded!', monty.getCurrentSong(), time=self.getSetting('timer'))
def onDisconnect(self, params):
- self.o.show('Disconnected!', time=settings.get('notify.timer', NOTIFY_DEFAULT_TIMER))
+ self.o.show('Disconnected!', time=self.getSetting('timer'))
def onStateChange(self, params):
- self.o.show(params['newState'], monty.getCurrentSong(), time=settings.get('notify.timer', NOTIFY_DEFAULT_TIMER))
+ self.o.show(params['newState'], monty.getCurrentSong(), time=self.getSetting('timer'))
def onVolumeChange(self, params):
- self.o.show('Volume: %i%%'%(params['newVolume']), monty.getCurrentSong(), time=settings.get('notify.timer', NOTIFY_DEFAULT_TIMER))
+ self.o.show('Volume: %i%%'%(params['newVolume']), monty.getCurrentSong(), time=self.getSetting('timer'))
def _getSettings(self):
txt=QtGui.QTextEdit()
- txt.insertPlainText(settings.get('notify.songformat', NOTIFY_DEFAULT_SONGFORMAT))
+ txt.insertPlainText(self.getSetting('songformat'))
return [
['notify.songformat', 'Song format', 'How to format the current playing song.', txt],
- ['notify.timer', 'Show seconds', 'How many seconds does the notification have to be shown.', QtGui.QLineEdit(str(settings.get('notify.timer', NOTIFY_DEFAULT_TIMER)))],
+ ['notify.timer', 'Show seconds', 'How many seconds does the notification have to be shown.', QtGui.QLineEdit(str(self.getSetting('timer')))],
]
def afterSaveSettings(self):
try:
- int(settings.get('notify.timer', NOTIFY_DEFAULT_TIMER))
+ int(self.getSetting('timer'))
except:
- settings.set('notify.timer', NOTIFY_DEFAULT_TIMER)
+ self.getSetting('timer')
self.getSettingWidget('notify.timer').setText(str(NOTIFY_DEFAULT_TIMER))
self.onSongChange(None)
diff --git a/plugins/PlayControl.py b/plugins/PlayControl.py
index a23283d..e903c2f 100644
--- a/plugins/PlayControl.py
+++ b/plugins/PlayControl.py
@@ -21,6 +21,11 @@ PC_REPEAT_SONG=1 # repeat current song
PC_REPEAT_ALBUM=2 # repeat current album
PC_REPEAT_PLAYLIST=3 # repeat playlist
+PLAYCONTROL_SHUFFLE_DEFAULT=PC_RANDOM_ALBUM
+PLAYCONTROL_OLDSHUFFLE_DEFAULT=PLAYCONTROL_SHUFFLE_DEFAULT
+PLAYCONTROL_QUEUE_DEFAULT=''
+PLAYCONTROL_REPEAT_DEFAULT=PC_REPEAT_PLAYLIST
+
class wgPlayControl(QtGui.QWidget):
"""Displays controls for interacting with playing, like play, volume ..."""
@@ -52,8 +57,9 @@ class wgPlayControl(QtGui.QWidget):
# what mode where we in before the queue started?
beforeQueuedMode=None
- def __init__(self, parent=None):
+ def __init__(self, p, parent=None):
QtGui.QWidget.__init__(self, parent)
+ self.p=p
class wgSvgSwitcher(QtSvg.QSvgWidget):
"""Widget showing an svg-image, which, when clicked, will (un)hide an element."""
@@ -93,14 +99,14 @@ class wgPlayControl(QtGui.QWidget):
self.cmbShuffle.addItem('Random song')
self.cmbShuffle.addItem('Random album')
self.cmbShuffle.addItem('Queue')
- self.cmbShuffle.setCurrentIndex(int(settings.get('playcontrol.shuffle', PC_RANDOM_SONG)))
+ self.cmbShuffle.setCurrentIndex(int(self.p.getSetting('shuffle')))
self.cmbRepeat=QtGui.QComboBox(self)
self.cmbRepeat.addItem('No repeat')
self.cmbRepeat.addItem('Repeat current song')
self.cmbRepeat.addItem('Repeat album')
self.cmbRepeat.addItem('Playlist')
- self.cmbRepeat.setCurrentIndex(int(settings.get('playcontrol.repeat', PC_REPEAT_PLAYLIST)))
+ self.cmbRepeat.setCurrentIndex(int(self.p.getSetting('repeat')))
self.objects=[self.slrVolume, self.slrTime,
self.btnStop, self.btnNext, self.btnPrevious]
@@ -212,7 +218,7 @@ class wgPlayControl(QtGui.QWidget):
else:
# no songs anymore, so we must restore the old mode!
# We should never arrive here though ...
- self.cmbShuffle.setCurrentIndex(int(settings.get('playcontrol.oldshuffle', 0)))
+ self.cmbShuffle.setCurrentIndex(int(self.p.getSetting('oldshuffle')))
if random==PC_RANDOM_NO:
# just follow our leader Monty.
@@ -244,7 +250,7 @@ class wgPlayControl(QtGui.QWidget):
if random==PC_RANDOM_QUEUE:
# now here reset the mode to the previous, if needed
if len(self.queuedSongs)==0:
- self.cmbShuffle.setCurrentIndex(int(settings.get('playcontrol.oldshuffle', 0)))
+ self.cmbShuffle.setCurrentIndex(int(self.p.getSetting('oldshuffle')))
if nextID!=None:
monty.play(nextID)
@@ -293,7 +299,7 @@ class wgPlayControl(QtGui.QWidget):
self.svgVolume.load('gfx/stock_volume-%s.svg'%(mode))
def onCmbRepeatChanged(self, newval):
- settings.set('playcontrol.repeat', newval)
+ self.p.setSetting('repeat', newval)
if newval==PC_REPEAT_PLAYLIST:
monty.repeat(1)
else:
@@ -302,16 +308,16 @@ class wgPlayControl(QtGui.QWidget):
if newval==PC_RANDOM_QUEUE:
# must do some extra's if moving to queued-mode
if len(self.queuedSongs):
- settings.set('playcontrol.oldshuffle', settings.get('playcontrol.shuffle', 0))
+ self.p.setSetting('oldshuffle', self.p.getSetting('shuffle'))
else:
- self.cmbShuffle.setCurrentIndex(int(settings.get('playcontrol.shuffle', 0)))
+ self.cmbShuffle.setCurrentIndex(int(self.p.getSetting('shuffle')))
return
else:
# clear the queued songs when switching
self.queuedSongs=[]
self._onQueueUpdate()
- settings.set('playcontrol.shuffle', newval)
+ self.p.setSetting('shuffle', newval)
if newval==PC_RANDOM_SONG:
monty.random(1)
else:
@@ -321,13 +327,13 @@ class wgPlayControl(QtGui.QWidget):
def saveQueue(self):
# save the ids as a list of space-separated numbers
self.p.extended("saving queue")
- settings.set('playcontrol.queue', str(self.queuedSongs)[1:-1].replace(',', ''))
+ self.p.setSetting('queue', str(self.queuedSongs)[1:-1].replace(',', ''))
def loadQueue(self):
# just read all the numbers!
self.p.extended("loading queue")
self.queuedSongs=[]
i=0
- ids=settings.get('playcontrol.queue', '').split(' ')
+ ids=self.p.getSetting('queue').split(' ')
for id in ids:
try:
self.queuedSongs.append(int(id))
@@ -347,8 +353,7 @@ class pluginPlayControl(Plugin):
self.addMontyListener('onDisconnect', self.onDisconnect)
self.addMontyListener('onTimeChange', self.onTimeChange)
def _load(self):
- self.o=wgPlayControl(None)
- self.o.p=self
+ self.o=wgPlayControl(self, None)
self.o.loadQueue()
def _unload(self):
self.o.saveQueue()
diff --git a/plugins/Playlist.py b/plugins/Playlist.py
index f236360..4528d99 100644
--- a/plugins/Playlist.py
+++ b/plugins/Playlist.py
@@ -4,7 +4,6 @@ from clPlugin import *
from misc import *
from wgPlaylist import Playlist
from wgSongList import clrRowSel
-from clSettings import settings
# Dependencies:
# playcontrol
diff --git a/plugins/Scrobbler.py b/plugins/Scrobbler.py
index f634196..94bec01 100644
--- a/plugins/Scrobbler.py
+++ b/plugins/Scrobbler.py
@@ -3,6 +3,9 @@ import datetime
from clPlugin import *
+SCROBBLER_USERNAME_DEFAULT=''
+SCROBBLER_PASSWORD_DEFAULT=''
+
# TODO cached failed submissions
class pluginScrobbler(Plugin):
@@ -31,9 +34,9 @@ class pluginScrobbler(Plugin):
self.debug("no username provided, not logging in")
def _username(self):
- return settings.get('scrobbler.username', '')
+ return self.getSetting('username')
def _password(self):
- return settings.get('scrobbler.password', '')
+ return self.getSetting('password')
def onTimeChange(self, params):
if self.submitted==False and self.loggedIn:
song=monty.getCurrentSong()
diff --git a/plugins/SongStatus.py b/plugins/SongStatus.py
index 45a8dc8..8c9bc64 100644
--- a/plugins/SongStatus.py
+++ b/plugins/SongStatus.py
@@ -5,7 +5,7 @@ from traceback import print_exc
import format
-SS_DEFAULT_FORMAT='<font size="4">now $state</font>'\
+SONGSTATUS_FORMAT_DEFAULT='<font size="4">now $state</font>'\
'$if($title,<font size="8" color="blue">$title</font>'\
'<br />by <font size="8" color="green">$artist</font>'\
'<br /><font size="5" color="red">[$album # $track]</font>)'\
@@ -16,8 +16,10 @@ class wgSongStatus(QtGui.QWidget):
" label containing the info"
lblInfo=None
format=None
- def __init__(self, parent=None):
+ p=None
+ def __init__(self, p, parent=None):
QtGui.QWidget.__init__(self, parent)
+ self.p=p
self.lblInfo=QtGui.QLabel()
self.setMinimumWidth(400)
@@ -46,7 +48,7 @@ class wgSongStatus(QtGui.QWidget):
def updateFormat(self):
try:
- self.format=format.compile(settings.get('songstatus.format', SS_DEFAULT_FORMAT))
+ self.format=format.compile(self.p.getSetting('format'))
except Exception, e:
self.format=lambda p: "Invalid format: %s"%(e)
@@ -64,7 +66,7 @@ class pluginSongStatus(Plugin):
self.addMontyListener('onDisconnect', self.update)
def _load(self):
- self.o=wgSongStatus(None)
+ self.o=wgSongStatus(self, None)
self.update(None)
def _unload(self):
self.o=None
@@ -79,7 +81,7 @@ class pluginSongStatus(Plugin):
def _getSettings(self):
format=QtGui.QTextEdit()
- format.insertPlainText(settings.get('songstatus.format', SS_DEFAULT_FORMAT))
+ format.insertPlainText(self.getSetting('format'))
return [
['songstatus.format', 'Format', 'Format of the song status. Possible tags: $title, $artist, $album, $track, $time, $length, $state', format]
]
diff --git a/plugins/Tabs.py b/plugins/Tabs.py
index 8058c42..8ebf761 100644
--- a/plugins/Tabs.py
+++ b/plugins/Tabs.py
@@ -5,7 +5,6 @@ from thread import start_new_thread
from traceback import print_exc
from misc import *
-from clSettings import settings,mpdSettings
from clMonty import monty
from clPlugin import *
@@ -20,8 +19,9 @@ class AddHtmlEvent(QtCore.QEvent):
QtCore.QEvent.__init__(self,QtCore.QEvent.User)
self.html=html
-TABS_DEFAULT_ENGINE='http://www.google.com/search?q=tabs|chords+"$artist"+"$title"'
-TABS_DEFAULT_SITES='azchords.com <pre>(.*?)</pre>\n'\
+TABS_DIR_DEFAULT='/jammin'
+TABS_ENGINE_DEFAULT='http://www.google.com/search?q=tabs|chords+"$artist"+"$title"'
+TABS_SITES_DEFAULT='azchords.com <pre>(.*?)</pre>\n'\
'fretplay.com <P CLASS="tabs">(.*?)</P>\n'\
'guitaretab.com <pre style="COLOR: #000000; FONT-SIZE: 11px;">(.*)?</pre>'\
@@ -29,8 +29,9 @@ class wgTabs(QtGui.QWidget):
" contains the tabs"
txt=None
p=None # plugin
- def __init__(self, parent=None):
+ def __init__(self, p, parent=None):
QtGui.QWidget.__init__(self, parent)
+ self.p=p
self.txt=QtGui.QTextEdit(parent)
self.txt.setReadOnly(True)
@@ -70,7 +71,7 @@ class wgTabs(QtGui.QWidget):
QtCore.QCoreApplication.postEvent(self, ResetEvent(song))
# save the data to file!
- save_dir=settings.get('tabs.dir', '/holy_grail')
+ 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()))
@@ -90,13 +91,13 @@ class wgTabs(QtGui.QWidget):
# fetch from inet
QtCore.QCoreApplication.postEvent(self, AddHtmlEvent('<i>Searching tabs ...</i>'))
- lines=settings.get('tabs.sites', TABS_DEFAULT_SITES).split('\n')
+ 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=settings.get('tabs.engine', TABS_DEFAULT_ENGINE)
+ SE=self.p.getSetting('engine')
try:
ret=fetch(SE, sites, song, {})
if ret:
@@ -137,8 +138,7 @@ class pluginTabs(Plugin):
self.addMontyListener('onReady', self.refresh)
self.addMontyListener('onDisconnect', self.onDisconnect)
def _load(self):
- self.o=wgTabs(None)
- self.o.p=self
+ self.o=wgTabs(self, None)
self.refresh(None)
def _unload(self):
self.o=None
@@ -155,11 +155,11 @@ class pluginTabs(Plugin):
def _getSettings(self):
sites=QtGui.QTextEdit()
- sites.insertPlainText(settings.get('tabs.sites', TABS_DEFAULT_SITES))
+ sites.insertPlainText(self.getSetting('sites'))
return [
- ['tabs.engine', 'Search engine', 'The URL that is used to search. $artist, $title and $album are replaced in the URL.', QtGui.QLineEdit(settings.get('tabs.engine', TABS_DEFAULT_ENGINE))],
+ ['tabs.engine', 'Search engine', 'The URL that is used to search. $artist, $title and $album are replaced in the URL.', QtGui.QLineEdit(self.getSetting('engine'))],
['tabs.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 <tabs>(.*?)</tabs>', sites],
- ['tabs.dir', 'Tabs directory', 'Directory where tabs should be stored and retrieved.', QtGui.QLineEdit(settings.get('tabs.dir'))],
+ ['tabs.dir', 'Tabs directory', 'Directory where tabs should be stored and retrieved.', QtGui.QLineEdit(self.getSetting('dir'))],
]
def afterSaveSettings(self):
self.o.onSongChange(None)