From 71794c14051cb80431d81cdcc352a3198849163a Mon Sep 17 00:00:00 2001 From: Anton Khirnov Date: Sat, 7 Mar 2009 09:52:41 +0100 Subject: clPlugin: get rid of CamelCase. --- nephilim/plugins/AlbumCover.py | 60 +++++++++++++++++++--------------------- nephilim/plugins/Filebrowser.py | 13 ++++----- nephilim/plugins/Library.py | 42 ++++++++++++++-------------- nephilim/plugins/Lyrics.py | 17 +++++------- nephilim/plugins/Notify.py | 61 ++++++++++++++++++++--------------------- nephilim/plugins/PlayControl.py | 43 ++++++++++++++--------------- nephilim/plugins/Playlist.py | 32 ++++++++++----------- nephilim/plugins/Systray.py | 60 +++++++++++++++++++--------------------- nephilim/plugins/__init__.py | 14 ++++++---- 9 files changed, 162 insertions(+), 180 deletions(-) (limited to 'nephilim/plugins') diff --git a/nephilim/plugins/AlbumCover.py b/nephilim/plugins/AlbumCover.py index 5330189..fba252f 100644 --- a/nephilim/plugins/AlbumCover.py +++ b/nephilim/plugins/AlbumCover.py @@ -53,7 +53,7 @@ class wgAlbumCover(QtGui.QLabel): self.setPixmap(cover.scaled(self.size(), QtCore.Qt.KeepAspectRatio, QtCore.Qt.SmoothTransformation)) logging.info('Cover set.') - if (write and self.p.settings.value(self.p.getName() + '/store').toBool() + if (write and self.p.settings().value(self.p.name() + '/store').toBool() and self.cover_filepath): if cover.save(self.cover_filepath, 'png'): logging.info('Cover saved.') @@ -67,7 +67,7 @@ class wgAlbumCover(QtGui.QLabel): def refresh(self): logging.info("refreshing cover") - song = self.p.mpclient.current_song() + song = self.p.mpclient().current_song() if not song: self.clear() self.cover_loaded = False @@ -80,18 +80,18 @@ class wgAlbumCover(QtGui.QLabel): self.cover_dirname = '' self.cover_filepath = '' else: - dirname = self.p.settings.value(self.p.getName() + '/coverdir').toString() - self.cover_dirname = expand_tags(dirname, (self.p.winMain, song)) - filebase = self.p.settings.value(self.p.getName() + '/covername').toString() + dirname = self.p.settings().value(self.p.name() + '/coverdir').toString() + self.cover_dirname = expand_tags(dirname, (self.p.parent(), song)) + filebase = self.p.settings().value(self.p.name() + '/covername').toString() self.cover_filepath = '%s/%s'%(self.cover_dirname, - expand_tags(filebase, (self.p.winMain, song)).replace('/', '_')) + expand_tags(filebase, (self.p.parent(), song)).replace('/', '_')) self.fetch_cover(song) def fetch_cover(self, song): write = False if not QtCore.QFile.exists(self.cover_filepath): for i in (0, 1): - src = self.p.settings.value(self.p.getName() + '/method%i'%i).toInt()[0] + src = self.p.settings().value(self.p.name() + '/method%i'%i).toInt()[0] if src == AC_FETCH_LOCAL_DIR and self.cover_dirname: cover = self.fetch_local(song) elif src == AC_FETCH_AMAZON: @@ -108,7 +108,7 @@ class wgAlbumCover(QtGui.QLabel): self.set_cover(cover, write) def fetch_local_manual(self): - song = self.p.mpclient.current_song() + song = self.p.mpclient().current_song() if not song: return @@ -157,7 +157,7 @@ class wgAlbumCover(QtGui.QLabel): return None def fetch_amazon_manual(self): - song = self.p.mpclient.current_song() + song = self.p.mpclient().current_song() if not song: return cover = self.fetch_amazon(song) @@ -198,14 +198,10 @@ class wgAlbumCover(QtGui.QLabel): class AlbumCover(Plugin): o = None - DEFAULTS = {'coverdir' : '$musicdir/$songdir', 'covername' : '.cover_nephilim_$artist_$album', - 'method0' : 1, 'method1' : 1, 'store' : True} - def __init__(self, winMain): - Plugin.__init__(self, winMain, 'AlbumCover') - self.addListener('onSongChange' , self.refresh) - self.addListener('onReady' , self.refresh) - self.addListener('onDisconnect' , self.refresh) - self.addListener('onStateChange', self.refresh) + DEFAULTS = {'coverdir' : '$musicdir/$songdir', 'covername' : '.cover_nephilim_$artist_$album', + 'method0' : 1, 'method1' : 1, 'store' : True} + LISTENERS = {'onSongChange' : 'refresh', 'onReady' : 'refresh', 'onDisconnect' : 'refresh', + 'onStateChange': 'refresh'} def _load(self): self.o = wgAlbumCover(self) @@ -220,8 +216,8 @@ class AlbumCover(Plugin): def get_cover(self): return self.o.get_cover() - def _getDockWidget(self): - return self._createDock(self.o) + def _get_dock_widget(self): + return self._create_dock(self.o) class SettingsWidgetAlbumCover(Plugin.SettingsWidget): methods = [] @@ -231,7 +227,7 @@ class AlbumCover(Plugin): def __init__(self, plugin): Plugin.SettingsWidget.__init__(self, plugin) - self.settings.beginGroup(self.plugin.getName()) + self.settings().beginGroup(self.plugin.name()) # fetching methods comboboxes self.methods = [QtGui.QComboBox(), QtGui.QComboBox()] @@ -239,23 +235,23 @@ class AlbumCover(Plugin): method.addItem('No method.') method.addItem('Local dir') method.addItem('Amazon') - method.setCurrentIndex(self.settings.value('method' + str(i)).toInt()[0]) + method.setCurrentIndex(self.settings().value('method' + str(i)).toInt()[0]) # store covers groupbox self.store = QtGui.QGroupBox('Store covers.') self.store.setToolTip('Should %s store its own copy of covers?'%APPNAME) self.store.setCheckable(True) - self.store.setChecked(self.settings.value('store').toBool()) + self.store.setChecked(self.settings().value('store').toBool()) self.store.setLayout(QtGui.QGridLayout()) # paths to covers - self.coverdir = QtGui.QLineEdit(self.settings.value('coverdir').toString()) + self.coverdir = QtGui.QLineEdit(self.settings().value('coverdir').toString()) self.coverdir.setToolTip('Where should %s store covers.\n' '$musicdir will be expanded to path to MPD music library (as set by user)\n' '$songdir will be expanded to path to the song (relative to $musicdir\n' 'other tags same as in covername' %APPNAME) - self.covername = QtGui.QLineEdit(self.settings.value('covername').toString()) + self.covername = QtGui.QLineEdit(self.settings().value('covername').toString()) self.covername.setToolTip('Filename for %s cover files.\n' 'All tags supported by MPD will be expanded to their\n' 'values for current song, e.g. $title, $track, $artist,\n' @@ -270,16 +266,16 @@ class AlbumCover(Plugin): self._add_widget(self.methods[1], 'Method 1', 'Method to try if the first one fails.') self.layout().addWidget(self.store) - self.settings.endGroup() + self.settings().endGroup() def save_settings(self): - self.settings.beginGroup(self.plugin.getName()) - self.settings.setValue('method0', QVariant(self.methods[0].currentIndex())) - self.settings.setValue('method1', QVariant(self.methods[1].currentIndex())) - self.settings.setValue('coverdir', QVariant(self.coverdir.text())) - self.settings.setValue('covername', QVariant(self.covername.text())) - self.settings.setValue('store', QVariant(self.store.isChecked())) - self.settings.endGroup() + self.settings().beginGroup(self.plugin.name()) + self.settings().setValue('method0', QVariant(self.methods[0].currentIndex())) + self.settings().setValue('method1', QVariant(self.methods[1].currentIndex())) + self.settings().setValue('coverdir', QVariant(self.coverdir.text())) + self.settings().setValue('covername', QVariant(self.covername.text())) + self.settings().setValue('store', QVariant(self.store.isChecked())) + self.settings().endGroup() self.plugin.o.refresh() def get_settings_widget(self): diff --git a/nephilim/plugins/Filebrowser.py b/nephilim/plugins/Filebrowser.py index 5faa678..71969eb 100644 --- a/nephilim/plugins/Filebrowser.py +++ b/nephilim/plugins/Filebrowser.py @@ -7,9 +7,6 @@ from ..misc import ORGNAME, APPNAME class Filebrowser(Plugin): o = None - def __init__(self, winMain): - Plugin.__init__(self, winMain, 'Filebrowser') - def _load(self): self.o = wgFilebrowser(self) @@ -19,8 +16,8 @@ class Filebrowser(Plugin): def getInfo(self): return 'A file browser that allows adding files not in collection.' - def _getDockWidget(self): - return self._createDock(self.o) + def _get_dock_widget(self): + return self._create_dock(self.o) class wgFilebrowser(QtGui.QWidget): view = None @@ -56,13 +53,13 @@ class wgFilebrowser(QtGui.QWidget): self.view.setRootIndex(index) self.path.setText(self.model.filePath(index)) else: - if not 'file://' in self.plugin.mpclient.urlhandlers(): - self.setStatus('file:// handler not available. Connect via unix domain sockets.') + if not 'file://' in self.plugin.mpclient()().urlhandlers(): + self.set_status('file:// handler not available. Connect via unix domain sockets.') return paths = [] for index in self.view.selectedIndexes(): paths.append(u'file://' + unicode(self.model.filePath(index))) - self.plugin.mpclient.add(paths) + self.plugin.mpclient()().add(paths) def path_changed(self): if os.path.isdir(self.path.text()): diff --git a/nephilim/plugins/Library.py b/nephilim/plugins/Library.py index ebc49ab..85ad556 100644 --- a/nephilim/plugins/Library.py +++ b/nephilim/plugins/Library.py @@ -6,29 +6,30 @@ from ..misc import ORGNAME, APPNAME class Library(Plugin): o=None - DEFAULTS = {'modes' : 'artist\n'\ - 'artist/album\n'\ - 'artist/date/album\n'\ - 'genre\n'\ - 'genre/artist\n'\ - 'genre/artist/album\n'} - - def __init__(self, winMain): - Plugin.__init__(self, winMain, 'Library') - self.settings = QtCore.QSettings(ORGNAME, APPNAME) + DEFAULTS = {'modes' : 'artist\n'\ + 'artist/album\n'\ + 'artist/date/album\n'\ + 'genre\n'\ + 'genre/artist\n'\ + 'genre/artist/album\n'} + LISTENERS = {'onReady' : 'fill_library', 'onDisconnect' : 'fill_library', + 'onUpdateDBFinish' : 'fill_library'} + def _load(self): self.o = LibraryWidget(self) - self.mpclient.add_listener('onReady', self.o.fill_library) - self.mpclient.add_listener('onDisconnect', self.o.fill_library) - self.mpclient.add_listener('onUpdateDBFinish', self.o.fill_library) def _unload(self): self.o = None def getInfo(self): return "List showing all the songs allowing filtering and grouping." - def _getDockWidget(self): - return self._createDock(self.o) + def _get_dock_widget(self): + return self._create_dock(self.o) + + def fill_library(self, params): + if not self.o: + return + self.o.fill_library() class SettingsWidgetLibrary(Plugin.SettingsWidget): modes = None @@ -37,16 +38,17 @@ class Library(Plugin): self.setLayout(QtGui.QVBoxLayout()) self.modes = QtGui.QTextEdit() - self.modes.insertPlainText(self.settings.value(self.plugin.getName() + '/modes').toString()) + self.modes.insertPlainText(self.settings().value(self.plugin.name() + '/modes').toString()) self.layout().addWidget(self.modes) def save_settings(self): - self.settings.setValue(self.plugin.getName() + '/modes', QVariant(self.modes.toPlainText())) + self.settings().setValue(self.plugin.name() + '/modes', QVariant(self.modes.toPlainText())) self.plugin.o.refresh_modes() def get_settings_widget(self): return self.SettingsWidgetLibrary(self) + class LibraryWidget(QtGui.QWidget): library = None search_txt = None @@ -58,7 +60,7 @@ class LibraryWidget(QtGui.QWidget): QtGui.QWidget.__init__(self) self.plugin = plugin self.settings = QtCore.QSettings(ORGNAME, APPNAME) - self.settings.beginGroup(self.plugin.getName()) + self.settings.beginGroup(self.plugin.name()) self.modes = QtGui.QComboBox() self.refresh_modes() @@ -97,7 +99,7 @@ class LibraryWidget(QtGui.QWidget): #build a tree from library tree = [{},self.library.invisibleRootItem()] - for song in self.plugin.mpclient.library(): + for song in self.plugin.mpclient().library(): cur_item = tree for part in str(self.modes.currentText()).split('/'): tag = song.getTag(part) @@ -141,7 +143,7 @@ class LibraryWidget(QtGui.QWidget): paths = [] for item in self.library.selectedItems(): self.item_to_playlist(item, paths) - self.plugin.mpclient.add(paths) + self.plugin.mpclient().add(paths) def item_to_playlist(self, item, add_queue): if item.type() == 1000: diff --git a/nephilim/plugins/Lyrics.py b/nephilim/plugins/Lyrics.py index c0b0fe3..2bfbb11 100644 --- a/nephilim/plugins/Lyrics.py +++ b/nephilim/plugins/Lyrics.py @@ -39,13 +39,10 @@ class wgLyrics(QtGui.QWidget): class Lyrics(Plugin): o = None - DEFAULTS = {'sites' : ['lyricwiki'], 'lyricdir' : '$musicdir/$songdir', - 'lyricname' : '.lyric_mpclient_$artist_$album_$song'} + DEFAULTS = {'sites' : ['lyricwiki'], 'lyricdir' : '$musicdir/$songdir', + 'lyricname' : '.lyric_mpclient_$artist_$album_$song'} + LISTENERS = {'onSongChange' : 'refresh', 'onReady' : 'refresh'} - def __init__(self, winMain): - Plugin.__init__(self, winMain, 'Lyrics') - self.addListener('onSongChange', self.refresh) - self.addListener('onReady', self.refresh) def _load(self): self.o = wgLyrics(self) def _unload(self): @@ -53,16 +50,16 @@ class Lyrics(Plugin): def getInfo(self): return "Show (and fetch) the lyrics of the currently playing song." - def _getDockWidget(self): - return self._createDock(self.o) + def _get_dock_widget(self): + return self._create_dock(self.o) def refresh(self, params = None): lyrics = None - song = self.mpclient.current_song() + song = self.mpclient().current_song() if not song: self.o.set_lyrics(None, None) return - for site in self.settings.value(self.getName() + '/sites').toStringList(): + for site in self.settings().value(self.name() + '/sites').toStringList(): lyrics = eval('self.fetch_%s(song)'%site) if lyrics: self.o.set_lyrics(song, lyrics) diff --git a/nephilim/plugins/Notify.py b/nephilim/plugins/Notify.py index f086693..4e1486c 100644 --- a/nephilim/plugins/Notify.py +++ b/nephilim/plugins/Notify.py @@ -11,7 +11,7 @@ NOTIFY_PRIORITY_VOLUME = 2 class winNotify(QtGui.QWidget): _timerID = None - winMain = None + parent = None p = None _current_priority = 0 @@ -20,10 +20,10 @@ class winNotify(QtGui.QWidget): cover_label = None text_label = None - def __init__(self, p, winMain, parent=None): - QtGui.QWidget.__init__(self, parent) - self.p = p - self.winMain = winMain + def __init__(self, p): + QtGui.QWidget.__init__(self, p.parent()) + self.p = p + self.parent = p.parent() self.timer = QtCore.QTimer(self) self.timer.setSingleShot(True) @@ -54,7 +54,7 @@ class winNotify(QtGui.QWidget): self._current_priority = priority self.cover_label.clear() - ac = self.winMain.plugins.plugin('AlbumCover') + ac = self.parent.plugins.plugin('AlbumCover') if ac: cover = ac.get_cover() if cover: @@ -80,43 +80,39 @@ class winNotify(QtGui.QWidget): class Notify(Plugin): o=None - DEFAULTS = {'songformat' : '$track - $artist - $title ($album) [$length]', - 'timer' : 3000} - def __init__(self, winMain): - Plugin.__init__(self, winMain, 'Notify') - self.addListener('onSongChange', self.onSongChange) - self.addListener('onReady', self.onReady) - self.addListener('onDisconnect', self.onDisconnect) - self.addListener('onStateChange', self.onStateChange) - self.addListener('onVolumeChange', self.onVolumeChange) + DEFAULTS = {'songformat' : '$track - $artist - $title ($album) [$length]', + 'timer' : 3000} + LISTENERS = {'onSongChange': 'onSongChange', 'onReady' : 'onReady', + 'onDisconnect': 'onDisconnect', 'onStateChange' : 'onStateChange', + 'onVolumeChange' : 'onVolumeChange'} def _load(self): - self.o = winNotify(self, self.winMain) + self.o = winNotify(self) def _unload(self): self.o=None def getInfo(self): return "Show interesting events in a popup window." def onSongChange(self, params): - song = self.mpclient.current_song() + song = self.mpclient().current_song() if not song: return - self.settings.beginGroup(self.name) - self.o.show(expand_tags(self.settings.value('songformat').toString(), (song,)), self.settings.value('timer').toInt()[0], + self.settings().beginGroup(self.name()) + self.o.show(expand_tags(self.settings().value('songformat').toString(), (song,)), self.settings().value('timer').toInt()[0], NOTIFY_PRIORITY_SONG) - self.settings.endGroup() + self.settings().endGroup() def onReady(self, params): - self.o.show('%s loaded'%APPNAME, self.settings.value(self.name + '/timer').toInt()[0]) + self.o.show('%s loaded'%APPNAME, self.settings().value(self.name() + '/timer').toInt()[0]) def onDisconnect(self, params): - self.o.show('Disconnected!', self.settings.value(self.name + '/timer').toInt()[0]) + self.o.show('Disconnected!', self.settings().value(self.name() + '/timer').toInt()[0]) def onStateChange(self, params): - self.o.show(params['newState'], self.settings.value(self.name + '/timer').toInt()[0]) + self.o.show(params['newState'], self.settings().value(self.name() + '/timer').toInt()[0]) def onVolumeChange(self, params): - self.o.show('Volume: %i%%'%(params['newVolume']), self.settings.value(self.name + '/timer').toInt()[0], priority = NOTIFY_PRIORITY_VOLUME) + self.o.show('Volume: %i%%'%(params['newVolume']), self.settings().value(self.name() + '/timer').toInt()[0], priority = NOTIFY_PRIORITY_VOLUME) class SettingsWidgetNotify(Plugin.SettingsWidget): format = None @@ -124,11 +120,11 @@ class Notify(Plugin): def __init__(self, plugin): Plugin.SettingsWidget.__init__(self, plugin) - self.settings.beginGroup(self.plugin.getName()) + self.settings().beginGroup(self.plugin.name()) - self.format = QtGui.QLineEdit(self.settings.value('songformat').toString()) + self.format = QtGui.QLineEdit(self.settings().value('songformat').toString()) - self.timer = QtGui.QLineEdit(self.settings.value('timer').toString()) + self.timer = QtGui.QLineEdit(self.settings().value('timer').toString()) self.timer.setValidator(QtGui.QIntValidator(self.timer)) self.setLayout(QtGui.QVBoxLayout()) @@ -136,14 +132,15 @@ class Notify(Plugin): 'will be expanded to their values for current song,\n' 'e.g. $track, $title, $artist, $album, $length, $date, etc.') self._add_widget(self.timer, 'Duration', 'How long should notifications be displayed in ms.') - self.settings.endGroup() + self.settings().endGroup() def save_settings(self): - self.settings.beginGroup(self.plugin.getName()) - self.settings.setValue('songformat', QVariant(self.format.text())) - self.settings.setValue('timer', QVariant(self.timer.text().toInt()[0])) - self.settings.endGroup() + self.settings().beginGroup(self.plugin.name()) + self.settings().setValue('songformat', QVariant(self.format.text())) + self.settings().setValue('timer', QVariant(self.timer.text().toInt()[0])) + self.settings().endGroup() self.plugin.onSongChange(None) def get_settings_widget(self): return self.SettingsWidgetNotify(self) + diff --git a/nephilim/plugins/PlayControl.py b/nephilim/plugins/PlayControl.py index 3ff7170..d6eebb5 100644 --- a/nephilim/plugins/PlayControl.py +++ b/nephilim/plugins/PlayControl.py @@ -44,7 +44,7 @@ class wgPlayControl(QtGui.QToolBar): painter.fillRect(rect, QtGui.QBrush(grad)) def __init__(self, p, parent = None): - QtGui.QToolBar.__init__(self, p.getName(), parent) + QtGui.QToolBar.__init__(self, p.name(), parent) self.setMovable(True) self.p = p @@ -59,12 +59,12 @@ class wgPlayControl(QtGui.QToolBar): self.random = QtGui.QPushButton(QtGui.QIcon('gfx/random.png'), '', self) self.random.setToolTip('Random') self.random.setCheckable(True) - self.connect(self.random, QtCore.SIGNAL('toggled(bool)'), self.p.mpclient.random) + self.connect(self.random, QtCore.SIGNAL('toggled(bool)'), self.p.mpclient().random) self.repeat = QtGui.QPushButton(QtGui.QIcon('gfx/repeat.png'), '', self) self.repeat.setToolTip('Repeat') self.repeat.setCheckable(True) - self.connect(self.repeat, QtCore.SIGNAL('toggled(bool)'), self.p.mpclient.repeat) + self.connect(self.repeat, QtCore.SIGNAL('toggled(bool)'), self.p.mpclient().repeat) self.addWidget(self.btnPlayPause) self.addWidget(self.btnStop) @@ -85,7 +85,7 @@ class wgPlayControl(QtGui.QToolBar): self.queuedSongs.extend(songs) def onStateChange(self, params): - status = self.p.mpclient.status() + status = self.p.mpclient().status() if status['state'] == 'play': self.btnPlayPause.changeIcon('gfx/media-playback-pause.svg') @@ -98,27 +98,27 @@ class wgPlayControl(QtGui.QToolBar): self.slrVolume.setValue(params['newVolume']) def onBtnPlayPauseClick(self): - status=self.p.mpclient.status() + status=self.p.mpclient().status() if status['state']=='play': - self.p.mpclient.pause() + self.p.mpclient().pause() logging.info("Toggling playback") elif status['state']=='stop': - self.p.mpclient.play(None) + self.p.mpclient().play(None) logging.info("Pausing playback") else: - self.p.mpclient.resume() + self.p.mpclient().resume() def onBtnStopClick(self): - self.p.mpclient.stop() + self.p.mpclient().stop() logging.info("Stopping playback") def onBtnPreviousClick(self): - self.p.mpclient.previous() + self.p.mpclient().previous() logging.info("Playing previous") def onBtnNextClick(self): - self.p.mpclient.next() + self.p.mpclient().next() logging.info("Playing next") def onVolumeSliderChange(self): v=self.slrVolume.value() - self.p.mpclient.set_volume(v) + self.p.mpclient().set_volume(v) if v<=1: mode='mute' else: @@ -128,13 +128,13 @@ class wgPlayControl(QtGui.QToolBar): def saveQueue(self): # save the ids as a list of space-separated numbers logging.info("saving queue") - self.p.settings.setValue(self.p.getName() + '/queue', QVariant(str(self.queuedSongs)[1:-1].replace(',', ''))) + self.p.settings().setValue(self.p.name() + '/queue', QVariant(str(self.queuedSongs)[1:-1].replace(',', ''))) def loadQueue(self): # just read all the numbers! logging.info("loading queue") self.queuedSongs=[] i=0 - ids=self.p.settings.value(self.p.getName() + '/queue').toString().split(' ') + ids=self.p.settings().value(self.p.name() + '/queue').toString().split(' ') for id in ids: try: self.queuedSongs.append(int(id)) @@ -143,19 +143,17 @@ class wgPlayControl(QtGui.QToolBar): class PlayControl(Plugin): o=None - DEFAULTS = {'queue' : ''} - def __init__(self, winMain): - Plugin.__init__(self, winMain, 'PlayControl') - self.addListener('onStateChange', self.onStateChange) - self.addListener('onVolumeChange', self.onVolumeChange) - self.addListener('onReady', self.onStateChange) + DEFAULTS = {'queue' : ''} + LISTENERS = {'onStateChange' : 'onStateChange', 'onVolumeChange' : 'onVolumeChange', + 'onReady' : 'onStateChange'} + def _load(self): self.o = wgPlayControl(self, None) self.o.loadQueue() - self.winMain.addToolBar(QtCore.Qt.TopToolBarArea, self.o) + self.parent().addToolBar(QtCore.Qt.TopToolBarArea, self.o) def _unload(self): self.o.saveQueue() - self.winMain.removeToolBar(self.o) + self.parent().removeToolBar(self.o) self.o = None def getInfo(self): return "Have total control over the playing!" @@ -167,3 +165,4 @@ class PlayControl(Plugin): self.o.onStateChange(params) def onVolumeChange(self, params): self.o.onVolumeChange(params) + diff --git a/nephilim/plugins/Playlist.py b/nephilim/plugins/Playlist.py index e57c9ac..d8c4347 100644 --- a/nephilim/plugins/Playlist.py +++ b/nephilim/plugins/Playlist.py @@ -3,32 +3,28 @@ from PyQt4.QtCore import QVariant from ..clPlugin import Plugin -# Dependencies: -# playcontrol class Playlist(Plugin): o = None - DEFAULTS = {'columns': ['track', 'title', 'artist', - 'date', 'album', 'length']} + DEFAULTS = {'columns': ['track', 'title', 'artist', + 'date', 'album', 'length']} + LISTENERS = {'onPlaylistChange' : 'on_playlist_change', + 'onDisconnect' : 'on_playlist_change', 'onReady' : 'on_playlist_change'} - def __init__(self, winMain): - Plugin.__init__(self, winMain, 'Playlist') def _load(self): self.o = PlaylistWidget(self) - self.mpclient.add_listener('onPlaylistChange', self.on_playlist_change) - self.mpclient.add_listener('onDisconnect', self.on_playlist_change) - self.mpclient.add_listener('onReady', self.on_playlist_change) def _unload(self): self.o = None def getInfo(self): return "The playlist showing the songs that will be played." - def _getDockWidget(self): - return self._createDock(self.o) + def _get_dock_widget(self): + return self._create_dock(self.o) def on_playlist_change(self, params = None): self.o.fill_playlist() + class PlaylistWidget(QtGui.QWidget): plugin = None playlist = None @@ -55,23 +51,23 @@ class PlaylistWidget(QtGui.QWidget): self.setSelectionMode(QtGui.QTreeWidget.ExtendedSelection) self.setAlternatingRowColors(True) self.setRootIsDecorated(False) - columns = self.plugin.settings.value(self.plugin.getName() + '/columns').toStringList() + columns = self.plugin.settings().value(self.plugin.name() + '/columns').toStringList() self.setColumnCount(len(columns)) self.setHeaderLabels(columns) - self.header().restoreState(self.plugin.settings.value(self.plugin.getName() + '/header_state').toByteArray()) + self.header().restoreState(self.plugin.settings().value(self.plugin.name() + '/header_state').toByteArray()) self.connect(self, QtCore.SIGNAL('itemActivated(QTreeWidgetItem*, int)'), self._song_activated) self.connect(self.header(), QtCore.SIGNAL('geometriesChanged()'), self._save_state) def _save_state(self): - self.plugin.settings.setValue(self.plugin.getName() + '/header_state', QVariant(self.header().saveState())) + self.plugin.settings().setValue(self.plugin.name() + '/header_state', QVariant(self.header().saveState())) def _song_activated(self, item): - self.plugin.mpclient.play(item.data(0, QtCore.Qt.UserRole).toPyObject().getID()) + self.plugin.mpclient().play(item.data(0, QtCore.Qt.UserRole).toPyObject().getID()) def fill(self): - columns = self.plugin.settings.value(self.plugin.getName() + '/columns').toStringList() + columns = self.plugin.settings().value(self.plugin.name() + '/columns').toStringList() self.clear() - for song in self.plugin.mpclient.playlist(): + for song in self.plugin.mpclient().playlist(): item = QtGui.QTreeWidgetItem() for i in range(len(columns)): item.setText(i, unicode(song.getTag(str(columns[i])))) @@ -84,7 +80,7 @@ class PlaylistWidget(QtGui.QWidget): for item in self.selectedItems(): ids.append(item.data(0, QtCore.Qt.UserRole).toPyObject().getID()) - self.plugin.mpclient.delete(ids) + self.plugin.mpclient().delete(ids) else: QtGui.QTreeWidget.keyPressEvent(self, event) diff --git a/nephilim/plugins/Systray.py b/nephilim/plugins/Systray.py index 4a3c45d..6451090 100644 --- a/nephilim/plugins/Systray.py +++ b/nephilim/plugins/Systray.py @@ -5,40 +5,35 @@ from ..clPlugin import Plugin from ..misc import sec2min, ORGNAME, APPNAME, appIcon, expand_tags class Systray(Plugin): - DEFAULTS = {'format': '$track - $title by $artist on $album ($length)'} - o = None - format = None - eventObj = None - time = None # indicator of current time [0..64] - appIcon = None - pixmap = None - def __init__(self, winMain): - Plugin.__init__(self, winMain, 'Systray') - self.addListener('onSongChange', self.update) - self.addListener('onReady', self.update) - self.addListener('onConnect', self.update) - self.addListener('onDisconnect', self.update) - self.addListener('onTimeChange', self.update) # TODO only update this when necessary, i.e. mouse-hover etc - self.appIcon = QtGui.QIcon(appIcon) + o = None + format = None + eventObj = None + time = None # indicator of current time [0..64] + appIcon = None + pixmap = None + DEFAULTS = {'format': '$track - $title by $artist on $album ($length)'} + LISTENERS = {'onSongChange' : 'update', 'onReady' : 'update', 'onConnect' : 'update', + 'onDisconnect' : 'update', 'onTimeChange' : 'update'} def _load(self): - self.format = self.settings.value(self.name + '/format').toString() + self.appIcon = QtGui.QIcon(appIcon) + self.format = self.settings().value(self.name() + '/format').toString() class SystrayWheelEventObject(QtCore.QObject): """This class listens for systray-wheel events""" def eventFilter(self, object, event): if type(event)==QtGui.QWheelEvent: numDegrees=event.delta() / 8 numSteps=5*numDegrees/15 - self.plugin.mpclient.set_volume(self.plugin.mpclient.volume() + numSteps) + self.plugin.mpclient()().set_volume(self.plugin.mpclient()().volume() + numSteps) event.accept() return True return False - self.o=QtGui.QSystemTrayIcon(QtGui.QIcon(appIcon), self.winMain) + self.o = QtGui.QSystemTrayIcon(QtGui.QIcon(appIcon), self.parent()) self.eventObj=SystrayWheelEventObject() self.eventObj.plugin = self self.o.installEventFilter(self.eventObj) - self.winMain.connect(self.o, QtCore.SIGNAL('activated (QSystemTrayIcon::ActivationReason)') + self.parent().connect(self.o, QtCore.SIGNAL('activated (QSystemTrayIcon::ActivationReason)') , self.onSysTrayClick) self.o.show() @@ -46,12 +41,12 @@ class Systray(Plugin): self.o.hide() self.o.setIcon(QtGui.QIcon(None)) self.o=None - self.winMain._wheelEvent=None + self.parent()._wheelEvent=None def getInfo(self): return "Display the mpclientpc icon in the systray." def update(self, params): - status = self.mpclient.status() + status = self.mpclient().status() if not status: return @@ -61,7 +56,7 @@ class Systray(Plugin): values['length'] = sec2min(status['length']) values['time'] = sec2min(status['time']) - song = self.mpclient.current_song() + song = self.mpclient().current_song() if song: self.o.setToolTip(expand_tags(self.format, (song,))) else: @@ -76,27 +71,27 @@ class Systray(Plugin): # redraw the systray icon self.pixmap = self.appIcon.pixmap(64,64) painter = QtGui.QPainter(self.pixmap) - painter.fillRect(1, curTime, 63, 64, self.winMain.palette().brush(QtGui.QPalette.Base)) + painter.fillRect(1, curTime, 63, 64, self.parent().palette().brush(QtGui.QPalette.Base)) self.appIcon.paint(painter, 1, 0, 63, 64) self.o.setIcon(QtGui.QIcon(self.pixmap)) elif not song: - self.time=None + self.time = None self.o.setIcon(QtGui.QIcon(appIcon)) def onSysTrayClick(self, reason): if reason == QtGui.QSystemTrayIcon.Trigger or\ reason == QtGui.QSystemTrayIcon.Context: - w = self.getWinMain() + w = self.parent() # left mouse button if w.isVisible(): w.setVisible(False) else: w.setVisible(True) elif reason == QtGui.QSystemTrayIcon.MiddleClick: - if self.mpclient.is_playing(): - self.mpclient.pause() + if self.mpclient().is_playing(): + self.mpclient().pause() else: - self.mpclient.resume() + self.mpclient().resume() class SettingsWidgetSystray(Plugin.SettingsWidget): format = None @@ -104,15 +99,16 @@ class Systray(Plugin): def __init__(self, plugin): Plugin.SettingsWidget.__init__(self, plugin) - self.format = QtGui.QLineEdit(self.settings.value(self.plugin.getName() + '/format').toString()) + self.format = QtGui.QLineEdit(self.settings().value(self.plugin.name() + '/format').toString()) self.setLayout(QtGui.QVBoxLayout()) self._add_widget(self.format, 'Tooltip format') def save_settings(self): - self.settings.beginGroup(self.plugin.getName()) - self.settings.setValue('format', QVariant(self.format.text())) - self.settings.endGroup() + self.settings().beginGroup(self.plugin.name()) + self.settings().setValue('format', QVariant(self.format.text())) + self.settings().endGroup() def get_settings_widget(self): return self.SettingsWidgetSystray(self) + diff --git a/nephilim/plugins/__init__.py b/nephilim/plugins/__init__.py index e52334f..84aa2e5 100644 --- a/nephilim/plugins/__init__.py +++ b/nephilim/plugins/__init__.py @@ -5,13 +5,15 @@ __all__ = ['AlbumCover', 'Filebrowser', 'Library', 'Lyrics', 'Notify', 'PlayCont 'Playlist', 'Systray'] class Plugins: - _plugins = None - parent = None + _plugins = None + parent = None + mpclient = None - def __init__(self, parent): + def __init__(self, parent, mpclient): """load all modules in the plugins directory.""" self._plugins = {} self.parent = parent + self.mpclient = mpclient for name in __all__: self.init_plugin(name) @@ -39,7 +41,7 @@ class Plugins: logging.error('Failed to initialize plugin %s: %s.'%(name, e)) return False - self._plugins[name] = eval('module.%s(self.parent)'%name) + self._plugins[name] = eval('module.%s(self.parent, self.mpclient, \'%s\')'%(name, name)) return True def load(self, name): @@ -52,7 +54,7 @@ class Plugins: def unload(self, name): if name in self._plugins: - if self._plugins[name].isLoaded(): + if self._plugins[name].is_loaded(): self._plugins[name].unload() def plugins(self): @@ -61,6 +63,6 @@ class Plugins: def loaded_plugins(self): list = [] for plugin in self._plugins.values(): - if plugin.isLoaded(): + if plugin.is_loaded(): list.append(plugin) return list -- cgit v1.2.3