summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--nephilim/mpclient.py121
-rw-r--r--nephilim/plugin.py6
-rw-r--r--nephilim/plugins/AlbumCover.py7
-rw-r--r--nephilim/plugins/Library.py8
-rw-r--r--nephilim/plugins/Lyrics.py8
-rw-r--r--nephilim/plugins/Notify.py29
-rw-r--r--nephilim/plugins/PlayControl.py21
-rw-r--r--nephilim/plugins/Playlist.py6
-rw-r--r--nephilim/plugins/Systray.py21
-rw-r--r--nephilim/winConnect.py19
-rw-r--r--nephilim/winMain.py40
11 files changed, 123 insertions, 163 deletions
diff --git a/nephilim/mpclient.py b/nephilim/mpclient.py
index 2ee58b2..91afd40 100644
--- a/nephilim/mpclient.py
+++ b/nephilim/mpclient.py
@@ -8,7 +8,6 @@ from clSong import Song
class MPClient(QtCore.QObject):
"""This class offers another layer above pympd, with usefull events."""
_client = None # MPD client
- _listeners = None # array of listeners: { event: (listeners)* }
# cached objects
_cur_lib = None
@@ -27,24 +26,9 @@ class MPClient(QtCore.QObject):
_retr_mutex = QtCore.QMutex()
- events = {
- 'beforeSongChange':'curSongID',
- 'onSongChange':'oldSongID, newSongID',
- 'onTimeChange':'oldTime, newTime',
- 'onStateChange':'oldState, newState',
- 'onVolumeChange':'oldVolume, newVolume',
- 'onConnect':'',
- 'onDisconnect':'',
- 'onReady':'', # when connected, and initialisation is ready
- 'onUpdateDBStart':'', # start updating database
- 'onUpdateDBFinish':'', # when updating database has finished
- 'onPlaylistChange' : '',
- }
-
def __init__(self):
QtCore.QObject.__init__(self)
self._client = None
- self._listeners = {}
self._cur_songid = -1
self._cur_time = -1
@@ -54,10 +38,7 @@ class MPClient(QtCore.QObject):
self._cur_playlist = []
self._cur_plist_id = -1
- for event in self.events:
- self._listeners[event] = []
-
- def connect(self, host, port):
+ def connect_mpd(self, host, port):
"""Connect to MPD@host:port. Returns Tue at success, False otherwise."""
if self._client:
return True
@@ -68,18 +49,18 @@ class MPClient(QtCore.QObject):
self._client = None
return False
- self._raiseEvent('onConnect', None)
+ self.emit(QtCore.SIGNAL('connected'))
self._update_lib()
self._update_playlist()
self._update_current_song()
self._timer_id = self.startTimer(500)
- self._raiseEvent('onStateChange', {'oldState':'stop', 'newState':self.status()['state']})
- self._raiseEvent('onReady', None)
+ self.emit(QtCore.SIGNAL('state_changed'), 'stop', self.status()['state'])
+ self.emit(QtCore.SIGNAL('ready'))
return True
- def disconnect(self):
+ def disconnect_mpd(self):
"""Disconnect from MPD."""
if self._client:
self._client.close()
@@ -186,12 +167,7 @@ class MPClient(QtCore.QObject):
def next(self):
"""Move on to the next song in the playlist."""
self._playCalled = False
- self._raiseEvent('beforeSongChange', {'curSongID': self._cur_songid})
- # we only switch to the next song, if some of beforeSongChange's listeners
- # didn't explicitly call play. If it did, then it ain't good to immediatly
- # skip to the next song!
- if not self._playCalled:
- self._client.next()
+ self._client.next()
def previous(self):
"""Move back to the previous song in the playlist."""
self._client.previous()
@@ -236,17 +212,6 @@ class MPClient(QtCore.QObject):
volume = min(100, max(0, volume))
self._client.setvol(volume)
- def add_listener(self, event, callback):
- """Add callback to the listeners for event."""
- if not(event in self.events):
- raise Exception("Unknown event "+event)
- self._listeners[event].append(callback)
- def remove_listener(self, event, callback):
- """Remove callback from listeners for event."""
- if not(event in self.events):
- raise Exception("Unknown event "+event)
- self._listeners[event].remove(callback)
-
def _retrieve(self, method):
"""Makes sure only one call is made at a time to MPD."""
self._retr_mutex.lock()
@@ -282,80 +247,60 @@ class MPClient(QtCore.QObject):
else:
self._cur_song = Song(song)
- class SimpleThread(Thread):
- callback = None
- params = None
- def __init__(self,callback,params):
- Thread.__init__(self)
- self.callback = callback
- self.params = params
- def run(self):
- self.callback(self.params)
-
- def _raiseEvent(self, event, params):
- """Call all listeners for event with parameters params."""
- if not(event in self.events):
- raise Exception("Unknown raised event "+event)
-
- for listener in self._listeners[event]:
- self.SimpleThread(listener, params).run()
-
def timerEvent(self, event):
"""Check for changes since last check."""
status = self.status()
- if status == None:
+ if not status:
self._client = None
- self._raiseEvent('onDisconnect', None)
+ self.emit(QtCore.SIGNAL('disconnected'))
self.killTimer(self._timer_id)
return
+ # check if song has changed
self._update_current_song()
- " check if song has changed"
song = self._cur_song
if song:
- curID = song.getID()
+ cur_id = song.getID()
else:
- curID = -1
+ cur_id = -1
- if curID != self._cur_songid:
- self._raiseEvent('onSongChange', {'oldSongID':self._cur_songid, 'newSongID':curID})
- self._cur_songid = curID
+ if cur_id != self._cur_songid:
+ self.emit(QtCore.SIGNAL('song_changed'), cur_id)
+ self._cur_songid = cur_id
- " check if the time has changed"
+ # check if the time has changed
if 'time' in status:
- curTime = status['time']
- if curTime!=self._cur_time:
- self._raiseEvent('onTimeChange', {'oldTime':self._cur_time, 'newTime':curTime})
- self._cur_time = curTime
- if curTime>=status['length']-1:
- self._raiseEvent('beforeSongChange', {'curSongID':curID})
-
- " check if the playing state has changed"
+ cur_time = status['time']
+ if cur_time != self._cur_time:
+ self.emit(QtCore.SIGNAL('time_changed'), cur_time)
+ self._cur_time = cur_time
+
+ # check if the playing state has changed
if 'state' in status:
- curState = status['state']
- if curState!=self._cur_state:
- self._raiseEvent('onStateChange', {'oldState':self._cur_state, 'newState':curState})
- self._cur_state = curState
+ cur_state = status['state']
+ if cur_state != self._cur_state:
+ self.emit(QtCore.SIGNAL('state_changed'), cur_state)
+ self._cur_state = cur_state
- " check if the volume has changed"
+ #check if the volume has changed
if 'volume' in status:
- curVolume = int(status['volume'])
- if curVolume!=self._cur_volume:
- self._raiseEvent('onVolumeChange', {'oldVolume':self._cur_volume, 'newVolume':curVolume})
- self._cur_volume = curVolume
+ cur_vol = int(status['volume'])
+ if cur_vol != self._cur_volume:
+ self.emit(QtCore.SIGNAL('volume_changed'), cur_vol)
+ self._cur_volume = cur_vol
if 'playlist' in status:
cur_plist_id = int(status['playlist'])
if cur_plist_id != self._cur_plist_id:
self._update_playlist()
- self._raiseEvent('onPlaylistChange', None)
+ self.emit(QtCore.SIGNAL('playlist_changed'))
self._cur_plist_id = cur_plist_id
" update has started"
if 'updatings_db' in status and self._updatings_db == None:
self._updatings_db = status['updatings_db']
- self._raiseEvent('onUpdateDBStart', {})
+ self.emit(QtCore.SIGNAL('update_started'))
if not('updatings_db' in status) and self._updatings_db:
self._updatings_db = None
- self._raiseEvent('onUpdateDBFinish')
+ self.emit(QtCore.SIGNAL('update_finished'))
diff --git a/nephilim/plugin.py b/nephilim/plugin.py
index dcbd1a0..86a379c 100644
--- a/nephilim/plugin.py
+++ b/nephilim/plugin.py
@@ -5,7 +5,7 @@ import logging
import plugins
from misc import *
-class Plugin:
+class Plugin(QtCore.QObject):
_name = None
_dock_widget = None
_settings = None
@@ -14,9 +14,9 @@ class Plugin:
_parent = None
_mpclient = None
DEFAULTS = {}
- LISTENERS = {}
def __init__(self, parent, mpclient, name):
+ QtCore.QObject.__init__(self)
self._name = name
self._parent = parent
self._mpclient = mpclient
@@ -31,8 +31,6 @@ class Plugin:
self._settings.setValue(key, QVariant(self.DEFAULTS[key]))
self._settings.endGroup()
- for event, listener in self.LISTENERS.iteritems():
- self._listeners.append([event, eval('self.%s'%listener)])
def name(self):
return self._name
diff --git a/nephilim/plugins/AlbumCover.py b/nephilim/plugins/AlbumCover.py
index b65717b..412553a 100644
--- a/nephilim/plugins/AlbumCover.py
+++ b/nephilim/plugins/AlbumCover.py
@@ -37,6 +37,11 @@ class wgAlbumCover(QtGui.QLabel):
self.connect(view_action, QtCore.SIGNAL('triggered()'), self.view_cover)
self.connect(save_action, QtCore.SIGNAL('triggered()'), self.save_cover)
+ self.connect(self.p.mpclient(), QtCore.SIGNAL('song_changed'), self.refresh)
+ self.connect(self.p.mpclient(), QtCore.SIGNAL('ready'), self.refresh)
+ self.connect(self.p.mpclient(), QtCore.SIGNAL('disconnected'), self.refresh)
+ self.connect(self.p.mpclient(), QtCore.SIGNAL('state_changed'),self.refresh)
+
def mousePressEvent(self, event):
if event.button() == QtCore.Qt.RightButton:
self.menu.popup(event.globalPos())
@@ -200,8 +205,6 @@ class AlbumCover(Plugin):
o = None
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)
diff --git a/nephilim/plugins/Library.py b/nephilim/plugins/Library.py
index ecc2743..9790821 100644
--- a/nephilim/plugins/Library.py
+++ b/nephilim/plugins/Library.py
@@ -12,8 +12,6 @@ class Library(Plugin):
'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)
@@ -87,6 +85,10 @@ class LibraryWidget(QtGui.QWidget):
self.layout().addWidget(self.search_txt)
self.layout().addWidget(self.library)
+ self.connect(self.plugin.mpclient(), QtCore.SIGNAL('ready'), self.fill_library)
+ self.connect(self.plugin.mpclient(), QtCore.SIGNAL('disconnected'), self.fill_library)
+ self.connect(self.plugin.mpclient(), QtCore.SIGNAL('update_finished'), self.fill_library)
+
def refresh_modes(self):
self.modes.clear()
for mode in self.settings.value('/modes').toString().split('\n'):
@@ -94,7 +96,7 @@ class LibraryWidget(QtGui.QWidget):
self.modes.setCurrentIndex(self.settings.value('current_mode').toInt()[0])
- def fill_library(self, params = None):
+ def fill_library(self):
self.library.clear()
#build a tree from library
diff --git a/nephilim/plugins/Lyrics.py b/nephilim/plugins/Lyrics.py
index 8ed376e..4cb2e16 100644
--- a/nephilim/plugins/Lyrics.py
+++ b/nephilim/plugins/Lyrics.py
@@ -23,6 +23,7 @@ class wgLyrics(QtGui.QWidget):
self.layout().setMargin(0)
self.layout().addWidget(self.txtView)
+
def set_lyrics(self, song, lyrics):
self.txtView.clear()
@@ -41,19 +42,22 @@ class Lyrics(Plugin):
o = None
DEFAULTS = {'sites' : ['lyricwiki'], 'lyricdir' : '$musicdir/$songdir',
'lyricname' : '.lyric_mpclient_$artist_$album_$song'}
- LISTENERS = {'onSongChange' : 'refresh', 'onReady' : 'refresh'}
def _load(self):
self.o = wgLyrics(self)
+ self.connect(self.mpclient(), QtCore.SIGNAL('song_changed'), self.refresh)
+ self.connect(self.mpclient(), QtCore.SIGNAL('ready'), self.refresh)
def _unload(self):
self.o = None
+ self.disconnect(self.mpclient(), QtCore.SIGNAL('song_changed'), self.refresh)
+ self.disconnect(self.mpclient(), QtCore.SIGNAL('ready'), self.refresh)
def getInfo(self):
return "Show (and fetch) the lyrics of the currently playing song."
def _get_dock_widget(self):
return self._create_dock(self.o)
- def refresh(self, params = None):
+ def refresh(self):
lyrics = None
song = self.mpclient().current_song()
if not song:
diff --git a/nephilim/plugins/Notify.py b/nephilim/plugins/Notify.py
index 4326a32..7535f05 100644
--- a/nephilim/plugins/Notify.py
+++ b/nephilim/plugins/Notify.py
@@ -45,6 +45,8 @@ class winNotify(QtGui.QWidget):
font.setPixelSize(20)
self.setFont(font)
+ self.connect
+
def mousePressEvent(self, event):
self.hide()
@@ -82,18 +84,25 @@ class Notify(Plugin):
o=None
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.connect(self.mpclient(), QtCore.SIGNAL('song_changed'), self.onSongChange)
+ self.connect(self.mpclient(), QtCore.SIGNAL('ready'), self.onReady)
+ 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('ready'), self.onReady)
+ 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, params):
+ def onSongChange(self):
song = self.mpclient().current_song()
if not song:
return
@@ -102,17 +111,17 @@ class Notify(Plugin):
NOTIFY_PRIORITY_SONG)
self.settings().endGroup()
- def onReady(self, params):
+ def onReady(self):
self.o.show('%s loaded'%APPNAME, self.settings().value(self.name() + '/timer').toInt()[0])
- def onDisconnect(self, params):
+ def onDisconnect(self):
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])
+ def onStateChange(self, new_state):
+ self.o.show(new_state, 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)
+ def onVolumeChange(self, new_vol):
+ self.o.show('Volume: %i%%'%(new_vol), self.settings().value(self.name() + '/timer').toInt()[0], priority = NOTIFY_PRIORITY_VOLUME)
class SettingsWidgetNotify(Plugin.SettingsWidget):
format = None
diff --git a/nephilim/plugins/PlayControl.py b/nephilim/plugins/PlayControl.py
index b6755e2..9eb1855 100644
--- a/nephilim/plugins/PlayControl.py
+++ b/nephilim/plugins/PlayControl.py
@@ -81,21 +81,24 @@ class wgPlayControl(QtGui.QToolBar):
# queue gets loaded in _load of pluginPlayControl
self.queuedSongs=[]
+ self.connect(self.p.mpclient(), QtCore.SIGNAL('state_changed'), self.onStateChange)
+ self.connect(self.p.mpclient(), QtCore.SIGNAL('volume_changed'), self.onVolumeChange)
+
def addSongsToQueue(self, songs):
self.queuedSongs.extend(songs)
- def onStateChange(self, params):
+ def onStateChange(self, new_state):
status = self.p.mpclient().status()
- if status['state'] == 'play':
+ if new_state == 'play':
self.btnPlayPause.changeIcon('gfx/media-playback-pause.svg')
self.btnPlayPause.setToolTip('pauze')
- elif status['state'] == 'pause' or status['state'] == 'stop':
+ elif new_state == 'pause' or new_state == 'stop':
self.btnPlayPause.changeIcon('gfx/media-playback-start.svg')
self.btnPlayPause.setToolTip('play')
- def onVolumeChange(self, params):
- self.slrVolume.setValue(params['newVolume'])
+ def onVolumeChange(self, new_vol):
+ self.slrVolume.setValue(new_vol)
def onBtnPlayPauseClick(self):
status=self.p.mpclient().status()
@@ -144,8 +147,6 @@ class wgPlayControl(QtGui.QToolBar):
class PlayControl(Plugin):
o=None
DEFAULTS = {'queue' : ''}
- LISTENERS = {'onStateChange' : 'onStateChange', 'onVolumeChange' : 'onVolumeChange',
- 'onReady' : 'onStateChange'}
def _load(self):
self.o = wgPlayControl(self, None)
@@ -160,9 +161,3 @@ class PlayControl(Plugin):
def addSongsToQueue(self, songs):
return self.o.addSongsToQueue(songs)
-
- def onStateChange(self, params):
- 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 9d32e8c..e894b86 100644
--- a/nephilim/plugins/Playlist.py
+++ b/nephilim/plugins/Playlist.py
@@ -7,8 +7,6 @@ class Playlist(Plugin):
o = None
DEFAULTS = {'columns': ['track', 'title', 'artist',
'date', 'album', 'length']}
- LISTENERS = {'onPlaylistChange' : 'on_playlist_change',
- 'onDisconnect' : 'on_playlist_change', 'onReady' : 'on_playlist_change'}
def _load(self):
self.o = PlaylistWidget(self)
@@ -40,6 +38,10 @@ class PlaylistWidget(QtGui.QWidget):
self.layout().setMargin(0)
self.layout().addWidget(self.playlist)
+ self.connect(self.plugin.mpclient(), QtCore.SIGNAL('playlist_changed'), self.fill_playlist)
+ self.connect(self.plugin.mpclient(), QtCore.SIGNAL('disconnected'), self.fill_playlist)
+ self.connect(self.plugin.mpclient(), QtCore.SIGNAL('ready'), self.fill_playlist)
+
class Playlist(QtGui.QTreeWidget):
song = None
plugin = None
diff --git a/nephilim/plugins/Systray.py b/nephilim/plugins/Systray.py
index 744f16b..5a8212c 100644
--- a/nephilim/plugins/Systray.py
+++ b/nephilim/plugins/Systray.py
@@ -12,8 +12,6 @@ class Systray(Plugin):
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.appIcon = QtGui.QIcon(appIcon)
@@ -35,17 +33,28 @@ class Systray(Plugin):
self.o.installEventFilter(self.eventObj)
self.parent().connect(self.o, QtCore.SIGNAL('activated (QSystemTrayIcon::ActivationReason)')
, self.onSysTrayClick)
- self.o.show()
+ self.connect(self.mpclient(), QtCore.SIGNAL('song_changed'), self.update)
+ self.connect(self.mpclient(), QtCore.SIGNAL('ready'), self.update)
+ self.connect(self.mpclient(), QtCore.SIGNAL('connected'), self.update)
+ self.connect(self.mpclient(), QtCore.SIGNAL('disconnected'), self.update)
+ self.connect(self.mpclient(), QtCore.SIGNAL('time_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('ready'), self.update)
+ self.disconnect(self.mpclient(), QtCore.SIGNAL('connected'), 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
- self.parent()._wheelEvent=None
+ self.o = None
+ self.parent()._wheelEvent = None
def getInfo(self):
return "Display the mpclientpc icon in the systray."
- def update(self, params):
+ def update(self):
status = self.mpclient().status()
if not status:
return
diff --git a/nephilim/winConnect.py b/nephilim/winConnect.py
index 45789ac..f88472b 100644
--- a/nephilim/winConnect.py
+++ b/nephilim/winConnect.py
@@ -12,8 +12,7 @@ class winConnect(QtGui.QWidget):
mpclient = None
settings = None
-
- def __init__(self,parent):
+ def __init__(self, parent):
QtGui.QWidget.__init__(self, parent)
self.settings = QtCore.QSettings(ORGNAME, APPNAME)
self.txtHost = QtGui.QLineEdit(self.settings.value('MPD/host', QVariant('localhost')).toString())
@@ -36,10 +35,9 @@ class winConnect(QtGui.QWidget):
self.setLayout(frame)
self.resize(200,80)
self.center()
- doEvents()
- self.mpclient.add_listener('onReady', self.onReady)
- self.mpclient.add_listener('onConnect', self.onConnect)
+ self.connect(self.mpclient, QtCore.SIGNAL('ready'), self.onReady)
+ self.connect(self.mpclient, QtCore.SIGNAL('connected'), self.onConnect)
def center(self):
screen = QtGui.QDesktopWidget().screenGeometry()
@@ -55,22 +53,19 @@ class winConnect(QtGui.QWidget):
self.show()
self.activateWindow()
self.raise_()
- doEvents()
- def onConnect(self, params):
+ def onConnect(self):
if self._timerID:
self.killTimer(self._timerID)
self._timerID=None
self.lblInfo.setText('Connected!\nRestoring library and playlist ...')
- doEvents()
self.settings.setValue('MPD/host', QVariant(self.txtHost.text()))
self.settings.setValue('MPD/port', QVariant(self.txtPort.text()))
self.txtHost.setEnabled(False)
self.txtPort.setEnabled(False)
- doEvents()
- def onReady(self, params):
+ def onReady(self):
self.hide()
def timerEvent(self, event):
@@ -78,9 +73,7 @@ class winConnect(QtGui.QWidget):
port = int(self.txtPort.text()) if self.txtPort.text() else None
self.lblInfo.setText('Trying to connect to '+host+':'+str(port)+' ...')
- doEvents()
- self.mpclient.connect(host, port)
- doEvents()
+ self.mpclient.connect_mpd(host, port)
def windowActivationChange(self, bool):
self.activateWindow()
diff --git a/nephilim/winMain.py b/nephilim/winMain.py
index f48c2e0..6fd5ac2 100644
--- a/nephilim/winMain.py
+++ b/nephilim/winMain.py
@@ -65,7 +65,7 @@ class winMain(QtGui.QMainWindow):
self.mConnect=m.addAction('Connect ...', self.wConnect.monitor)
self.mConnect.setIcon(QtGui.QIcon(appIcon))
# disconnect
- self.mDisconnect=m.addAction('Disconnect', self.mpclient.disconnect)
+ self.mDisconnect=m.addAction('Disconnect', self.mpclient.disconnect_mpd)
self.mDisconnect.setIcon(QtGui.QIcon('gfx/disconnect.png'))
# separator
m.addSeparator()
@@ -104,14 +104,14 @@ class winMain(QtGui.QMainWindow):
self.restoreLayout()
" add event handlers"
- self.mpclient.add_listener('onReady', self.onReady)
- self.mpclient.add_listener('onConnect', self.onConnect)
- self.mpclient.add_listener('onDisconnect', self.onDisconnect)
- self.mpclient.add_listener('onUpdateDBStart', self.onUpdateDBStart)
- self.mpclient.add_listener('onUpdateDBFinish', self.onUpdateDBFinish)
- self.mpclient.add_listener('onSongChange', self.on_song_change)
- self.mpclient.add_listener('onStateChange', self.update_state_messages)
- self.mpclient.add_listener('onTimeChange', self.on_time_change)
+ self.connect(self.mpclient, QtCore.SIGNAL('ready'), self.onReady)
+ self.connect(self.mpclient, QtCore.SIGNAL('connected'), self.onConnect)
+ self.connect(self.mpclient, QtCore.SIGNAL('disconnected'), self.onDisconnect)
+ self.connect(self.mpclient, QtCore.SIGNAL('update_started'), self.onUpdateDBStart)
+ self.connect(self.mpclient, QtCore.SIGNAL('update_finished'), self.onUpdateDBFinish)
+ self.connect(self.mpclient, QtCore.SIGNAL('song_changed'), self.on_song_change)
+ self.connect(self.mpclient, QtCore.SIGNAL('state_changed'), self.update_state_messages)
+ self.connect(self.mpclient, QtCore.SIGNAL('time_changed'), self.on_time_change)
self.enableAll(True)
self.setWindowIcon(QtGui.QIcon(appIcon))
@@ -218,10 +218,10 @@ class winMain(QtGui.QMainWindow):
self.wSettings.show()
self.wSettings.raise_()
- def onReady(self, params):
+ def onReady(self):
self.initialiseData()
- def onConnect(self, params):
+ def onConnect(self):
logging.info("Connected to MPD")
self.setStatus('Restoring library and playlist ...')
self.mDisconnect.setEnabled(True)
@@ -240,19 +240,19 @@ class winMain(QtGui.QMainWindow):
self.setStatus("")
doEvents
- def onDisconnect(self, params):
+ def onDisconnect(self):
logging.info("Disconnected from MPD")
self.mDisconnect.setEnabled(False)
self.mConnect.setEnabled(True)
self.enableAll(False)
self.setStatus("You are disconnected. Choose File->Connect to reconnect!")
- def onUpdateDBFinish(self, params):
+ def onUpdateDBFinish(self):
self.setStatus('')
- def onUpdateDBStart(self, params):
+ def onUpdateDBStart(self):
self.setStatus('Updating the database. Please wait ...')
- def update_state_messages(self, params = None):
+ def update_state_messages(self):
song = self.mpclient.current_song()
if song and self.mpclient.is_playing():
self.setWindowTitle('%s by %s - %s'%(song.getTitle(), song.getArtist(), APPNAME))
@@ -264,17 +264,17 @@ class winMain(QtGui.QMainWindow):
def on_time_slider_change(self):
self.mpclient.seek(self.time_slider.value())
- def on_song_change(self, params):
+ def on_song_change(self):
status = self.mpclient.status()
self.time_slider.setMaximum(status['length'])
self.time_slider.setEnabled(True)
self.time_label.duration = sec2min(status['length'])
- self.update_state_messages(params)
+ self.update_state_messages()
- def on_time_change(self, params):
+ def on_time_change(self, new_time):
if not self.time_slider.isSliderDown():
- self.time_slider.setValue(params['newTime'])
- self.time_label.setText(sec2min(params['newTime']) + '/' + self.time_label.duration)
+ self.time_slider.setValue(new_time)
+ self.time_label.setText(sec2min(new_time) + '/' + self.time_label.duration)
def expand_tags(self, str):
# maybe there's a better place for this function