ProjectFlask/FlaskCommandDialog.py

branch
eric7
changeset 64
0ee58185b8df
parent 61
fe1e8783a95f
child 66
0d3168d0e310
equal deleted inserted replaced
63:7c05cbc8b3e5 64:0ee58185b8df
5 5
6 """ 6 """
7 Module implementing a dialog to run a flask command and show its output. 7 Module implementing a dialog to run a flask command and show its output.
8 """ 8 """
9 9
10 from PyQt5.QtCore import pyqtSlot, Qt, QProcess, QTimer 10 from PyQt6.QtCore import pyqtSlot, Qt, QProcess, QTimer
11 from PyQt5.QtWidgets import QDialog, QDialogButtonBox, QAbstractButton 11 from PyQt6.QtWidgets import QDialog, QDialogButtonBox, QAbstractButton
12 12
13 from E5Gui import E5MessageBox 13 from EricWidgets import EricMessageBox
14 14
15 from .Ui_FlaskCommandDialog import Ui_FlaskCommandDialog 15 from .Ui_FlaskCommandDialog import Ui_FlaskCommandDialog
16 16
17 17
18 class FlaskCommandDialog(QDialog, Ui_FlaskCommandDialog): 18 class FlaskCommandDialog(QDialog, Ui_FlaskCommandDialog):
45 self.__successMessage = msgSuccess 45 self.__successMessage = msgSuccess
46 self.__errorMessage = msgError 46 self.__errorMessage = msgError
47 47
48 self.__process = None 48 self.__process = None
49 49
50 self.buttonBox.button(QDialogButtonBox.Close).setEnabled(True) 50 self.buttonBox.button(
51 self.buttonBox.button(QDialogButtonBox.Close).setDefault(True) 51 QDialogButtonBox.StandardButton.Close).setEnabled(True)
52 self.buttonBox.button(QDialogButtonBox.Cancel).setEnabled(False) 52 self.buttonBox.button(
53 QDialogButtonBox.StandardButton.Close).setDefault(True)
54 self.buttonBox.button(
55 QDialogButtonBox.StandardButton.Cancel).setEnabled(False)
53 56
54 def startCommand(self, command, args=None): 57 def startCommand(self, command, args=None):
55 """ 58 """
56 Public method to start a flask command and show its output. 59 Public method to start a flask command and show its output.
57 60
68 flaskCommand = self.__project.getFlaskCommand() 71 flaskCommand = self.__project.getFlaskCommand()
69 72
70 self.__process = QProcess() 73 self.__process = QProcess()
71 self.__process.setProcessEnvironment(env) 74 self.__process.setProcessEnvironment(env)
72 self.__process.setWorkingDirectory(workdir) 75 self.__process.setWorkingDirectory(workdir)
73 self.__process.setProcessChannelMode(QProcess.MergedChannels) 76 self.__process.setProcessChannelMode(
77 QProcess.ProcessChannelMode.MergedChannels)
74 78
75 self.__process.readyReadStandardOutput.connect(self.__readStdOut) 79 self.__process.readyReadStandardOutput.connect(self.__readStdOut)
76 self.__process.finished.connect(self.__processFinished) 80 self.__process.finished.connect(self.__processFinished)
77 81
78 self.outputEdit.clear() 82 self.outputEdit.clear()
82 flaskArgs += args 86 flaskArgs += args
83 87
84 self.__process.start(flaskCommand, flaskArgs) 88 self.__process.start(flaskCommand, flaskArgs)
85 ok = self.__process.waitForStarted(10000) 89 ok = self.__process.waitForStarted(10000)
86 if not ok: 90 if not ok:
87 E5MessageBox.critical( 91 EricMessageBox.critical(
88 None, 92 None,
89 self.tr("Execute Flask Command"), 93 self.tr("Execute Flask Command"),
90 self.tr("""The Flask process could not be started.""")) 94 self.tr("""The Flask process could not be started."""))
91 else: 95 else:
92 self.buttonBox.button(QDialogButtonBox.Close).setEnabled(False) 96 self.buttonBox.button(
93 self.buttonBox.button(QDialogButtonBox.Cancel).setDefault(True) 97 QDialogButtonBox.StandardButton.Close).setEnabled(False)
94 self.buttonBox.button(QDialogButtonBox.Cancel).setEnabled(True) 98 self.buttonBox.button(
95 self.buttonBox.button(QDialogButtonBox.Cancel).setFocus( 99 QDialogButtonBox.StandardButton.Cancel).setDefault(True)
96 Qt.OtherFocusReason) 100 self.buttonBox.button(
101 QDialogButtonBox.StandardButton.Cancel).setEnabled(True)
102 self.buttonBox.button(
103 QDialogButtonBox.StandardButton.Cancel).setFocus(
104 Qt.FocusReason.OtherFocusReason)
97 else: 105 else:
98 ok = False 106 ok = False
99 107
100 return ok 108 return ok
101 109
125 @param exitCode exit code of the process 133 @param exitCode exit code of the process
126 @type int 134 @type int
127 @param exitStatus exit status of the process 135 @param exitStatus exit status of the process
128 @type QProcess.ExitStatus 136 @type QProcess.ExitStatus
129 """ 137 """
130 self.__normal = (exitStatus == QProcess.NormalExit) and (exitCode == 0) 138 self.__normal = (
139 exitStatus == QProcess.ExitStatus.NormalExit and
140 exitCode == 0
141 )
131 self.__cancelProcess() 142 self.__cancelProcess()
132 143
133 self.buttonBox.button(QDialogButtonBox.Cancel).setEnabled(False) 144 self.buttonBox.button(
134 self.buttonBox.button(QDialogButtonBox.Close).setEnabled(True) 145 QDialogButtonBox.StandardButton.Cancel).setEnabled(False)
135 self.buttonBox.button(QDialogButtonBox.Close).setDefault(True) 146 self.buttonBox.button(
136 self.buttonBox.button(QDialogButtonBox.Close).setFocus( 147 QDialogButtonBox.StandardButton.Close).setEnabled(True)
137 Qt.OtherFocusReason) 148 self.buttonBox.button(
149 QDialogButtonBox.StandardButton.Close).setDefault(True)
150 self.buttonBox.button(
151 QDialogButtonBox.StandardButton.Close).setFocus(
152 Qt.FocusReason.OtherFocusReason)
138 153
139 if self.__normal and self.__successMessage: 154 if self.__normal and self.__successMessage:
140 self.outputEdit.insertPlainText(self.__successMessage) 155 self.outputEdit.insertPlainText(self.__successMessage)
141 elif not self.__normal and self.__errorMessage: 156 elif not self.__normal and self.__errorMessage:
142 self.outputEdit.insertPlainText(self.__errorMessage) 157 self.outputEdit.insertPlainText(self.__errorMessage)
146 """ 161 """
147 Private slot to terminate the current process. 162 Private slot to terminate the current process.
148 """ 163 """
149 if ( 164 if (
150 self.__process is not None and 165 self.__process is not None and
151 self.__process.state() != QProcess.NotRunning 166 self.__process.state() != QProcess.ProcessState.NotRunning
152 ): 167 ):
153 self.__process.terminate() 168 self.__process.terminate()
154 QTimer.singleShot(2000, self.__process.kill) 169 QTimer.singleShot(2000, self.__process.kill)
155 self.__process.waitForFinished(3000) 170 self.__process.waitForFinished(3000)
156 171
162 Private slot handling presses of the button box buttons. 177 Private slot handling presses of the button box buttons.
163 178
164 @param button reference to the button been clicked 179 @param button reference to the button been clicked
165 @type QAbstractButton 180 @type QAbstractButton
166 """ 181 """
167 if button is self.buttonBox.button(QDialogButtonBox.Close): 182 if button is self.buttonBox.button(
183 QDialogButtonBox.StandardButton.Close
184 ):
168 self.close() 185 self.close()
169 elif button is self.buttonBox.button(QDialogButtonBox.Cancel): 186 elif button is self.buttonBox.button(
187 QDialogButtonBox.StandardButton.Cancel
188 ):
170 self.__cancelProcess() 189 self.__cancelProcess()
171 190
172 def normalExit(self): 191 def normalExit(self):
173 """ 192 """
174 Public method to test, if the process ended without errors. 193 Public method to test, if the process ended without errors.

eric ide

mercurial