summaryrefslogtreecommitdiff
path: root/nephilim
diff options
context:
space:
mode:
authorAnton Khirnov <wyskas@gmail.com>2009-06-20 17:10:53 +0200
committerAnton Khirnov <wyskas@gmail.com>2009-06-20 17:10:53 +0200
commitc6af9fe01cb3bea21471f839ec26a07b04ac24c2 (patch)
tree704e0d0542e8bf5a22a3d8632c9885cd989c1d5b /nephilim
parente7e7093a12fb5eb52fd0bb3071a7c85c7d8aefbd (diff)
plugin: make mpclient a var instead of a function.
Diffstat (limited to 'nephilim')
-rw-r--r--nephilim/plugin.py12
-rw-r--r--nephilim/plugins/AlbumCover.py12
-rw-r--r--nephilim/plugins/Filebrowser.py6
-rw-r--r--nephilim/plugins/Library.py10
-rw-r--r--nephilim/plugins/Lyrics.py8
-rw-r--r--nephilim/plugins/Notify.py22
-rw-r--r--nephilim/plugins/PlayControl.py38
-rw-r--r--nephilim/plugins/Playlist.py10
-rw-r--r--nephilim/plugins/Songinfo.py4
-rw-r--r--nephilim/plugins/Systray.py20
10 files changed, 70 insertions, 72 deletions
diff --git a/nephilim/plugin.py b/nephilim/plugin.py
index b443167..d4a248e 100644
--- a/nephilim/plugin.py
+++ b/nephilim/plugin.py
@@ -25,13 +25,13 @@ import plugins
class Plugin(QtCore.QObject):
# public, const
name = None
- logger = None
+ logger = None
+ mpclient = None
_dock_widget = None
_settings = None
_loaded = None
_parent = None
- _mpclient = None
o = None
DEFAULTS = {}
@@ -39,8 +39,8 @@ class Plugin(QtCore.QObject):
def __init__(self, parent, mpclient, name):
QtCore.QObject.__init__(self)
self.name = name
+ self.mpclient = mpclient
self._parent = parent
- self._mpclient = mpclient
self._loaded = False
self._settings = QtCore.QSettings()
@@ -60,8 +60,6 @@ class Plugin(QtCore.QObject):
return self._parent
def set_status(self, status):
self._parent.setStatus(status)
- def mpclient(self):
- return self._mpclient
def settings(self):
return self._settings
@@ -71,7 +69,7 @@ class Plugin(QtCore.QObject):
opts = QtGui.QDockWidget.DockWidgetClosable|QtGui.QDockWidget.DockWidgetMovable
QtGui.QApplication.instance().main_win.addDock(self.get_dock_widget(opts))
QtGui.QApplication.instance().main_win.restore_layout()
- self.connect(self._mpclient, QtCore.SIGNAL('connect_changed'), self.set_enabled)
+ self.connect(self.mpclient, QtCore.SIGNAL('connect_changed'), self.set_enabled)
self._loaded = True
def unload(self):
if not self._loaded:
@@ -83,7 +81,7 @@ class Plugin(QtCore.QObject):
QtGui.QApplication.instance().main_win.removeDock(dock_widget)
self._dock_widget = None
self._settingsWidget = None
- self.disconnect(self._mpclient, QtCore.SIGNAL('connect_changed'), self.set_enabled)
+ self.disconnect(self.mpclient, QtCore.SIGNAL('connect_changed'), self.set_enabled)
self._loaded = False
def is_loaded(self):
return self._loaded
diff --git a/nephilim/plugins/AlbumCover.py b/nephilim/plugins/AlbumCover.py
index e9d3f60..2a80fc0 100644
--- a/nephilim/plugins/AlbumCover.py
+++ b/nephilim/plugins/AlbumCover.py
@@ -66,9 +66,9 @@ class wgAlbumCover(QtGui.QLabel):
self.connect(save_action, QtCore.SIGNAL('triggered()'), self._save_cover)
# MPD events
- self.connect(self.plugin.mpclient(), QtCore.SIGNAL('song_changed'), self.refresh)
- self.connect(self.plugin.mpclient(), QtCore.SIGNAL('disconnected'), self.refresh)
- self.connect(self.plugin.mpclient(), QtCore.SIGNAL('state_changed'),self.refresh)
+ self.connect(self.plugin.mpclient, QtCore.SIGNAL('song_changed'), self.refresh)
+ self.connect(self.plugin.mpclient, QtCore.SIGNAL('disconnected'), self.refresh)
+ self.connect(self.plugin.mpclient, QtCore.SIGNAL('state_changed'),self.refresh)
self.connect(self, QtCore.SIGNAL('new_cover_fetched'), self.set_cover)
@@ -94,7 +94,7 @@ class wgAlbumCover(QtGui.QLabel):
self.plugin.emit(QtCore.SIGNAL('cover_changed'), None)
return
- if song != self.plugin.mpclient().current_song():
+ if song != self.plugin.mpclient.current_song():
return
self.cover = QtGui.QPixmap.fromImage(cover)
@@ -122,7 +122,7 @@ class wgAlbumCover(QtGui.QLabel):
self.parent().emit(QtCore.SIGNAL('new_cover_fetched'), self.song, cover, write)
def _fetch_cover(self, fetch_func):
- song = self.plugin.mpclient().current_song()
+ song = self.plugin.mpclient.current_song()
if not song:
return self.emit(QtCore.SIGNAL('new_cover_fetched'), None, None)
@@ -157,7 +157,7 @@ class wgAlbumCover(QtGui.QLabel):
return cover, write
def _fetch_local_manual(self):
- song = self.plugin.mpclient().current_song()
+ song = self.plugin.mpclient.current_song()
if not song:
return self.emit(QtCore.SIGNAL('new_cover_fetched'), None, None)
diff --git a/nephilim/plugins/Filebrowser.py b/nephilim/plugins/Filebrowser.py
index 642f764..4c28eee 100644
--- a/nephilim/plugins/Filebrowser.py
+++ b/nephilim/plugins/Filebrowser.py
@@ -99,7 +99,7 @@ class wgFilebrowser(QtGui.QWidget):
except (OSError, IOError), e:
self.logger.error('Error copying to collection: %s.'%e)
- self.plugin.mpclient().update_db(target_paths)
+ self.plugin.mpclient.update_db(target_paths)
def __init__(self, plugin):
@@ -128,14 +128,14 @@ class wgFilebrowser(QtGui.QWidget):
self.view.setRootIndex(index)
self.path.setText(self.model.filePath(index))
else:
- if not 'file://' in self.plugin.mpclient().urlhandlers():
+ if not 'file://' in self.plugin.mpclient.urlhandlers():
self.logger.error('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.logger.info('Adding %d song to playlist.'%len(paths))
- 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 6fa0c92..91865bc 100644
--- a/nephilim/plugins/Library.py
+++ b/nephilim/plugins/Library.py
@@ -156,9 +156,9 @@ class LibraryWidget(QtGui.QWidget):
self.layout().addWidget(self.search_txt)
self.layout().addWidget(self.library_view)
- self.connect(self.plugin.mpclient(), QtCore.SIGNAL('connected'), self.fill_library)
- self.connect(self.plugin.mpclient(), QtCore.SIGNAL('disconnected'), self.fill_library)
- self.connect(self.plugin.mpclient(), QtCore.SIGNAL('db_updated'), self.fill_library)
+ self.connect(self.plugin.mpclient, QtCore.SIGNAL('connected'), self.fill_library)
+ self.connect(self.plugin.mpclient, QtCore.SIGNAL('disconnected'), self.fill_library)
+ self.connect(self.plugin.mpclient, QtCore.SIGNAL('db_updated'), self.fill_library)
def refresh_modes(self):
self.modes.clear()
@@ -168,7 +168,7 @@ class LibraryWidget(QtGui.QWidget):
def fill_library(self):
self.logger.info('Refreshing library.')
- self.library_model.fill(self.plugin.mpclient().library(), str(self.modes.currentText()))
+ self.library_model.fill(self.plugin.mpclient.library(), str(self.modes.currentText()))
def filter_changed(self, text):
items = self.library_model.findItems(text, QtCore.Qt.MatchContains|QtCore.Qt.MatchRecursive)
@@ -191,7 +191,7 @@ class LibraryWidget(QtGui.QWidget):
paths = []
for item in items:
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 not item.hasChildren():
diff --git a/nephilim/plugins/Lyrics.py b/nephilim/plugins/Lyrics.py
index b49e18c..5f6d579 100644
--- a/nephilim/plugins/Lyrics.py
+++ b/nephilim/plugins/Lyrics.py
@@ -54,7 +54,7 @@ class wgLyrics(QtGui.QWidget):
if not song:
return self.txtView.clear()
- if song != self.p.mpclient().current_song():
+ if song != self.p.mpclient.current_song():
return
self.txtView.clear()
@@ -84,11 +84,11 @@ class Lyrics(Plugin):
for site in _available_sites:
if site in self.settings().value('%s/sites'%self.name).toStringList():
self.sites.append(site)
- self.connect(self.mpclient(), QtCore.SIGNAL('song_changed'), self.refresh)
+ self.connect(self.mpclient, QtCore.SIGNAL('song_changed'), self.refresh)
def _unload(self):
self.o = None
self.sites = []
- self.disconnect(self.mpclient(), QtCore.SIGNAL('song_changed'), self.refresh)
+ self.disconnect(self.mpclient, QtCore.SIGNAL('song_changed'), self.refresh)
def info(self):
return "Show (and fetch) the lyrics of the currently playing song."
@@ -106,7 +106,7 @@ class Lyrics(Plugin):
def refresh(self):
self.logger.info('Autorefreshing lyrics.')
- song = self.mpclient().current_song()
+ song = self.mpclient.current_song()
if not song:
return self.o.set_lyrics(None, None)
diff --git a/nephilim/plugins/Notify.py b/nephilim/plugins/Notify.py
index 4192d67..a686555 100644
--- a/nephilim/plugins/Notify.py
+++ b/nephilim/plugins/Notify.py
@@ -107,23 +107,23 @@ class Notify(Plugin):
def _load(self):
self.o = winNotify(self)
- self.connect(self.mpclient(), QtCore.SIGNAL('song_changed'), self.onSongChange)
- self.connect(self.mpclient(), QtCore.SIGNAL('connected'), self.onConnected)
- self.connect(self.mpclient(), QtCore.SIGNAL('disconnected'), self.onDisconnect)
- self.connect(self.mpclient(), QtCore.SIGNAL('state_changed'), self.onStateChange)
- self.connect(self.mpclient(), QtCore.SIGNAL('volume_changed'),self.onVolumeChange)
+ self.connect(self.mpclient, QtCore.SIGNAL('song_changed'), self.onSongChange)
+ self.connect(self.mpclient, QtCore.SIGNAL('connected'), self.onConnected)
+ self.connect(self.mpclient, QtCore.SIGNAL('disconnected'), self.onDisconnect)
+ self.connect(self.mpclient, QtCore.SIGNAL('state_changed'), self.onStateChange)
+ self.connect(self.mpclient, QtCore.SIGNAL('volume_changed'),self.onVolumeChange)
def _unload(self):
self.o=None
- self.disconnect(self.mpclient(), QtCore.SIGNAL('song_changed'), self.onSongChange)
- self.disconnect(self.mpclient(), QtCore.SIGNAL('connected'), self.onConnected)
- self.disconnect(self.mpclient(), QtCore.SIGNAL('disconnected'), self.onDisconnect)
- self.disconnect(self.mpclient(), QtCore.SIGNAL('state_changed'), self.onStateChange)
- self.disconnect(self.mpclient(), QtCore.SIGNAL('volume_changed'),self.onVolumeChange)
+ self.disconnect(self.mpclient, QtCore.SIGNAL('song_changed'), self.onSongChange)
+ self.disconnect(self.mpclient, QtCore.SIGNAL('connected'), self.onConnected)
+ self.disconnect(self.mpclient, QtCore.SIGNAL('disconnected'), self.onDisconnect)
+ self.disconnect(self.mpclient, QtCore.SIGNAL('state_changed'), self.onStateChange)
+ self.disconnect(self.mpclient, QtCore.SIGNAL('volume_changed'),self.onVolumeChange)
def getInfo(self):
return "Show interesting events in a popup window."
def onSongChange(self):
- song = self.mpclient().current_song()
+ song = self.mpclient.current_song()
if not song:
return
self.settings().beginGroup(self.name)
diff --git a/nephilim/plugins/PlayControl.py b/nephilim/plugins/PlayControl.py
index a809a3a..8153eb7 100644
--- a/nephilim/plugins/PlayControl.py
+++ b/nephilim/plugins/PlayControl.py
@@ -82,31 +82,31 @@ class wgPlayControl(QtGui.QToolBar):
self.random = self.addAction(QtGui.QIcon('gfx/media-playlist-shuffle.svgz'), 'random')
self.random.setCheckable(True)
- self.connect(self.random, QtCore.SIGNAL('toggled(bool)'), self.p.mpclient().random)
- self.connect(self.p.mpclient(), QtCore.SIGNAL('random_changed'), self.random.setChecked)
+ self.connect(self.random, QtCore.SIGNAL('toggled(bool)'), self.p.mpclient.random)
+ self.connect(self.p.mpclient, QtCore.SIGNAL('random_changed'), self.random.setChecked)
self.repeat = self.addAction(QtGui.QIcon('gfx/media-playlist-repeat.svg'), 'repeat')
self.repeat.setCheckable(True)
- self.connect(self.p.mpclient(), QtCore.SIGNAL('repeat_changed'), self.repeat.setChecked)
- self.connect(self.repeat, QtCore.SIGNAL('toggled(bool)'), self.p.mpclient().repeat)
+ self.connect(self.p.mpclient, QtCore.SIGNAL('repeat_changed'), self.repeat.setChecked)
+ self.connect(self.repeat, QtCore.SIGNAL('toggled(bool)'), self.p.mpclient.repeat)
self.single = self.addAction(QtGui.QIcon('gfx/single.png'), 'single mode')
self.single.setCheckable(True)
- self.connect(self.p.mpclient(), QtCore.SIGNAL('single_changed'), self.single.setChecked)
- self.connect(self.single, QtCore.SIGNAL('toggled(bool)'), self.p.mpclient().single)
+ self.connect(self.p.mpclient, QtCore.SIGNAL('single_changed'), self.single.setChecked)
+ self.connect(self.single, QtCore.SIGNAL('toggled(bool)'), self.p.mpclient.single)
self.consume = self.addAction(QtGui.QIcon('gfx/consume.png'), 'consume mode')
self.consume.setCheckable(True)
- self.connect(self.p.mpclient(), QtCore.SIGNAL('consume_changed'), self.consume.setChecked)
- self.connect(self.consume, QtCore.SIGNAL('toggled(bool)'), self.p.mpclient().consume)
+ self.connect(self.p.mpclient, QtCore.SIGNAL('consume_changed'), self.consume.setChecked)
+ self.connect(self.consume, QtCore.SIGNAL('toggled(bool)'), self.p.mpclient.consume)
self.connect(self, QtCore.SIGNAL('orientationChanged(Qt::Orientation)'), self.vol_slider.setOrientation)
- self.connect(self.p.mpclient(), QtCore.SIGNAL('state_changed'), self.onStateChange)
- self.connect(self.p.mpclient(), QtCore.SIGNAL('volume_changed'), self.onVolumeChange)
+ self.connect(self.p.mpclient, QtCore.SIGNAL('state_changed'), self.onStateChange)
+ self.connect(self.p.mpclient, QtCore.SIGNAL('volume_changed'), self.onVolumeChange)
def onStateChange(self, new_state):
- status = self.p.mpclient().status()
+ status = self.p.mpclient.status()
if new_state == 'play':
self.play_action.setIcon(self.pause_icon)
@@ -119,26 +119,26 @@ class wgPlayControl(QtGui.QToolBar):
self.vol_slider.setValue(new_vol)
def on_play_click(self):
- status=self.p.mpclient().status()
+ status=self.p.mpclient.status()
if status['state']=='play':
self.logger.info('Toggling playback')
- self.p.mpclient().pause()
+ self.p.mpclient.pause()
elif status['state']=='stop':
self.logger.info('Pausing playback')
- self.p.mpclient().play(None)
+ self.p.mpclient.play(None)
else:
- self.p.mpclient().resume()
+ self.p.mpclient.resume()
def on_stop_click(self):
self.logger.info('Stopping playback')
- self.p.mpclient().stop()
+ self.p.mpclient.stop()
def on_prev_click(self):
self.logger.info('Playing previous')
- self.p.mpclient().previous()
+ self.p.mpclient.previous()
def on_next_click(self):
self.logger.info('Playing next')
- self.p.mpclient().next()
+ self.p.mpclient.next()
def onVolumeSliderChange(self):
- self.p.mpclient().set_volume(self.vol_slider.value())
+ self.p.mpclient.set_volume(self.vol_slider.value())
class PlayControl(Plugin):
o = None
diff --git a/nephilim/plugins/Playlist.py b/nephilim/plugins/Playlist.py
index f9b1a54..da10677 100644
--- a/nephilim/plugins/Playlist.py
+++ b/nephilim/plugins/Playlist.py
@@ -70,19 +70,19 @@ class PlaylistWidget(QtGui.QWidget):
self.connect(self, QtCore.SIGNAL('itemActivated(QTreeWidgetItem*, int)'), self._song_activated)
self.connect(self.header(), QtCore.SIGNAL('geometriesChanged()'), self._save_state)
- self.connect(self.plugin.mpclient(), QtCore.SIGNAL('playlist_changed'), self.fill)
- self.connect(self.plugin.mpclient(), QtCore.SIGNAL('disconnected'), self.fill)
+ self.connect(self.plugin.mpclient, QtCore.SIGNAL('playlist_changed'), self.fill)
+ self.connect(self.plugin.mpclient, QtCore.SIGNAL('disconnected'), self.fill)
def _save_state(self):
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().id())
+ self.plugin.mpclient.play(item.data(0, QtCore.Qt.UserRole).toPyObject().id())
def fill(self):
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.tag(str(columns[i]))))
@@ -95,7 +95,7 @@ class PlaylistWidget(QtGui.QWidget):
for item in self.selectedItems():
ids.append(item.data(0, QtCore.Qt.UserRole).toPyObject().id())
- self.plugin.mpclient().delete(ids)
+ self.plugin.mpclient.delete(ids)
else:
QtGui.QTreeWidget.keyPressEvent(self, event)
diff --git a/nephilim/plugins/Songinfo.py b/nephilim/plugins/Songinfo.py
index fb9d3fe..86739e9 100644
--- a/nephilim/plugins/Songinfo.py
+++ b/nephilim/plugins/Songinfo.py
@@ -48,10 +48,10 @@ class SonginfoWidget(QtGui.QWidget):
self.labels[item].setWordWrap(True)
self.layout().addWidget(self.labels[item])
- self.connect(self.plugin.mpclient(), QtCore.SIGNAL('song_changed'), self.on_song_change)
+ self.connect(self.plugin.mpclient, QtCore.SIGNAL('song_changed'), self.on_song_change)
def on_song_change(self):
- song = self.plugin.mpclient().current_song()
+ song = self.plugin.mpclient.current_song()
if not song:
for item in self.labels:
self.labels[item].setText('<b>%s</b>:'%item)
diff --git a/nephilim/plugins/Systray.py b/nephilim/plugins/Systray.py
index 2dc16f8..23f7210 100644
--- a/nephilim/plugins/Systray.py
+++ b/nephilim/plugins/Systray.py
@@ -36,7 +36,7 @@ class Systray(Plugin):
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
@@ -48,12 +48,12 @@ class Systray(Plugin):
self.parent().connect(self.o, QtCore.SIGNAL('activated (QSystemTrayIcon::ActivationReason)')
, self.onSysTrayClick)
- self.connect(self.mpclient(), QtCore.SIGNAL('song_changed'), self.update)
+ self.connect(self.mpclient, QtCore.SIGNAL('song_changed'), self.update)
self.o.show()
def _unload(self):
- self.disconnect(self.mpclient(), QtCore.SIGNAL('song_changed'), self.update)
- self.disconnect(self.mpclient(), QtCore.SIGNAL('disconnected'), self.update)
- self.disconnect(self.mpclient(), QtCore.SIGNAL('time_changed'), self.update)
+ self.disconnect(self.mpclient, QtCore.SIGNAL('song_changed'), self.update)
+ self.disconnect(self.mpclient, QtCore.SIGNAL('disconnected'), self.update)
+ self.disconnect(self.mpclient, QtCore.SIGNAL('time_changed'), self.update)
self.o.hide()
self.o.setIcon(QtGui.QIcon(None))
self.o = None
@@ -62,7 +62,7 @@ class Systray(Plugin):
return "Display the mpclientpc icon in the systray."
def update(self):
- status = self.mpclient().status()
+ status = self.mpclient.status()
if not status:
return
@@ -72,7 +72,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:
@@ -87,10 +87,10 @@ class Systray(Plugin):
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