from PyQt4 import QtGui, QtCore import sys from misc import * from clMonty import monty from clSettings import settings import plugins class winSettings(QtGui.QWidget): btnSave=None btnClose=None lstPlugins=None winMain=None def __init__(self, winMain, parent=None): QtGui.QWidget.__init__(self, parent) self.winMain=winMain self.btnSave=Button('save all', self.onBtnSaveClick) self.btnClose=Button('close', self.onBtnCloseClick) self.lstPlugins=QtGui.QListWidget(self) layoutWin=QtGui.QVBoxLayout() layoutButtons=QtGui.QHBoxLayout() tabWidget=QtGui.QTabWidget(parent) self.setLayout(layoutWin) tabWidget.addTab(self.lstPlugins, "plugins") for k,entry in plugins.listPlugins().iteritems(): plugin=entry[plugins.PLUGIN_INSTANCE] if plugin: tabWidget.addTab(plugin.getSettingsWidget(), plugin.getName()) self.fillList() layoutWin.addWidget(tabWidget) layoutWin.addLayout(layoutButtons) layoutButtons.addStretch() layoutButtons.addWidget(self.btnSave) layoutButtons.addWidget(self.btnClose) self.connect(self.lstPlugins, QtCore.SIGNAL('itemChanged (QListWidgetItem*)'), self.onlstPluginItemChanged) self.setWindowIcon(appIcon) self.setWindowTitle('Settings') self.setAttribute(QtCore.Qt.WA_DeleteOnClose) self.center() self.resize(800,400) doEvents() def fillList(self): self.lstPlugins.clear() for k,entry in plugins.listPlugins().iteritems(): plugin=entry[plugins.PLUGIN_INSTANCE] if plugin: item=QtGui.QListWidgetItem("%s\t%s"%(entry[plugins.PLUGIN_CLASS], plugin.getInfo())) if plugin.isLoaded(): item.setCheckState(QtCore.Qt.Checked) else: item.setCheckState(QtCore.Qt.Unchecked) if settings.get('%s.load'%(plugin.getName(True)),None)==None: # load new plugins by default item.setTextColor(QtCore.Qt.blue) settings.set('%s.load'%(plugin.getName(True)), 1) else: item=QtGui.QListWidgetItem("%s\t%s"%(entry[plugins.PLUGIN_CLASS], entry[plugins.PLUGIN_MSG])) item.setCheckState(QtCore.Qt.Unchecked) item.setTextColor(QtCore.Qt.red) self.lstPlugins.addItem(item) def center(self): screen = QtGui.QDesktopWidget().screenGeometry() size = self.geometry() self.move((screen.width()-size.width())/2, (screen.height()-size.height())/2+100) def onBtnSaveClick(self): map(lambda entry: entry[plugins.PLUGIN_INSTANCE] and entry[plugins.PLUGIN_INSTANCE].saveSettings(), plugins.listPlugins().values()) def onBtnCloseClick(self): self.close() def onlstPluginItemChanged(self, item): # check here if we have to load or unload the plugin! toload=int(item.checkState()==QtCore.Qt.Checked) className=str(item.text()[0:str(item.text()).find('\t')]) if toload: # refresh the plugin file plugin=plugins.loadPlugin(className, self.winMain) if plugin: plugin.load() self.fillList() else: plugin=plugins.getPlugin(className) if plugin: plugin.unload() if plugin: settings.set('%s.load'%(plugin.getName(True)), toload) def closeEvent(self, event): map(lambda entry: entry[plugins.PLUGIN_INSTANCE] and entry[plugins.PLUGIN_INSTANCE].resetSettingCache(), plugins.listPlugins().values()) self.winMain.wSettings=None