Don't show appname in window title when playing.
[montypc/ni.git] / winSettings.py
blob3e5e96cdc9885b48d4cf15d62e88e842a4954dae
1 from PyQt4 import QtGui, QtCore
2 from PyQt4.QtCore import QVariant
3 import os
5 from misc import ORGNAME, APPNAME, Button, appIcon, doEvents
6 import plugins
9 class winSettings(QtGui.QWidget):
10 btnSave=None
11 btnClose=None
12 lstPlugins=None
14 winMain=None
15 settings = None
16 settings_wg = []
18 class SettingsWidgetMPD(QtGui.QWidget):
19 monty = None
20 settings = None
21 host_txt = None
22 port_txt = None
23 lib_txt = None
24 update = None
26 def __init__(self, monty):
27 QtGui.QWidget.__init__(self)
28 self.settings = QtCore.QSettings(ORGNAME, APPNAME)
29 self.monty = monty
31 self.settings.beginGroup('MPD')
32 self.host_txt = QtGui.QLineEdit(self.settings.value('host', QVariant('localhost')).toString())
33 self.port_txt = QtGui.QLineEdit(self.settings.value('port', QVariant('6600')).toString())
34 self.lib_txt = QtGui.QLineEdit(self.settings.value('music_dir', QVariant(os.path.expanduser('~/music/'))).toString())
35 self.settings.endGroup()
37 self.update = QtGui.QPushButton('Update MPD database')
38 self.connect(self.update, QtCore.SIGNAL('clicked()'), self.update_db)
40 self.setLayout(QtGui.QVBoxLayout())
41 self.layout().addWidget(self.host_txt)
42 self.layout().addWidget(self.port_txt)
43 self.layout().addWidget(self.lib_txt)
44 self.layout().addWidget(self.update)
46 def save_settings(self):
47 self.settings.beginGroup('MPD')
48 self.settings.setValue('host', QVariant(self.host_txt.text()))
49 self.settings.setValue('port', QVariant(self.port_txt.text()))
50 self.settings.setValue('music_dir', QVariant(self.lib_txt.text()))
51 self.settings.endGroup()
53 def update_db(self):
54 self.monty.updateDB()
56 def __init__(self, winMain, parent=None):
57 QtGui.QWidget.__init__(self, parent)
58 self.settings = QtCore.QSettings(ORGNAME, APPNAME)
59 self.winMain = winMain
61 self.btnSave = Button('save all', self.onBtnSaveClick)
62 self.btnClose = Button('close', self.onBtnCloseClick)
64 tabWidget = QtGui.QTabWidget(parent)
65 self.settings_wg.append(self.SettingsWidgetMPD(self.winMain.monty))
66 tabWidget.addTab(self.settings_wg[-1], 'MPD settings')
68 self.lstPlugins = QtGui.QListWidget(self)
69 tabWidget.addTab(self.lstPlugins, 'plugins')
70 for k,entry in plugins.listPlugins().iteritems():
71 plugin=entry[plugins.PLUGIN_INSTANCE]
72 if plugin:
73 wg = plugin.get_settings_widget()
74 if wg:
75 self.settings_wg.append(wg)
76 tabWidget.addTab(self.settings_wg[-1], plugin.getName())
77 self.fillList()
79 self.setLayout(QtGui.QVBoxLayout())
80 self.layout().addWidget(tabWidget)
82 layoutButtons = QtGui.QHBoxLayout()
83 layoutButtons.addStretch()
84 layoutButtons.addWidget(self.btnSave)
85 layoutButtons.addWidget(self.btnClose)
86 self.layout().addLayout(layoutButtons)
88 self.connect(self.lstPlugins, QtCore.SIGNAL('itemChanged (QListWidgetItem*)'), self.onlstPluginItemChanged)
90 self.setWindowIcon(QtGui.QIcon(appIcon))
91 self.setWindowTitle('Settings')
92 self.setAttribute(QtCore.Qt.WA_DeleteOnClose)
93 self.center()
94 self.resize(800,400)
95 doEvents()
97 def fillList(self):
98 self.lstPlugins.clear()
99 for k,entry in plugins.listPlugins().iteritems():
100 plugin=entry[plugins.PLUGIN_INSTANCE]
101 if plugin:
102 if entry[plugins.PLUGIN_MSG]:
103 item=QtGui.QListWidgetItem("%s\t%s"%(entry[plugins.PLUGIN_CLASS], entry[plugins.PLUGIN_MSG]))
104 item.setCheckState(QtCore.Qt.Unchecked)
105 item.setTextColor(QtCore.Qt.red)
106 else:
107 item=QtGui.QListWidgetItem("%s\t%s"%(entry[plugins.PLUGIN_CLASS], plugin.getInfo()))
108 if plugin.isLoaded():
109 item.setCheckState(QtCore.Qt.Checked)
110 else:
111 item.setCheckState(QtCore.Qt.Unchecked)
113 if self.settings.value(plugin.getName() + '/load') == None:
114 # load new plugins by default
115 item.setTextColor(QtCore.Qt.blue)
116 self.settings.setValue(plugin.getName() + '/load', QtCore.QVariant(True))
118 else:
119 item=QtGui.QListWidgetItem("%s\t%s"%(entry[plugins.PLUGIN_CLASS], entry[plugins.PLUGIN_MSG]))
120 item.setCheckState(QtCore.Qt.Unchecked)
121 item.setTextColor(QtCore.Qt.red)
122 self.lstPlugins.addItem(item)
124 def center(self):
125 screen = QtGui.QDesktopWidget().screenGeometry()
126 size = self.geometry()
127 self.move((screen.width()-size.width())/2, (screen.height()-size.height())/2+100)
129 def onBtnSaveClick(self):
130 for wg in self.settings_wg:
131 wg.save_settings()
133 def onBtnCloseClick(self):
134 self.close()
135 def onlstPluginItemChanged(self, item):
136 # check here if we have to load or unload the plugin!
137 toload = (item.checkState() == QtCore.Qt.Checked)
138 className=str(item.text()[0:str(item.text()).find('\t')])
139 if toload:
140 # refresh the plugin file
141 plugin=plugins.loadPlugin(className, self.winMain)
142 if plugin:
143 plugin.load()
144 self.fillList()
145 self.winMain.restoreLayout()
146 else:
147 plugin=plugins.getPlugin(className)
148 if plugin:
149 plugin.unload()
150 if plugin:
151 self.settings.setValue(plugin.getName() + '/load', QtCore.QVariant(toload))
152 def closeEvent(self, event):
153 map(lambda entry: entry[plugins.PLUGIN_INSTANCE] and entry[plugins.PLUGIN_INSTANCE].resetSettingCache(), plugins.listPlugins().values())
154 self.settings_wg = None
155 self.winMain.wSettings=None