From c351b5c9f9f93b95cfa57c9bf10a6807e7f1b5f7 Mon Sep 17 00:00:00 2001 From: Anton Khirnov Date: Sat, 7 Mar 2009 11:38:26 +0100 Subject: mpclient: use Qt signals/slots for events. --- nephilim/plugins/AlbumCover.py | 7 +++++-- nephilim/plugins/Library.py | 8 +++++--- nephilim/plugins/Lyrics.py | 8 ++++++-- nephilim/plugins/Notify.py | 29 +++++++++++++++++++---------- nephilim/plugins/PlayControl.py | 21 ++++++++------------- nephilim/plugins/Playlist.py | 6 ++++-- nephilim/plugins/Systray.py | 21 +++++++++++++++------ 7 files changed, 62 insertions(+), 38 deletions(-) (limited to 'nephilim/plugins') 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 -- cgit v1.2.3