eric7/Plugins/WizardPlugins/InputDialogWizard/InputDialogWizardDialog.py

branch
eric7
changeset 8312
800c432b34c8
parent 8218
7c09585bd960
child 8318
962bce857696
equal deleted inserted replaced
8311:4e8b98454baa 8312:800c432b34c8
1 # -*- coding: utf-8 -*-
2
3 # Copyright (c) 2003 - 2021 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 PyQt5.QtCore import pyqtSlot
13 from PyQt5.QtGui import QDoubleValidator
14 from PyQt5.QtWidgets import QLineEdit, QDialog, QInputDialog, QDialogButtonBox
15
16 from .Ui_InputDialogWizardDialog import Ui_InputDialogWizardDialog
17
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 super().__init__(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 = self.buttonBox.addButton(
44 self.tr("Test"), QDialogButtonBox.ButtonRole.ActionRole)
45
46 msh = self.minimumSizeHint()
47 self.resize(max(self.width(), msh.width()), msh.height())
48
49 @pyqtSlot(bool)
50 def on_rItem_toggled(self, checked):
51 """
52 Private slot to perform actions dependant on the item type selection.
53
54 @param checked flag indicating the checked state (boolean)
55 """
56 self.bTest.setEnabled(not checked)
57
58 def on_buttonBox_clicked(self, button):
59 """
60 Private slot called by a button of the button box clicked.
61
62 @param button button that was clicked (QAbstractButton)
63 """
64 if button == self.bTest:
65 self.on_bTest_clicked()
66
67 @pyqtSlot()
68 def on_bTest_clicked(self):
69 """
70 Private method to test the selected options.
71 """
72 if self.rText.isChecked():
73 if self.rEchoNormal.isChecked():
74 echomode = QLineEdit.EchoMode.Normal
75 elif self.rEchoNoEcho.isChecked():
76 echomode = QLineEdit.EchoMode.NoEcho
77 else:
78 echomode = QLineEdit.EchoMode.Password
79 QInputDialog.getText(
80 None,
81 self.eCaption.text(),
82 self.eLabel.text(),
83 echomode,
84 self.eTextDefault.text())
85 elif self.rInteger.isChecked():
86 QInputDialog.getInt(
87 None,
88 self.eCaption.text(),
89 self.eLabel.text(),
90 self.sIntDefault.value(),
91 self.sIntFrom.value(),
92 self.sIntTo.value(),
93 self.sIntStep.value())
94 elif self.rDouble.isChecked():
95 try:
96 doubleDefault = float(self.eDoubleDefault.text())
97 except ValueError:
98 doubleDefault = 0
99 try:
100 doubleFrom = float(self.eDoubleFrom.text())
101 except ValueError:
102 doubleFrom = -2147483647
103 try:
104 doubleTo = float(self.eDoubleTo.text())
105 except ValueError:
106 doubleTo = 2147483647
107 QInputDialog.getDouble(
108 None,
109 self.eCaption.text(),
110 self.eLabel.text(),
111 doubleDefault,
112 doubleFrom,
113 doubleTo,
114 self.sDoubleDecimals.value())
115
116 def getCode(self, indLevel, indString):
117 """
118 Public method to get the source code for Qt5.
119
120 @param indLevel indentation level (int)
121 @param indString string used for indentation (space or tab) (string)
122 @return generated code (string)
123 """
124 # calculate our indentation level and the indentation string
125 il = indLevel + 1
126 istring = il * indString
127 estring = os.linesep + indLevel * indString
128
129 # now generate the code
130 if self.parentSelf.isChecked():
131 parent = "self"
132 elif self.parentNone.isChecked():
133 parent = "None"
134 elif self.parentOther.isChecked():
135 parent = self.parentEdit.text()
136 if parent == "":
137 parent = "None"
138
139 resvar = self.eResultVar.text()
140 if not resvar:
141 resvar = "result"
142 code = '{0}, ok = QInputDialog.'.format(resvar)
143 if self.rText.isChecked():
144 code += 'getText({0}{1}'.format(os.linesep, istring)
145 code += '{0},{1}{2}'.format(parent, os.linesep, istring)
146 code += 'self.tr("{0}"),{1}{2}'.format(
147 self.eCaption.text(), os.linesep, istring)
148 code += 'self.tr("{0}"),{1}{2}'.format(
149 self.eLabel.text(), os.linesep, istring)
150 if self.rEchoNormal.isChecked():
151 code += 'QLineEdit.EchoMode.Normal'
152 elif self.rEchoNoEcho.isChecked():
153 code += 'QLineEdit.EchoMode.NoEcho'
154 else:
155 code += 'QLineEdit.EchoMode.Password'
156 if self.eTextDefault.text():
157 code += ',{0}{1}self.tr("{2}")'.format(
158 os.linesep, istring, self.eTextDefault.text())
159 code += '){0}'.format(estring)
160 elif self.rInteger.isChecked():
161 code += 'getInt({0}{1}'.format(os.linesep, istring)
162 code += '{0},{1}{2}'.format(parent, os.linesep, istring)
163 code += 'self.tr("{0}"),{1}{2}'.format(
164 self.eCaption.text(), os.linesep, istring)
165 code += 'self.tr("{0}"),{1}{2}'.format(
166 self.eLabel.text(), os.linesep, istring)
167 code += '{0:d}, {1:d}, {2:d}, {3:d}){4}'.format(
168 self.sIntDefault.value(), self.sIntFrom.value(),
169 self.sIntTo.value(), self.sIntStep.value(), estring)
170 elif self.rDouble.isChecked():
171 try:
172 doubleDefault = float(self.eDoubleDefault.text())
173 except ValueError:
174 doubleDefault = 0
175 try:
176 doubleFrom = float(self.eDoubleFrom.text())
177 except ValueError:
178 doubleFrom = -2147483647
179 try:
180 doubleTo = float(self.eDoubleTo.text())
181 except ValueError:
182 doubleTo = 2147483647
183 code += 'getDouble({0}{1}'.format(os.linesep, istring)
184 code += '{0},{1}{2}'.format(parent, os.linesep, istring)
185 code += 'self.tr("{0}"),{1}{2}'.format(
186 self.eCaption.text(), os.linesep, istring)
187 code += 'self.tr("{0}"),{1}{2}'.format(
188 self.eLabel.text(), os.linesep, istring)
189 code += '{0}, {1}, {2}, {3:d}){4}'.format(
190 doubleDefault, doubleFrom, doubleTo,
191 self.sDoubleDecimals.value(), estring)
192 elif self.rItem.isChecked():
193 code += 'getItem({0}{1}'.format(os.linesep, istring)
194 code += '{0},{1}{2}'.format(parent, os.linesep, istring)
195 code += 'self.tr("{0}"),{1}{2}'.format(
196 self.eCaption.text(), os.linesep, istring)
197 code += 'self.tr("{0}"),{1}{2}'.format(
198 self.eLabel.text(), os.linesep, istring)
199 code += '{0},{1}{2}'.format(
200 self.eVariable.text(), os.linesep, istring)
201 code += '{0:d}, {1}){2}'.format(
202 self.sCurrentItem.value(), self.cEditable.isChecked(), estring)
203
204 return code

eric ide

mercurial