From b9d88546dc97b2245644a87ecfef467256468e00 Mon Sep 17 00:00:00 2001 From: jerous Date: Sun, 2 Nov 2008 23:59:50 +0100 Subject: no more references to class itself in plugin-settings (no need to specify plugin in settings) --- clPlugin.py | 29 +++++++++++++++++++++++++++-- plugins/AlbumCover.py | 4 ++-- plugins/Library.py | 2 +- plugins/Logger.py | 3 --- plugins/Lyrics.py | 6 +++--- plugins/Notify.py | 4 ++-- plugins/Playlist.py | 2 +- plugins/Scrobbler.py | 4 ++-- plugins/SongStatus.py | 2 +- plugins/Tabs.py | 6 +++--- 10 files changed, 42 insertions(+), 20 deletions(-) diff --git a/clPlugin.py b/clPlugin.py index 100ec2b..d11614c 100644 --- a/clPlugin.py +++ b/clPlugin.py @@ -87,17 +87,28 @@ class Plugin: return self.dockWidget def getSettingsWidget(self): + """Get the widget containing all settings.""" + # is the widget constructed yet? if not self.settingsWidget: self.settings=self._getSettings() + # do we have any settings? if len(self.settings): + # create a widget self.settingsWidget=QtGui.QWidget(None) layout=QtGui.QGridLayout() self.settingsWidget.setLayout(layout) + # add for every setting a new entry for i in xrange(len(self.settings)): setting=self.settings[i] try: setting[4] except: + # if setting[0] doesn't contain a dot, it means it + # is for this one, else it might be a setting from + # another plugin. But this only applies when using + # the default settings-manager + if setting[0] and setting[0].count('.')==0: + setting[0]="%s.%s"%(self._getPluginClassname(self.__class__), setting[0]) setting.append(settings) tooltip="%s\n\n(%s)"%(setting[2],setting[0]) label=QtGui.QLabel(setting[1]) @@ -143,12 +154,17 @@ class Plugin: return setting[3] return None + def _getPluginClassname(self, cl): + """Returns the name of a plugin (without 'plugin'-prefix)""" + return str(cl).split('.')[-1].lower()[len('plugin'):] + + 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'):] + pluginClass=self._getPluginClassname(pluginClass) if default==None: # what module is this class in? @@ -164,7 +180,7 @@ class Plugin: if pluginClass==None: pluginClass=self.__class__ # fetch the name - pluginClass=str(self.__class__).split('.')[-1].lower()[len('plugin'):] + pluginClass=self._getPluginClassname(pluginClass) settings.set("%s.%s"%(str(pluginClass).lower(), setting), value) @@ -180,6 +196,15 @@ class Plugin: This method must return a list of arrays. Format: [ [setting, title, tooltip, widget, opt settingsmgr]+ ]""" + # setting[0] == setting. If setting contains a dot (.), setting is absolute, i.e. + # it belongs to a plugin. If it doesn't contain a dot, it belongs to the + # current class. E.g. 'lyrics.engine' and 'engine' are equal, if we are in + # the class pluginLyrics. Note that this only applies when setting[4] is + # not set. + # setting[1] == caption + # setting[2] == help message + # setting[3] == widget containing the value + # setting[4] == setting-class to use return [] def _createDock(self, widget): """Creates a QDockWidget with parent $parent containing widget $widget.""" diff --git a/plugins/AlbumCover.py b/plugins/AlbumCover.py index 50676d3..4e43cf3 100644 --- a/plugins/AlbumCover.py +++ b/plugins/AlbumCover.py @@ -206,8 +206,8 @@ class pluginAlbumCover(Plugin): 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(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'))]) + ret.append(['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(['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 302ede5..b1d86e9 100644 --- a/plugins/Library.py +++ b/plugins/Library.py @@ -68,7 +68,7 @@ class pluginLibrary(Plugin): modes=QtGui.QTextEdit() modes.insertPlainText(self.getSetting('modes')) return [ - ['library.modes', 'Modes', 'Sets the available modes.', modes], + ['modes', 'Modes', 'Sets the available modes.', modes], ] def afterSaveSettings(self): self.o.setModes(self.getSetting('modes').split('\n')) diff --git a/plugins/Logger.py b/plugins/Logger.py index d4eaba8..575fd5b 100644 --- a/plugins/Logger.py +++ b/plugins/Logger.py @@ -65,6 +65,3 @@ class pluginLogger(Plugin): def _getDockWidget(self): return self._createDock(self.o) - - def _getSettings(self): - return [] diff --git a/plugins/Lyrics.py b/plugins/Lyrics.py index c2f3c0a..97c7c8b 100644 --- a/plugins/Lyrics.py +++ b/plugins/Lyrics.py @@ -237,9 +237,9 @@ class pluginLyrics(Plugin): sites=QtGui.QTextEdit() 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(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 (.*?)', sites], - ['lyrics.dir', 'Lyrics directory', 'Directory where lyrics should be stored and retrieved.', QtGui.QLineEdit(self.getSetting('dir'))], + ['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 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 (.*?)', sites], + ['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/Notify.py b/plugins/Notify.py index 85c1a92..d039617 100644 --- a/plugins/Notify.py +++ b/plugins/Notify.py @@ -154,8 +154,8 @@ class pluginNotify(Plugin): txt=QtGui.QTextEdit() 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(self.getSetting('timer')))], + ['songformat', 'Song format', 'How to format the current playing song.', txt], + ['timer', 'Show seconds', 'How many seconds does the notification have to be shown.', QtGui.QLineEdit(str(self.getSetting('timer')))], ] def afterSaveSettings(self): try: diff --git a/plugins/Playlist.py b/plugins/Playlist.py index 76f5964..0e45ea6 100644 --- a/plugins/Playlist.py +++ b/plugins/Playlist.py @@ -84,7 +84,7 @@ class pluginPlaylist(Plugin): modes=QtGui.QTextEdit() modes.insertPlainText(self.getSetting('modes')) return [ - ['playlist.modes', 'Modes', 'Sets the available modes.', modes], + ['modes', 'Modes', 'Sets the available modes.', modes], ] def afterSaveSettings(self): self.o.setModes(self.getSetting('modes').split('\n')) diff --git a/plugins/Scrobbler.py b/plugins/Scrobbler.py index c29b6be..2b969d3 100644 --- a/plugins/Scrobbler.py +++ b/plugins/Scrobbler.py @@ -84,8 +84,8 @@ class pluginScrobbler(Plugin): self._login() def _getSettings(self): return [ - ['scrobbler.username', 'Username', 'Username to submit to last.fm.', QtGui.QLineEdit(self._username())], - ['scrobbler.password', 'Password', 'Password to user to submit. Note that the password is stored *unencrypted* to file.', QtGui.QLineEdit(self._password())], + ['username', 'Username', 'Username to submit to last.fm.', QtGui.QLineEdit(self._username())], + ['password', 'Password', 'Password to user to submit. Note that the password is stored *unencrypted* to file.', QtGui.QLineEdit(self._password())], ] def afterSaveSettings(self): self._login() diff --git a/plugins/SongStatus.py b/plugins/SongStatus.py index 8c9bc64..052e99b 100644 --- a/plugins/SongStatus.py +++ b/plugins/SongStatus.py @@ -83,7 +83,7 @@ class pluginSongStatus(Plugin): format=QtGui.QTextEdit() format.insertPlainText(self.getSetting('format')) return [ - ['songstatus.format', 'Format', 'Format of the song status. Possible tags: $title, $artist, $album, $track, $time, $length, $state', format] + ['format', 'Format', 'Format of the song status. Possible tags: $title, $artist, $album, $track, $time, $length, $state', format] ] def afterSaveSettings(self): self.o.updateFormat() diff --git a/plugins/Tabs.py b/plugins/Tabs.py index 8ebf761..5dc2aa2 100644 --- a/plugins/Tabs.py +++ b/plugins/Tabs.py @@ -157,9 +157,9 @@ class pluginTabs(Plugin): sites=QtGui.QTextEdit() 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(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 (.*?)', sites], - ['tabs.dir', 'Tabs directory', 'Directory where tabs should be stored and retrieved.', QtGui.QLineEdit(self.getSetting('dir'))], + ['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) -- cgit v1.2.3