From 7ea46b5470d3212d2b1bad639497597fb1e771f1 Mon Sep 17 00:00:00 2001 From: Anton Khirnov Date: Fri, 19 Jun 2009 15:03:40 +0200 Subject: [PATCH] move plugins enable/disable code from winMain to plugins --- nephilim/mpclient.py | 6 ++++-- nephilim/nephilim_app.py | 5 +++++ nephilim/plugin.py | 6 ++++++ nephilim/plugins/PlayControl.py | 4 ++-- nephilim/plugins/Systray.py | 2 ++ nephilim/winMain.py | 14 -------------- 6 files changed, 19 insertions(+), 18 deletions(-) diff --git a/nephilim/mpclient.py b/nephilim/mpclient.py index dfa8e3f..52743c1 100644 --- a/nephilim/mpclient.py +++ b/nephilim/mpclient.py @@ -82,7 +82,8 @@ class MPClient(QtCore.QObject): self._update_playlist() self._update_current_song() - self.emit(QtCore.SIGNAL('connected')) + self.emit(QtCore.SIGNAL('connected')) #should be removed + self.emit(QtCore.SIGNAL('connect_changed'), True) self.logger.info('Successfully connected to MPD.') self._timer_id = self.startTimer(500) self._db_timer_id = self.startTimer(10000) @@ -111,7 +112,8 @@ class MPClient(QtCore.QObject): self._cur_lib = [] self._cur_playlist = [] self._commands = [] - self.emit(QtCore.SIGNAL('disconnected')) + self.emit(QtCore.SIGNAL('disconnected')) #should be removed + self.emit(QtCore.SIGNAL('connect_changed'), False) self.logger.info('Disconnected from MPD.') def password(self, password): """Use the password to authenticate with MPD.""" diff --git a/nephilim/nephilim_app.py b/nephilim/nephilim_app.py index ee3f88c..269cc9e 100644 --- a/nephilim/nephilim_app.py +++ b/nephilim/nephilim_app.py @@ -24,6 +24,7 @@ from settings_wg import SettingsWidget import plugins class NephilimApp(QtGui.QApplication): + # public, constant "main window object" main_win = None "MPD layer" @@ -32,6 +33,8 @@ class NephilimApp(QtGui.QApplication): plugins = None "settings object" settings = None + + # private "settings window" __settings_win = None @@ -63,6 +66,8 @@ class NephilimApp(QtGui.QApplication): self.connect(self, QtCore.SIGNAL('aboutToQuit()'), self.__cleanup) + if show_settings: + self.show_settings_win() self.main_win.restore_layout() QtGui.QApplication.exec_() diff --git a/nephilim/plugin.py b/nephilim/plugin.py index fdf1c91..539cd5d 100644 --- a/nephilim/plugin.py +++ b/nephilim/plugin.py @@ -30,6 +30,7 @@ class Plugin(QtCore.QObject): _parent = None _mpclient = None + o = None logger = None DEFAULTS = {} @@ -71,6 +72,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._loaded = True def unload(self): if not self._loaded: @@ -82,9 +84,13 @@ 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._loaded = False def is_loaded(self): return self._loaded + def set_enabled(self, val): + if self.o: + self.o.setEnabled(val) def get_dock_widget(self, opts = None): self._dock_widget = self._get_dock_widget() diff --git a/nephilim/plugins/PlayControl.py b/nephilim/plugins/PlayControl.py index a1b78a8..8b05e82 100644 --- a/nephilim/plugins/PlayControl.py +++ b/nephilim/plugins/PlayControl.py @@ -145,9 +145,9 @@ class PlayControl(Plugin): def _load(self): self.o = wgPlayControl(self, None) - self.parent().addToolBar(QtCore.Qt.TopToolBarArea, self.o) + QtGui.QApplication.instance().main_win.addToolBar(QtCore.Qt.TopToolBarArea, self.o) def _unload(self): - self.parent().removeToolBar(self.o) + QtGui.QApplication.instance().main_win.removeToolBar(self.o) self.o = None def getInfo(self): return "Have total control over the playing!" diff --git a/nephilim/plugins/Systray.py b/nephilim/plugins/Systray.py index 705c968..90a64b5 100644 --- a/nephilim/plugins/Systray.py +++ b/nephilim/plugins/Systray.py @@ -111,3 +111,5 @@ class Systray(Plugin): def get_settings_widget(self): return self.SettingsWidgetSystray(self) + def set_enabled(self, val): + pass diff --git a/nephilim/winMain.py b/nephilim/winMain.py index 5b79d38..dfd8678 100644 --- a/nephilim/winMain.py +++ b/nephilim/winMain.py @@ -109,7 +109,6 @@ class winMain(QtGui.QMainWindow): 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.wConnect.monitor() self.update_state_messages() @@ -200,24 +199,11 @@ class winMain(QtGui.QMainWindow): def onConnected(self): self.mDisconnect.setEnabled(True) self.mConnect.setEnabled(False) - self.initialiseData() - - def enableAll(self, value): - for plugin in self.plugins.loaded_plugins(): - try: - plugin.o.setEnabled(value) - except: - pass - - def initialiseData(self): -# self.enableAll(True) - self.setStatus("") 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 update_state_messages(self): -- 2.11.4.GIT