src/eric7/Plugins/WizardPlugins/InputDialogWizard/InputDialogWizardDialog.py

branch
eric7
changeset 9221
bf71ee032bb4
parent 9209
b99e7fd55fd3
child 9264
18a7312cfdb3
child 9433
6df1aeaa4529
equal deleted inserted replaced
9220:e9e7eca7efee 9221:bf71ee032bb4
17 17
18 18
19 class InputDialogWizardDialog(QDialog, Ui_InputDialogWizardDialog): 19 class InputDialogWizardDialog(QDialog, Ui_InputDialogWizardDialog):
20 """ 20 """
21 Class implementing the input dialog wizard dialog. 21 Class implementing the input dialog wizard dialog.
22 22
23 It displays a dialog for entering the parameters 23 It displays a dialog for entering the parameters
24 for the QInputDialog code generator. 24 for the QInputDialog code generator.
25 """ 25 """
26
26 def __init__(self, parent=None): 27 def __init__(self, parent=None):
27 """ 28 """
28 Constructor 29 Constructor
29 30
30 @param parent parent widget (QWidget) 31 @param parent parent widget (QWidget)
31 """ 32 """
32 super().__init__(parent) 33 super().__init__(parent)
33 self.setupUi(self) 34 self.setupUi(self)
34 35
35 # set the validators for the double line edits 36 # set the validators for the double line edits
36 self.eDoubleDefault.setValidator( 37 self.eDoubleDefault.setValidator(
37 QDoubleValidator(-2147483647, 2147483647, 99, self.eDoubleDefault)) 38 QDoubleValidator(-2147483647, 2147483647, 99, self.eDoubleDefault)
39 )
38 self.eDoubleFrom.setValidator( 40 self.eDoubleFrom.setValidator(
39 QDoubleValidator(-2147483647, 2147483647, 99, self.eDoubleFrom)) 41 QDoubleValidator(-2147483647, 2147483647, 99, self.eDoubleFrom)
42 )
40 self.eDoubleTo.setValidator( 43 self.eDoubleTo.setValidator(
41 QDoubleValidator(-2147483647, 2147483647, 99, self.eDoubleTo)) 44 QDoubleValidator(-2147483647, 2147483647, 99, self.eDoubleTo)
42 45 )
46
43 self.rText.toggled.connect(self.__typeSelectButtonToggled) 47 self.rText.toggled.connect(self.__typeSelectButtonToggled)
44 self.rMultiLineText.toggled.connect(self.__typeSelectButtonToggled) 48 self.rMultiLineText.toggled.connect(self.__typeSelectButtonToggled)
45 self.rInteger.toggled.connect(self.__typeSelectButtonToggled) 49 self.rInteger.toggled.connect(self.__typeSelectButtonToggled)
46 self.rDouble.toggled.connect(self.__typeSelectButtonToggled) 50 self.rDouble.toggled.connect(self.__typeSelectButtonToggled)
47 self.rItem.toggled.connect(self.__typeSelectButtonToggled) 51 self.rItem.toggled.connect(self.__typeSelectButtonToggled)
48 52
49 self.bTest = self.buttonBox.addButton( 53 self.bTest = self.buttonBox.addButton(
50 self.tr("Test"), QDialogButtonBox.ButtonRole.ActionRole) 54 self.tr("Test"), QDialogButtonBox.ButtonRole.ActionRole
51 55 )
56
52 # simulate a dialog type selection 57 # simulate a dialog type selection
53 self.__typeSelectButtonToggled(True) 58 self.__typeSelectButtonToggled(True)
54 59
55 msh = self.minimumSizeHint() 60 msh = self.minimumSizeHint()
56 self.resize(max(self.width(), msh.width()), msh.height()) 61 self.resize(max(self.width(), msh.width()), msh.height())
57 62
58 @pyqtSlot(bool) 63 @pyqtSlot(bool)
59 def __typeSelectButtonToggled(self, checked): 64 def __typeSelectButtonToggled(self, checked):
60 """ 65 """
61 Private slot to modify the dialog according to the selected type. 66 Private slot to modify the dialog according to the selected type.
62 67
63 Note: This is a multiplexed slot. Therefore it just reacts upon a 68 Note: This is a multiplexed slot. Therefore it just reacts upon a
64 positive check state (i.e. checked == True). 69 positive check state (i.e. checked == True).
65 70
66 @param checked flag indicating the checked state 71 @param checked flag indicating the checked state
67 @type bool 72 @type bool
68 """ 73 """
69 self.bTest.setEnabled(True) 74 self.bTest.setEnabled(True)
70 if checked: 75 if checked:
77 elif self.rDouble.isChecked(): 82 elif self.rDouble.isChecked():
78 self.specificsStack.setCurrentWidget(self.doublePage) 83 self.specificsStack.setCurrentWidget(self.doublePage)
79 elif self.rItem.isChecked(): 84 elif self.rItem.isChecked():
80 self.specificsStack.setCurrentWidget(self.itemPage) 85 self.specificsStack.setCurrentWidget(self.itemPage)
81 self.bTest.setEnabled(False) 86 self.bTest.setEnabled(False)
82 87
83 def on_buttonBox_clicked(self, button): 88 def on_buttonBox_clicked(self, button):
84 """ 89 """
85 Private slot called by a button of the button box clicked. 90 Private slot called by a button of the button box clicked.
86 91
87 @param button button that was clicked (QAbstractButton) 92 @param button button that was clicked (QAbstractButton)
88 """ 93 """
89 if button == self.bTest: 94 if button == self.bTest:
90 self.on_bTest_clicked() 95 self.on_bTest_clicked()
91 96
92 @pyqtSlot() 97 @pyqtSlot()
93 def on_bTest_clicked(self): 98 def on_bTest_clicked(self):
94 """ 99 """
95 Private method to test the selected options. 100 Private method to test the selected options.
96 """ 101 """
104 QInputDialog.getText( 109 QInputDialog.getText(
105 None, 110 None,
106 self.eCaption.text(), 111 self.eCaption.text(),
107 self.eLabel.text(), 112 self.eLabel.text(),
108 echomode, 113 echomode,
109 self.eTextDefault.text()) 114 self.eTextDefault.text(),
115 )
110 elif self.rMultiLineText.isChecked(): 116 elif self.rMultiLineText.isChecked():
111 QInputDialog.getMultiLineText( 117 QInputDialog.getMultiLineText(
112 None, 118 None,
113 self.eCaption.text(), 119 self.eCaption.text(),
114 self.eLabel.text(), 120 self.eLabel.text(),
115 self.eMultiTextDefault.toPlainText()) 121 self.eMultiTextDefault.toPlainText(),
122 )
116 elif self.rInteger.isChecked(): 123 elif self.rInteger.isChecked():
117 QInputDialog.getInt( 124 QInputDialog.getInt(
118 None, 125 None,
119 self.eCaption.text(), 126 self.eCaption.text(),
120 self.eLabel.text(), 127 self.eLabel.text(),
121 self.sIntDefault.value(), 128 self.sIntDefault.value(),
122 self.sIntFrom.value(), 129 self.sIntFrom.value(),
123 self.sIntTo.value(), 130 self.sIntTo.value(),
124 self.sIntStep.value()) 131 self.sIntStep.value(),
132 )
125 elif self.rDouble.isChecked(): 133 elif self.rDouble.isChecked():
126 try: 134 try:
127 doubleDefault = float(self.eDoubleDefault.text()) 135 doubleDefault = float(self.eDoubleDefault.text())
128 except ValueError: 136 except ValueError:
129 doubleDefault = 0 137 doubleDefault = 0
140 self.eCaption.text(), 148 self.eCaption.text(),
141 self.eLabel.text(), 149 self.eLabel.text(),
142 doubleDefault, 150 doubleDefault,
143 doubleFrom, 151 doubleFrom,
144 doubleTo, 152 doubleTo,
145 self.sDoubleDecimals.value()) 153 self.sDoubleDecimals.value(),
146 154 )
155
147 def getCode(self, indLevel, indString): 156 def getCode(self, indLevel, indString):
148 """ 157 """
149 Public method to get the source code for Qt6. 158 Public method to get the source code for Qt6.
150 159
151 @param indLevel indentation level (int) 160 @param indLevel indentation level (int)
152 @param indString string used for indentation (space or tab) (string) 161 @param indString string used for indentation (space or tab) (string)
153 @return generated code (string) 162 @return generated code (string)
154 """ 163 """
155 # calculate our indentation level and the indentation string 164 # calculate our indentation level and the indentation string
156 il = indLevel + 1 165 il = indLevel + 1
157 istring = il * indString 166 istring = il * indString
158 estring = os.linesep + indLevel * indString 167 estring = os.linesep + indLevel * indString
159 168
160 # now generate the code 169 # now generate the code
161 if self.parentSelf.isChecked(): 170 if self.parentSelf.isChecked():
162 parent = "self" 171 parent = "self"
163 elif self.parentNone.isChecked(): 172 elif self.parentNone.isChecked():
164 parent = "None" 173 parent = "None"
165 elif self.parentOther.isChecked(): 174 elif self.parentOther.isChecked():
166 parent = self.parentEdit.text() 175 parent = self.parentEdit.text()
167 if parent == "": 176 if parent == "":
168 parent = "None" 177 parent = "None"
169 178
170 resvar = self.eResultVar.text() 179 resvar = self.eResultVar.text()
171 if not resvar: 180 if not resvar:
172 resvar = "result" 181 resvar = "result"
173 code = '{0}, ok = QInputDialog.'.format(resvar) 182 code = "{0}, ok = QInputDialog.".format(resvar)
174 if self.rText.isChecked(): 183 if self.rText.isChecked():
175 code += 'getText({0}{1}'.format(os.linesep, istring) 184 code += "getText({0}{1}".format(os.linesep, istring)
176 code += '{0},{1}{2}'.format(parent, os.linesep, istring) 185 code += "{0},{1}{2}".format(parent, os.linesep, istring)
177 code += 'self.tr("{0}"),{1}{2}'.format( 186 code += 'self.tr("{0}"),{1}{2}'.format(
178 self.eCaption.text(), os.linesep, istring) 187 self.eCaption.text(), os.linesep, istring
179 code += 'self.tr("{0}"),{1}{2}'.format( 188 )
180 self.eLabel.text(), os.linesep, istring) 189 code += 'self.tr("{0}"),{1}{2}'.format(
190 self.eLabel.text(), os.linesep, istring
191 )
181 if self.rEchoNormal.isChecked(): 192 if self.rEchoNormal.isChecked():
182 code += 'QLineEdit.EchoMode.Normal' 193 code += "QLineEdit.EchoMode.Normal"
183 elif self.rEchoNoEcho.isChecked(): 194 elif self.rEchoNoEcho.isChecked():
184 code += 'QLineEdit.EchoMode.NoEcho' 195 code += "QLineEdit.EchoMode.NoEcho"
185 else: 196 else:
186 code += 'QLineEdit.EchoMode.Password' 197 code += "QLineEdit.EchoMode.Password"
187 if self.eTextDefault.text(): 198 if self.eTextDefault.text():
188 if self.cTranslateTextDefault.isChecked(): 199 if self.cTranslateTextDefault.isChecked():
189 code += ',{0}{1}self.tr("{2}")'.format( 200 code += ',{0}{1}self.tr("{2}")'.format(
190 os.linesep, istring, self.eTextDefault.text()) 201 os.linesep, istring, self.eTextDefault.text()
202 )
191 else: 203 else:
192 code += ',{0}{1}"{2}"'.format( 204 code += ',{0}{1}"{2}"'.format(
193 os.linesep, istring, self.eTextDefault.text()) 205 os.linesep, istring, self.eTextDefault.text()
194 code += '{0}){0}'.format(estring) 206 )
207 code += "{0}){0}".format(estring)
195 elif self.rMultiLineText.isChecked(): 208 elif self.rMultiLineText.isChecked():
196 code += 'getMultiLineText({0}{1}'.format(os.linesep, istring) 209 code += "getMultiLineText({0}{1}".format(os.linesep, istring)
197 code += '{0},{1}{2}'.format(parent, os.linesep, istring) 210 code += "{0},{1}{2}".format(parent, os.linesep, istring)
198 code += 'self.tr("{0}"),{1}{2}'.format( 211 code += 'self.tr("{0}"),{1}{2}'.format(
199 self.eCaption.text(), os.linesep, istring) 212 self.eCaption.text(), os.linesep, istring
213 )
200 code += 'self.tr("{0}")'.format(self.eLabel.text()) 214 code += 'self.tr("{0}")'.format(self.eLabel.text())
201 if self.eMultiTextDefault.toPlainText(): 215 if self.eMultiTextDefault.toPlainText():
202 defTxt = "\\n".join( 216 defTxt = "\\n".join(self.eMultiTextDefault.toPlainText().splitlines())
203 self.eMultiTextDefault.toPlainText().splitlines()
204 )
205 if self.cTranslateMultiTextDefault.isChecked(): 217 if self.cTranslateMultiTextDefault.isChecked():
206 code += ',{0}{1}self.tr("{2}")'.format( 218 code += ',{0}{1}self.tr("{2}")'.format(os.linesep, istring, defTxt)
207 os.linesep, istring,
208 defTxt)
209 else: 219 else:
210 code += ',{0}{1}"{2}"'.format( 220 code += ',{0}{1}"{2}"'.format(os.linesep, istring, defTxt)
211 os.linesep, istring, 221 code += "{0}){0}".format(estring)
212 defTxt)
213 code += '{0}){0}'.format(estring)
214 elif self.rInteger.isChecked(): 222 elif self.rInteger.isChecked():
215 code += 'getInt({0}{1}'.format(os.linesep, istring) 223 code += "getInt({0}{1}".format(os.linesep, istring)
216 code += '{0},{1}{2}'.format(parent, os.linesep, istring) 224 code += "{0},{1}{2}".format(parent, os.linesep, istring)
217 code += 'self.tr("{0}"),{1}{2}'.format( 225 code += 'self.tr("{0}"),{1}{2}'.format(
218 self.eCaption.text(), os.linesep, istring) 226 self.eCaption.text(), os.linesep, istring
219 code += 'self.tr("{0}"),{1}{2}'.format( 227 )
220 self.eLabel.text(), os.linesep, istring) 228 code += 'self.tr("{0}"),{1}{2}'.format(
221 code += '{0:d}, {1:d}, {2:d}, {3:d}'.format( 229 self.eLabel.text(), os.linesep, istring
222 self.sIntDefault.value(), self.sIntFrom.value(), 230 )
223 self.sIntTo.value(), self.sIntStep.value()) 231 code += "{0:d}, {1:d}, {2:d}, {3:d}".format(
224 code += '{0}){0}'.format(estring) 232 self.sIntDefault.value(),
233 self.sIntFrom.value(),
234 self.sIntTo.value(),
235 self.sIntStep.value(),
236 )
237 code += "{0}){0}".format(estring)
225 elif self.rDouble.isChecked(): 238 elif self.rDouble.isChecked():
226 try: 239 try:
227 doubleDefault = float(self.eDoubleDefault.text()) 240 doubleDefault = float(self.eDoubleDefault.text())
228 except ValueError: 241 except ValueError:
229 doubleDefault = 0 242 doubleDefault = 0
233 doubleFrom = -2147483647 246 doubleFrom = -2147483647
234 try: 247 try:
235 doubleTo = float(self.eDoubleTo.text()) 248 doubleTo = float(self.eDoubleTo.text())
236 except ValueError: 249 except ValueError:
237 doubleTo = 2147483647 250 doubleTo = 2147483647
238 code += 'getDouble({0}{1}'.format(os.linesep, istring) 251 code += "getDouble({0}{1}".format(os.linesep, istring)
239 code += '{0},{1}{2}'.format(parent, os.linesep, istring) 252 code += "{0},{1}{2}".format(parent, os.linesep, istring)
240 code += 'self.tr("{0}"),{1}{2}'.format( 253 code += 'self.tr("{0}"),{1}{2}'.format(
241 self.eCaption.text(), os.linesep, istring) 254 self.eCaption.text(), os.linesep, istring
242 code += 'self.tr("{0}"),{1}{2}'.format( 255 )
243 self.eLabel.text(), os.linesep, istring) 256 code += 'self.tr("{0}"),{1}{2}'.format(
244 code += '{0}, {1}, {2}, {3:d}'.format( 257 self.eLabel.text(), os.linesep, istring
245 doubleDefault, doubleFrom, doubleTo, 258 )
246 self.sDoubleDecimals.value()) 259 code += "{0}, {1}, {2}, {3:d}".format(
247 code += '{0}){0}'.format(estring) 260 doubleDefault, doubleFrom, doubleTo, self.sDoubleDecimals.value()
261 )
262 code += "{0}){0}".format(estring)
248 elif self.rItem.isChecked(): 263 elif self.rItem.isChecked():
249 code += 'getItem({0}{1}'.format(os.linesep, istring) 264 code += "getItem({0}{1}".format(os.linesep, istring)
250 code += '{0},{1}{2}'.format(parent, os.linesep, istring) 265 code += "{0},{1}{2}".format(parent, os.linesep, istring)
251 code += 'self.tr("{0}"),{1}{2}'.format( 266 code += 'self.tr("{0}"),{1}{2}'.format(
252 self.eCaption.text(), os.linesep, istring) 267 self.eCaption.text(), os.linesep, istring
253 code += 'self.tr("{0}"),{1}{2}'.format( 268 )
254 self.eLabel.text(), os.linesep, istring) 269 code += 'self.tr("{0}"),{1}{2}'.format(
255 code += '{0},{1}{2}'.format( 270 self.eLabel.text(), os.linesep, istring
256 self.eVariable.text(), os.linesep, istring) 271 )
257 code += '{0:d}, {1}'.format( 272 code += "{0},{1}{2}".format(self.eVariable.text(), os.linesep, istring)
258 self.sCurrentItem.value(), self.cEditable.isChecked()) 273 code += "{0:d}, {1}".format(
259 code += '{0}){0}'.format(estring) 274 self.sCurrentItem.value(), self.cEditable.isChecked()
260 275 )
276 code += "{0}){0}".format(estring)
277
261 return code 278 return code

eric ide

mercurial