1
# -*- coding: utf-8 -*-
3
# Copyright (c) 2005 - 2007 Detlev Offenbach <detlev@die-offenbachs.de>
7
Module implementing a dialog for entering multiple template variables.
12
class TemplateMultipleVariablesDialog(QDialog):
14
Class implementing a dialog for entering multiple template variables.
16
def __init__(self, variables, parent = None):
20
@param variables list of template variable names (list of strings)
21
@param parent parent widget of this dialog (QWidget)
23
QDialog.__init__(self, parent, None, 1)
25
TemplateMultipleVariablesDialogLayout = \
26
QVBoxLayout(self, 6, 6,"TemplateMultipleVariablesDialogLayout")
28
# generate the scrollview
29
self.variablesView = QScrollView(self, "variablesView")
30
self.variablesView.setFrameStyle(QFrame.NoFrame)
31
TemplateMultipleVariablesDialogLayout.addWidget(self.variablesView)
33
self.variablesView.setResizePolicy(QScrollView.AutoOneFit)
35
top = QWidget(self.variablesView.viewport())
36
self.variablesView.addChild(top)
37
grid = QGridLayout(top, len(variables), 2)
41
# populate the scrollview with labels and text edits
42
self.variablesEntries = {}
45
l = QLabel("%s:" % var, top)
46
grid.addWidget(l, row, 0, Qt.AlignTop)
47
if var.find(":") >= 0:
48
formatStr = var[1:-1].split(":")[1]
49
if formatStr in ["ml"]:
51
t.setTabChangesFocus(1)
56
grid.addWidget(t, row, 1)
57
self.variablesEntries[var] = t
59
self.variablesEntries[variables[0]].setFocus()
61
# generate the buttons
62
layout1 = QHBoxLayout(None,0,6,"layout1")
63
spacer1 = QSpacerItem(40,20,QSizePolicy.Expanding,QSizePolicy.Minimum)
64
layout1.addItem(spacer1)
66
self.okButton = QPushButton(self,"okButton")
67
self.okButton.setDefault(1)
68
layout1.addWidget(self.okButton)
70
self.cancelButton = QPushButton(self,"cancelButton")
71
layout1.addWidget(self.cancelButton)
72
spacer2 = QSpacerItem(40,20,QSizePolicy.Expanding,QSizePolicy.Minimum)
73
layout1.addItem(spacer2)
74
TemplateMultipleVariablesDialogLayout.addLayout(layout1)
76
# set the texts of the standard widgets
77
self.setCaption(self.trUtf8("Enter Template Variables"))
78
self.okButton.setText(self.trUtf8("&OK"))
79
self.okButton.setAccel(self.trUtf8("Alt+O"))
80
self.cancelButton.setText(self.trUtf8("&Cancel"))
81
self.cancelButton.setAccel(self.trUtf8("Alt+C"))
83
# polish up the dialog
84
self.resize(QSize(400,480).expandedTo(self.minimumSizeHint()))
85
self.clearWState(Qt.WState_Polished)
87
self.connect(self.okButton,SIGNAL("clicked()"),self.accept)
88
self.connect(self.cancelButton,SIGNAL("clicked()"),self.reject)
90
def getVariables(self):
92
Public method to get the values for all variables.
94
@return dictionary with the variable as a key and its value (string)
97
for var, textEdit in self.variablesEntries.items():
98
values[var] = unicode(textEdit.text())