|
1 # -*- coding: utf-8 -*- |
|
2 |
|
3 # Copyright (c) 2003 - 2009 Detlev Offenbach <detlev@die-offenbachs.de> |
|
4 # |
|
5 |
|
6 """ |
|
7 Module implementing the input dialog wizard dialog. |
|
8 """ |
|
9 |
|
10 import os |
|
11 |
|
12 from PyQt4.QtCore import * |
|
13 from PyQt4.QtGui import * |
|
14 |
|
15 from E4Gui.E4Application import e4App |
|
16 |
|
17 from Ui_InputDialogWizardDialog import Ui_InputDialogWizardDialog |
|
18 |
|
19 class InputDialogWizardDialog(QDialog, Ui_InputDialogWizardDialog): |
|
20 """ |
|
21 Class implementing the input dialog wizard dialog. |
|
22 |
|
23 It displays a dialog for entering the parameters |
|
24 for the QInputDialog code generator. |
|
25 """ |
|
26 def __init__(self, parent=None): |
|
27 """ |
|
28 Constructor |
|
29 |
|
30 @param parent parent widget (QWidget) |
|
31 """ |
|
32 QDialog.__init__(self, parent) |
|
33 self.setupUi(self) |
|
34 |
|
35 # set the validators for the double line edots |
|
36 self.eDoubleDefault.setValidator(\ |
|
37 QDoubleValidator(-2147483647, 2147483647, 99, self.eDoubleDefault)) |
|
38 self.eDoubleFrom.setValidator(\ |
|
39 QDoubleValidator(-2147483647, 2147483647, 99, self.eDoubleFrom)) |
|
40 self.eDoubleTo.setValidator(\ |
|
41 QDoubleValidator(-2147483647, 2147483647, 99, self.eDoubleTo)) |
|
42 |
|
43 self.bTest = \ |
|
44 self.buttonBox.addButton(self.trUtf8("Test"), QDialogButtonBox.ActionRole) |
|
45 |
|
46 @pyqtSlot(bool) |
|
47 def on_rItem_toggled(self, checked): |
|
48 """ |
|
49 Private slot to perform actions dependant on the item type selection. |
|
50 |
|
51 @param checked flag indicating the checked state (boolean) |
|
52 """ |
|
53 self.bTest.setEnabled(not checked) |
|
54 |
|
55 def on_buttonBox_clicked(self, button): |
|
56 """ |
|
57 Private slot called by a button of the button box clicked. |
|
58 |
|
59 @param button button that was clicked (QAbstractButton) |
|
60 """ |
|
61 if button == self.bTest: |
|
62 self.on_bTest_clicked() |
|
63 |
|
64 @pyqtSlot() |
|
65 def on_bTest_clicked(self): |
|
66 """ |
|
67 Private method to test the selected options. |
|
68 """ |
|
69 if self.rText.isChecked(): |
|
70 if self.rEchoNormal.isChecked(): |
|
71 echomode = QLineEdit.Normal |
|
72 elif self.rEchoNoEcho.isChecked(): |
|
73 echomode = QLineEdit.NoEcho |
|
74 else: |
|
75 echomode = QLineEdit.Password |
|
76 QInputDialog.getText(\ |
|
77 None, |
|
78 self.eCaption.text(), |
|
79 self.eLabel.text(), |
|
80 echomode, |
|
81 self.eTextDefault.text()) |
|
82 elif self.rInteger.isChecked(): |
|
83 QInputDialog.getInteger(\ |
|
84 None, |
|
85 self.eCaption.text(), |
|
86 self.eLabel.text(), |
|
87 self.sIntDefault.value(), |
|
88 self.sIntFrom.value(), |
|
89 self.sIntTo.value(), |
|
90 self.sIntStep.value()) |
|
91 elif self.rDouble.isChecked(): |
|
92 try: |
|
93 doubleDefault = float(self.eDoubleDefault.text()) |
|
94 except ValueError: |
|
95 doubleDefault = 0 |
|
96 try: |
|
97 doubleFrom = float(self.eDoubleFrom.text()) |
|
98 except ValueError: |
|
99 doubleFrom = -2147483647 |
|
100 try: |
|
101 doubleTo = float(self.eDoubleTo.text()) |
|
102 except ValueError: |
|
103 doubleTo = 2147483647 |
|
104 QInputDialog.getDouble(\ |
|
105 None, |
|
106 self.eCaption.text(), |
|
107 self.eLabel.text(), |
|
108 doubleDefault, |
|
109 doubleFrom, |
|
110 doubleTo, |
|
111 self.sDoubleDecimals.value()) |
|
112 |
|
113 def __getCode4(self, indLevel, indString): |
|
114 """ |
|
115 Private method to get the source code for Qt4. |
|
116 |
|
117 @param indLevel indentation level (int) |
|
118 @param indString string used for indentation (space or tab) (string) |
|
119 @return generated code (string) |
|
120 """ |
|
121 # calculate our indentation level and the indentation string |
|
122 il = indLevel + 1 |
|
123 istring = il * indString |
|
124 |
|
125 # now generate the code |
|
126 code = 'QInputDialog.' |
|
127 if self.rText.isChecked(): |
|
128 code += 'getText(\\%s%s' % (os.linesep, istring) |
|
129 code += 'None,%s%s' % (os.linesep, istring) |
|
130 code += 'self.trUtf8("%s"),%s%s' % \ |
|
131 (self.eCaption.text(), os.linesep, istring) |
|
132 code += 'self.trUtf8("%s"),%s%s' % \ |
|
133 (self.eLabel.text(), os.linesep, istring) |
|
134 if self.rEchoNormal.isChecked(): |
|
135 code += 'QLineEdit.Normal' |
|
136 elif self.rEchoNoEcho.isChecked(): |
|
137 code += 'QLineEdit.NoEcho' |
|
138 else: |
|
139 code += 'QLineEdit.Password' |
|
140 if self.eTextDefault.text(): |
|
141 code += ',%s%sself.trUtf8("%s")' % \ |
|
142 (os.linesep, istring, self.eTextDefault.text()) |
|
143 code += ')%s' % os.linesep |
|
144 elif self.rInteger.isChecked(): |
|
145 code += 'getInteger(\\%s%s' % (os.linesep, istring) |
|
146 code += 'None,%s%s' % (os.linesep, istring) |
|
147 code += 'self.trUtf8("%s"),%s%s' % \ |
|
148 (self.eCaption.text(), os.linesep, istring) |
|
149 code += 'self.trUtf8("%s"),%s%s' % \ |
|
150 (self.eLabel.text(), os.linesep, istring) |
|
151 code += '%d, %d, %d, %d)%s' % \ |
|
152 (self.sIntDefault.value(), self.sIntFrom.value(), |
|
153 self.sIntTo.value(), self.sIntStep.value(), os.linesep) |
|
154 elif self.rDouble.isChecked(): |
|
155 try: |
|
156 doubleDefault = float(self.eDoubleDefault.text()) |
|
157 except ValueError: |
|
158 doubleDefault = 0 |
|
159 try: |
|
160 doubleFrom = float(self.eDoubleFrom.text()) |
|
161 except ValueError: |
|
162 doubleFrom = -2147483647 |
|
163 try: |
|
164 doubleTo = float(self.eDoubleTo.text()) |
|
165 except ValueError: |
|
166 doubleTo = 2147483647 |
|
167 code += 'getDouble(\\%s%s' % (os.linesep, istring) |
|
168 code += 'None,%s%s' % (os.linesep, istring) |
|
169 code += 'self.trUtf8("%s"),%s%s' % \ |
|
170 (self.eCaption.text(), os.linesep, istring) |
|
171 code += 'self.trUtf8("%s"),%s%s' % \ |
|
172 (self.eLabel.text(), os.linesep, istring) |
|
173 code += '%s, %s, %s, %d)%s' % \ |
|
174 (doubleDefault, doubleFrom, doubleTo, |
|
175 self.sDoubleDecimals.value(), os.linesep) |
|
176 elif self.rItem.isChecked(): |
|
177 code += 'getItem(\\%s%s' % (os.linesep, istring) |
|
178 code += 'None,%s%s' % (os.linesep, istring) |
|
179 code += 'self.trUtf8("%s"),%s%s' % \ |
|
180 (self.eCaption.text(), os.linesep, istring) |
|
181 code += 'self.trUtf8("%s"),%s%s' % \ |
|
182 (self.eLabel.text(), os.linesep, istring) |
|
183 code += '%s,%s%s' % (self.eVariable.text(), os.linesep, istring) |
|
184 code += '%d, %s)%s' % \ |
|
185 (self.sCurrentItem.value(), self.cEditable.isChecked(), os.linesep) |
|
186 |
|
187 return code |
|
188 |
|
189 def getCode(self, indLevel, indString): |
|
190 """ |
|
191 Public method to get the source code. |
|
192 |
|
193 @param indLevel indentation level (int) |
|
194 @param indString string used for indentation (space or tab) (string) |
|
195 @return generated code (string) |
|
196 """ |
|
197 return self.__getCode4(indLevel, indString) |