From 27e27a05b82e4a64123c30cc8261e9e69cd1bea3 Mon Sep 17 00:00:00 2001 From: Anton Khirnov Date: Fri, 19 Jun 2009 10:49:54 +0200 Subject: Split some parts of winMain into a subclass of QApplication. --- nephilim/nephilim_app.py | 91 ++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 91 insertions(+) create mode 100644 nephilim/nephilim_app.py (limited to 'nephilim/nephilim_app.py') diff --git a/nephilim/nephilim_app.py b/nephilim/nephilim_app.py new file mode 100644 index 0000000..00cb8b4 --- /dev/null +++ b/nephilim/nephilim_app.py @@ -0,0 +1,91 @@ +# +# Copyright (C) 2009 Anton Khirnov +# +# Nephilim is free software: you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# Nephilim is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with Nephilim. If not, see . +# + +from PyQt4 import QtGui, QtCore + +from winMain import winMain +from misc import ORGNAME, APPNAME, appIcon +from mpclient import MPClient +from settings_wg import SettingsWidget +import plugins + +class NephilimApp(QtGui.QApplication): + "main window object" + main_win = None + "MPD layer" + mpclient = None + "plugins interface" + plugins = None + "settings object" + settings = None + "settings window" + settings_win = None + + def __init__(self, argv): + QtGui.QApplication.__init__(self, argv) + + self.setApplicationName(APPNAME) + self.setOrganizationName(ORGNAME) + self.setWindowIcon(QtGui.QIcon(appIcon)) + + def exec_(self): + #init MPD layer + self.mpclient = MPClient() + + #init settings + self.settings = QtCore.QSettings() + + #init main window + self.main_win = winMain() + + #init plugins + show_settings = False # are there new plugins? + self.plugins = plugins.Plugins(self.main_win, self.mpclient) + for plugin in self.plugins.plugins(): + if self.settings.value(plugin.name() + '/load') == None: + show_settings = True + if self.settings.value(plugin.name() + '/load', QtCore.QVariant(True)).toBool(): + self.plugins.load(plugin.name()) + + self.connect(self, QtCore.SIGNAL('aboutToQuit()'), self.cleanup) + + self.main_win.restore_layout() + QtGui.QApplication.exec_() + + def cleanup(self): + # unload all plugins + for plugin in self.plugins.loaded_plugins(): + plugin.unload() + + self.main_win.on_quit() + self.settings.sync() + + def show_settings_win(self): + if not self.settings_win: + self.settings_win = SettingsWidget(self.mpclient, self.plugins) + + self.connect(self.settings_win, QtCore.SIGNAL('destroyed()'), self.__del_settings_win) + self.settings_win.show() + self.settings_win.raise_() + + def __del_settings_win(self): + self.settings_win = None + + def expand_tags(self, str): + ret = str + ret = ret.replace('$musicdir', self.settings.value('MPD/music_dir').toString()) + return ret -- cgit v1.2.3