forked from tonioo/rst2pdf
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathconfigdialog.py
90 lines (80 loc) · 3.41 KB
/
configdialog.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
# -*- coding: utf-8 -*-
'''A completely generic, data-driven, configuration dialog'''
class ConfigDialog(QtGui.QDialog):
def __init__(self, parent):
QtGui.QDialog.__init__(self, parent)
# Set up the UI from designer
self.ui=UI_ConfigDialog()
self.ui.setupUi(self)
pages=[]
sections=[]
self.values={}
for sectionName, options in config.options:
# Create a page widget/layout for this section:
page=QtGui.QScrollArea()
innerpage=QtGui.QFrame()
layout=QtGui.QGridLayout()
row=-2
for optionName, definition in options:
row+=2
if definition[0]=='bool':
cb=QtGui.QCheckBox(optionName)
cb.setChecked(config.getValue(sectionName, optionName, definition[1]))
layout.addWidget(cb, row, 0, 1, 2)
self.values[sectionName+'/'+optionName]=[cb, lambda(cb): cb.isChecked()]
elif definition[0]=='int':
label=QtGui.QLabel(optionName+":")
label.setAlignment(QtCore.Qt.AlignRight|QtCore.Qt.AlignVCenter)
spin=QtGui.QSpinBox()
if definition[3] is not None:
spin.setMinimum(definition[3])
else:
spin.setMinimum(-99999)
if definition[4] is not None:
spin.setMaximum(definition[4])
else:
spin.setMaximum(99999)
spin.setValue(config.getValue(sectionName, optionName, definition[1]))
layout.addWidget(label, row, 0, 1, 1)
layout.addWidget(spin, row, 1, 1, 1)
self.values[sectionName+'/'+optionName]=[spin, lambda(spin): spin.value()]
elif definition[0]=='string':
label=QtGui.QLabel(optionName+":")
label.setAlignment(QtCore.Qt.AlignRight|QtCore.Qt.AlignVCenter)
text=QtGui.QLineEdit()
text.setText(unicode(config.getValue(sectionName, optionName, definition[1])))
layout.addWidget(label, row, 0, 1, 1)
layout.addWidget(text, row, 1, 1, 1)
self.values[sectionName+'/'+optionName]=[text, lambda(text): unicode(text.text())]
elif definition[0]=='password':
label=QtGui.QLabel(optionName+":")
label.setAlignment(QtCore.Qt.AlignRight|QtCore.Qt.AlignVCenter)
text=QtGui.QLineEdit()
text.setEchoMode(QtGui.QLineEdit.Password)
text.setText(unicode(config.getValue(sectionName, optionName, definition[1])))
layout.addWidget(label, row, 0, 1, 1)
layout.addWidget(text, row, 1, 1, 1)
self.values[sectionName+'/'+optionName]=[text, lambda(text): unicode(text.text())]
help=QtGui.QLabel(definition[2])
help.setWordWrap(True)
layout.addWidget(help, row, 2, 1, 1)
separator=QtGui.QFrame()
separator.setFrameStyle(QtGui.QFrame.HLine|QtGui.QFrame.Plain)
layout.addWidget(separator, row+1, 0, 1, 3)
innerpage.setLayout(layout)
innerpage.adjustSize()
page.resize(QtCore.QSize(innerpage.width()+5, page.height()))
page.setWidget(innerpage)
pages.append(page)
sections.append(sectionName)
for page, name in zip(pages,sections) :
# Make a tab out of it
self.ui.tabs.addTab(page, name)
self.ui.tabs.setCurrentIndex(1)
self.ui.tabs.removeTab(0)
def accept(self):
for k in self.values:
sec, opt=k.split('/')
widget, l = self.values[k]
config.setValue(sec, opt, l(widget))
QtGui.QDialog.accept(self)