ProjectPyramid/PyramidRoutesDialog.py

branch
eric7
changeset 159
d4e7f5a389e6
parent 156
62170c2682a3
child 160
41b23683d5a1
equal deleted inserted replaced
158:24582cac737e 159:d4e7f5a389e6
8 """ 8 """
9 9
10 import os 10 import os
11 11
12 from PyQt6.QtCore import pyqtSlot, Qt, QProcess, QTimer, QCoreApplication 12 from PyQt6.QtCore import pyqtSlot, Qt, QProcess, QTimer, QCoreApplication
13 from PyQt6.QtWidgets import ( 13 from PyQt6.QtWidgets import QDialog, QDialogButtonBox, QLineEdit, QTreeWidgetItem
14 QDialog, QDialogButtonBox, QLineEdit, QTreeWidgetItem
15 )
16 14
17 from EricWidgets import EricMessageBox 15 from EricWidgets import EricMessageBox
18 16
19 from .Ui_PyramidRoutesDialog import Ui_PyramidRoutesDialog 17 from .Ui_PyramidRoutesDialog import Ui_PyramidRoutesDialog
20 18
24 22
25 class PyramidRoutesDialog(QDialog, Ui_PyramidRoutesDialog): 23 class PyramidRoutesDialog(QDialog, Ui_PyramidRoutesDialog):
26 """ 24 """
27 Class implementing a dialog showing the available routes. 25 Class implementing a dialog showing the available routes.
28 """ 26 """
27
29 def __init__(self, project, parent=None): 28 def __init__(self, project, parent=None):
30 """ 29 """
31 Constructor 30 Constructor
32 31
33 @param project reference to the project object 32 @param project reference to the project object
34 @type Project 33 @type Project
35 @param parent reference to the parent widget 34 @param parent reference to the parent widget
36 @type QWidget 35 @type QWidget
37 """ 36 """
38 super().__init__(parent) 37 super().__init__(parent)
39 self.setupUi(self) 38 self.setupUi(self)
40 39
41 self.buttonBox.button( 40 self.buttonBox.button(QDialogButtonBox.StandardButton.Close).setEnabled(False)
42 QDialogButtonBox.StandardButton.Close).setEnabled(False) 41 self.buttonBox.button(QDialogButtonBox.StandardButton.Cancel).setDefault(True)
43 self.buttonBox.button( 42
44 QDialogButtonBox.StandardButton.Cancel).setDefault(True)
45
46 self.__project = project 43 self.__project = project
47 self.proc = None 44 self.proc = None
48 self.buffer = "" 45 self.buffer = ""
49 46
50 self.show() 47 self.show()
51 QCoreApplication.processEvents() 48 QCoreApplication.processEvents()
52 49
53 def finish(self): 50 def finish(self):
54 """ 51 """
55 Public slot called when the process finished or the user pressed the 52 Public slot called when the process finished or the user pressed the
56 button. 53 button.
57 """ 54 """
58 if ( 55 if (
59 self.proc is not None and 56 self.proc is not None
60 self.proc.state() != QProcess.ProcessState.NotRunning 57 and self.proc.state() != QProcess.ProcessState.NotRunning
61 ): 58 ):
62 self.proc.terminate() 59 self.proc.terminate()
63 QTimer.singleShot(2000, self.proc.kill) 60 QTimer.singleShot(2000, self.proc.kill)
64 self.proc.waitForFinished(3000) 61 self.proc.waitForFinished(3000)
65 62
66 self.inputGroup.setEnabled(False) 63 self.inputGroup.setEnabled(False)
67 self.inputGroup.hide() 64 self.inputGroup.hide()
68 65
69 self.proc = None 66 self.proc = None
70 67
71 self.__processBuffer() 68 self.__processBuffer()
72 69
73 self.buttonBox.button( 70 self.buttonBox.button(QDialogButtonBox.StandardButton.Close).setEnabled(True)
74 QDialogButtonBox.StandardButton.Close).setEnabled(True) 71 self.buttonBox.button(QDialogButtonBox.StandardButton.Cancel).setEnabled(False)
75 self.buttonBox.button( 72 self.buttonBox.button(QDialogButtonBox.StandardButton.Close).setDefault(True)
76 QDialogButtonBox.StandardButton.Cancel).setEnabled(False) 73 self.buttonBox.button(QDialogButtonBox.StandardButton.Close).setFocus(
77 self.buttonBox.button( 74 Qt.FocusReason.OtherFocusReason
78 QDialogButtonBox.StandardButton.Close).setDefault(True) 75 )
79 self.buttonBox.button( 76
80 QDialogButtonBox.StandardButton.Close).setFocus(
81 Qt.FocusReason.OtherFocusReason)
82
83 def on_buttonBox_clicked(self, button): 77 def on_buttonBox_clicked(self, button):
84 """ 78 """
85 Private slot called by a button of the button box clicked. 79 Private slot called by a button of the button box clicked.
86 80
87 @param button button that was clicked (QAbstractButton) 81 @param button button that was clicked (QAbstractButton)
88 """ 82 """
89 if button == self.buttonBox.button( 83 if button == self.buttonBox.button(QDialogButtonBox.StandardButton.Close):
90 QDialogButtonBox.StandardButton.Close
91 ):
92 self.close() 84 self.close()
93 elif button == self.buttonBox.button( 85 elif button == self.buttonBox.button(QDialogButtonBox.StandardButton.Cancel):
94 QDialogButtonBox.StandardButton.Cancel
95 ):
96 self.finish() 86 self.finish()
97 87
98 def __procFinished(self, exitCode, exitStatus): 88 def __procFinished(self, exitCode, exitStatus):
99 """ 89 """
100 Private slot connected to the finished signal. 90 Private slot connected to the finished signal.
101 91
102 @param exitCode exit code of the process 92 @param exitCode exit code of the process
103 @type int 93 @type int
104 @param exitStatus exit status of the process 94 @param exitStatus exit status of the process
105 @type QProcess.ExitStatus 95 @type QProcess.ExitStatus
106 """ 96 """
107 self.normal = ( 97 self.normal = exitStatus == QProcess.ExitStatus.NormalExit and exitCode == 0
108 exitStatus == QProcess.ExitStatus.NormalExit and
109 exitCode == 0
110 )
111 self.finish() 98 self.finish()
112 99
113 def __processBuffer(self): 100 def __processBuffer(self):
114 """ 101 """
115 Private slot to process the output buffer of the proutes command. 102 Private slot to process the output buffer of the proutes command.
116 """ 103 """
117 self.routes.clear() 104 self.routes.clear()
118 105
119 if not self.buffer: 106 if not self.buffer:
120 QTreeWidgetItem(self.routes, [self.tr("No routes found.")]) 107 QTreeWidgetItem(self.routes, [self.tr("No routes found.")])
121 self.routes.setHeaderHidden(True) 108 self.routes.setHeaderHidden(True)
122 else: 109 else:
123 lines = self.buffer.splitlines() 110 lines = self.buffer.splitlines()
139 parts = line.split(None, splitCount) 126 parts = line.split(None, splitCount)
140 QTreeWidgetItem(self.routes, parts) 127 QTreeWidgetItem(self.routes, parts)
141 row += 1 128 row += 1
142 for column in range(len(headers)): 129 for column in range(len(headers)):
143 self.routes.resizeColumnToContents(column) 130 self.routes.resizeColumnToContents(column)
144 131
145 def start(self, projectPath): 132 def start(self, projectPath):
146 """ 133 """
147 Public slot used to start the process. 134 Public slot used to start the process.
148 135
149 @param projectPath path to the Pyramid project 136 @param projectPath path to the Pyramid project
150 @type str 137 @type str
151 @return flag indicating a successful start of the process 138 @return flag indicating a successful start of the process
152 @rtype bool 139 @rtype bool
153 """ 140 """
154 QTreeWidgetItem(self.routes, [self.tr("Getting routes...")]) 141 QTreeWidgetItem(self.routes, [self.tr("Getting routes...")])
155 self.routes.setHeaderHidden(True) 142 self.routes.setHeaderHidden(True)
156 143
157 self.errorGroup.hide() 144 self.errorGroup.hide()
158 self.normal = False 145 self.normal = False
159 self.intercept = False 146 self.intercept = False
160 147
161 self.buttonBox.button( 148 self.buttonBox.button(QDialogButtonBox.StandardButton.Close).setEnabled(False)
162 QDialogButtonBox.StandardButton.Close).setEnabled(False) 149 self.buttonBox.button(QDialogButtonBox.StandardButton.Cancel).setEnabled(True)
163 self.buttonBox.button( 150 self.buttonBox.button(QDialogButtonBox.StandardButton.Cancel).setDefault(True)
164 QDialogButtonBox.StandardButton.Cancel).setEnabled(True) 151 self.buttonBox.button(QDialogButtonBox.StandardButton.Cancel).setFocus(
165 self.buttonBox.button( 152 Qt.FocusReason.OtherFocusReason
166 QDialogButtonBox.StandardButton.Cancel).setDefault(True) 153 )
167 self.buttonBox.button( 154
168 QDialogButtonBox.StandardButton.Cancel).setFocus(
169 Qt.FocusReason.OtherFocusReason)
170
171 self.proc = QProcess() 155 self.proc = QProcess()
172 156
173 self.proc.finished.connect(self.__procFinished) 157 self.proc.finished.connect(self.__procFinished)
174 self.proc.readyReadStandardOutput.connect(self.__readStdout) 158 self.proc.readyReadStandardOutput.connect(self.__readStdout)
175 self.proc.readyReadStandardError.connect(self.__readStderr) 159 self.proc.readyReadStandardError.connect(self.__readStderr)
176 160
177 cmd = self.__project.getPyramidCommand( 161 cmd = self.__project.getPyramidCommand(
178 "proutes", 162 "proutes", virtualEnv=self.__project.getProjectVirtualEnvironment()
179 virtualEnv=self.__project.getProjectVirtualEnvironment()
180 ) 163 )
181 args = [] 164 args = []
182 args.append("development.ini") 165 args.append("development.ini")
183 166
184 if projectPath: 167 if projectPath:
188 if not procStarted: 171 if not procStarted:
189 self.buttonBox.setFocus() 172 self.buttonBox.setFocus()
190 self.inputGroup.setEnabled(False) 173 self.inputGroup.setEnabled(False)
191 EricMessageBox.critical( 174 EricMessageBox.critical(
192 self, 175 self,
193 self.tr('Process Generation Error'), 176 self.tr("Process Generation Error"),
194 self.tr( 177 self.tr(
195 'The process {0} could not be started. ' 178 "The process {0} could not be started. "
196 'Ensure, that it is in the search path.' 179 "Ensure, that it is in the search path."
197 ).format(cmd)) 180 ).format(cmd),
181 )
198 else: 182 else:
199 self.inputGroup.setEnabled(True) 183 self.inputGroup.setEnabled(True)
200 self.inputGroup.show() 184 self.inputGroup.show()
201 return procStarted 185 return procStarted
202 186
203 def __readStdout(self): 187 def __readStdout(self):
204 """ 188 """
205 Private slot to handle the readyReadStandardOutput signal. 189 Private slot to handle the readyReadStandardOutput signal.
206 190
207 It reads the output of the process and appends it to a buffer for 191 It reads the output of the process and appends it to a buffer for
208 delayed processing. 192 delayed processing.
209 """ 193 """
210 if self.proc is not None: 194 if self.proc is not None:
211 out = str(self.proc.readAllStandardOutput(), 195 out = str(
212 Preferences.getSystem("IOEncoding"), 196 self.proc.readAllStandardOutput(),
213 'replace') 197 Preferences.getSystem("IOEncoding"),
198 "replace",
199 )
214 self.buffer += out 200 self.buffer += out
215 201
216 def __readStderr(self): 202 def __readStderr(self):
217 """ 203 """
218 Private slot to handle the readyReadStandardError signal. 204 Private slot to handle the readyReadStandardError signal.
219 205
220 It reads the error output of the process and inserts it into the 206 It reads the error output of the process and inserts it into the
221 error pane. 207 error pane.
222 """ 208 """
223 if self.proc is not None: 209 if self.proc is not None:
224 err = str(self.proc.readAllStandardError(), 210 err = str(
225 Preferences.getSystem("IOEncoding"), 211 self.proc.readAllStandardError(),
226 'replace') 212 Preferences.getSystem("IOEncoding"),
213 "replace",
214 )
227 self.errorGroup.show() 215 self.errorGroup.show()
228 self.errors.insertPlainText(err) 216 self.errors.insertPlainText(err)
229 self.errors.ensureCursorVisible() 217 self.errors.ensureCursorVisible()
230 218
231 QCoreApplication.processEvents() 219 QCoreApplication.processEvents()
232 220
233 def on_passwordCheckBox_toggled(self, isOn): 221 def on_passwordCheckBox_toggled(self, isOn):
234 """ 222 """
235 Private slot to handle the password checkbox toggled. 223 Private slot to handle the password checkbox toggled.
236 224
237 @param isOn flag indicating the status of the check box 225 @param isOn flag indicating the status of the check box
238 @type bool 226 @type bool
239 """ 227 """
240 if isOn: 228 if isOn:
241 self.input.setEchoMode(QLineEdit.EchoMode.Password) 229 self.input.setEchoMode(QLineEdit.EchoMode.Password)
242 else: 230 else:
243 self.input.setEchoMode(QLineEdit.EchoMode.Normal) 231 self.input.setEchoMode(QLineEdit.EchoMode.Normal)
244 232
245 @pyqtSlot() 233 @pyqtSlot()
246 def on_sendButton_clicked(self): 234 def on_sendButton_clicked(self):
247 """ 235 """
248 Private slot to send the input to the subversion process. 236 Private slot to send the input to the subversion process.
249 """ 237 """
250 inputTxt = self.input.text() 238 inputTxt = self.input.text()
251 inputTxt += os.linesep 239 inputTxt += os.linesep
252 240
253 if self.passwordCheckBox.isChecked(): 241 if self.passwordCheckBox.isChecked():
254 self.errors.insertPlainText(os.linesep) 242 self.errors.insertPlainText(os.linesep)
255 self.errors.ensureCursorVisible() 243 self.errors.ensureCursorVisible()
256 244
257 self.proc.write(strToQByteArray(inputTxt)) 245 self.proc.write(strToQByteArray(inputTxt))
258 246
259 self.passwordCheckBox.setChecked(False) 247 self.passwordCheckBox.setChecked(False)
260 self.input.clear() 248 self.input.clear()
261 249
262 def on_input_returnPressed(self): 250 def on_input_returnPressed(self):
263 """ 251 """
264 Private slot to handle the press of the return key in the input field. 252 Private slot to handle the press of the return key in the input field.
265 """ 253 """
266 self.intercept = True 254 self.intercept = True
267 self.on_sendButton_clicked() 255 self.on_sendButton_clicked()
268 256
269 def keyPressEvent(self, evt): 257 def keyPressEvent(self, evt):
270 """ 258 """
271 Protected slot to handle a key press event. 259 Protected slot to handle a key press event.
272 260
273 @param evt the key press event 261 @param evt the key press event
274 @type QKeyEvent 262 @type QKeyEvent
275 """ 263 """
276 if self.intercept: 264 if self.intercept:
277 self.intercept = False 265 self.intercept = False

eric ide

mercurial