11 try: |
11 try: |
12 str = unicode # __IGNORE_WARNING__ |
12 str = unicode # __IGNORE_WARNING__ |
13 except NameError: |
13 except NameError: |
14 pass |
14 pass |
15 |
15 |
|
16 import os |
|
17 |
16 from PyQt5.QtCore import pyqtSlot, QProcess, QTimer, QFileInfo |
18 from PyQt5.QtCore import pyqtSlot, QProcess, QTimer, QFileInfo |
17 from PyQt5.QtWidgets import QDialog, QDialogButtonBox, QAbstractButton, \ |
19 from PyQt5.QtWidgets import QDialog, QDialogButtonBox, QAbstractButton, \ |
18 QTextEdit |
20 QTextEdit, QLineEdit |
19 |
21 |
20 from E5Gui import E5MessageBox, E5FileDialog |
22 from E5Gui import E5MessageBox, E5FileDialog |
21 |
23 |
22 from .Ui_DjangoDialog import Ui_DjangoDialog |
24 from .Ui_DjangoDialog import Ui_DjangoDialog |
23 |
25 |
34 shows the output of the process. The dialog is modal, |
36 shows the output of the process. The dialog is modal, |
35 which causes a synchronized execution of the process. |
37 which causes a synchronized execution of the process. |
36 """ |
38 """ |
37 def __init__(self, text, fixed=False, linewrap=True, |
39 def __init__(self, text, fixed=False, linewrap=True, |
38 msgSuccess=None, msgError=None, |
40 msgSuccess=None, msgError=None, |
39 saveFilters=None, |
41 saveFilters=None, showInput=False, |
40 parent=None): |
42 parent=None): |
41 """ |
43 """ |
42 Constructor |
44 Constructor |
43 |
45 |
44 @param text text to be shown by the label (string) |
46 @param text text to be shown by the label (string) |
47 @keyparam msgSuccess optional string to show upon successful execution |
49 @keyparam msgSuccess optional string to show upon successful execution |
48 (string) |
50 (string) |
49 @keyparam msgError optional string to show upon unsuccessful execution |
51 @keyparam msgError optional string to show upon unsuccessful execution |
50 (string) |
52 (string) |
51 @keyparam saveFilters filename filter string (string) |
53 @keyparam saveFilters filename filter string (string) |
|
54 @keyparam showInput flag indicating to show the input widgets (bool) |
52 @keyparam parent parent widget (QWidget) |
55 @keyparam parent parent widget (QWidget) |
53 """ |
56 """ |
54 super(DjangoDialog, self).__init__(parent) |
57 super(DjangoDialog, self).__init__(parent) |
55 self.setupUi(self) |
58 self.setupUi(self) |
56 |
59 |
67 self.workingDir = None |
70 self.workingDir = None |
68 self.mergedOutput = False |
71 self.mergedOutput = False |
69 self.msgSuccess = msgSuccess |
72 self.msgSuccess = msgSuccess |
70 self.msgError = msgError |
73 self.msgError = msgError |
71 self.fileFilters = saveFilters |
74 self.fileFilters = saveFilters |
|
75 self.showInput = showInput |
72 |
76 |
73 self.outputGroup.setTitle(text) |
77 self.outputGroup.setTitle(text) |
74 |
78 |
75 if fixed: |
79 if fixed: |
76 if isWindowsPlatform(): |
80 if isWindowsPlatform(): |
108 |
112 |
109 self.buttonBox.button(QDialogButtonBox.Close).setEnabled(True) |
113 self.buttonBox.button(QDialogButtonBox.Close).setEnabled(True) |
110 self.buttonBox.button(QDialogButtonBox.Cancel).setEnabled(False) |
114 self.buttonBox.button(QDialogButtonBox.Cancel).setEnabled(False) |
111 self.buttonBox.button(QDialogButtonBox.Close).setDefault(True) |
115 self.buttonBox.button(QDialogButtonBox.Close).setDefault(True) |
112 self.buttonBox.button(QDialogButtonBox.Save).setEnabled(True) |
116 self.buttonBox.button(QDialogButtonBox.Save).setEnabled(True) |
|
117 |
|
118 self.inputGroup.setEnabled(False) |
|
119 self.inputGroup.hide() |
113 |
120 |
114 self.proc = None |
121 self.proc = None |
115 |
122 |
116 if self.argsLists: |
123 if self.argsLists: |
117 args = self.argsLists[0][:] |
124 args = self.argsLists[0][:] |
175 del args[0] |
182 del args[0] |
176 self.proc.start(prog, args) |
183 self.proc.start(prog, args) |
177 procStarted = self.proc.waitForStarted() |
184 procStarted = self.proc.waitForStarted() |
178 if not procStarted: |
185 if not procStarted: |
179 self.buttonBox.setFocus() |
186 self.buttonBox.setFocus() |
|
187 self.inputGroup.setEnabled(False) |
180 E5MessageBox.critical( |
188 E5MessageBox.critical( |
181 self, |
189 self, |
182 self.tr('Process Generation Error'), |
190 self.tr('Process Generation Error'), |
183 self.tr( |
191 self.tr( |
184 'The process {0} could not be started. ' |
192 'The process {0} could not be started. ' |
185 'Ensure, that it is in the search path.' |
193 'Ensure, that it is in the search path.' |
186 ).format(prog)) |
194 ).format(prog)) |
|
195 else: |
|
196 if self.showInput: |
|
197 self.inputGroup.setEnabled(True) |
|
198 self.inputGroup.show() |
|
199 else: |
|
200 self.inputGroup.setEnabled(False) |
|
201 self.inputGroup.hide() |
|
202 |
187 return procStarted |
203 return procStarted |
188 |
204 |
189 def startBatchProcesses(self, argsLists, workingDir=None, |
205 def startBatchProcesses(self, argsLists, workingDir=None, |
190 mergedOutput=False): |
206 mergedOutput=False): |
191 """ |
207 """ |
286 self, |
302 self, |
287 self.tr("Error saving data"), |
303 self.tr("Error saving data"), |
288 self.tr("""<p>The data could not be written""" |
304 self.tr("""<p>The data could not be written""" |
289 """ to <b>{0}</b></p><p>Reason: {1}</p>""") |
305 """ to <b>{0}</b></p><p>Reason: {1}</p>""") |
290 .format(fname, str(err))) |
306 .format(fname, str(err))) |
|
307 |
|
308 def on_passwordCheckBox_toggled(self, isOn): |
|
309 """ |
|
310 Private slot to handle the password checkbox toggled. |
|
311 |
|
312 @param isOn flag indicating the status of the check box (boolean) |
|
313 """ |
|
314 if isOn: |
|
315 self.input.setEchoMode(QLineEdit.Password) |
|
316 else: |
|
317 self.input.setEchoMode(QLineEdit.Normal) |
|
318 |
|
319 @pyqtSlot() |
|
320 def on_sendButton_clicked(self): |
|
321 """ |
|
322 Private slot to send the input to the manage.py process. |
|
323 """ |
|
324 inputTxt = self.input.text() |
|
325 inputTxt += os.linesep |
|
326 |
|
327 if self.passwordCheckBox.isChecked(): |
|
328 self.errors.insertPlainText(os.linesep) |
|
329 self.errors.ensureCursorVisible() |
|
330 else: |
|
331 self.errors.insertPlainText(inputTxt) |
|
332 self.errors.ensureCursorVisible() |
|
333 |
|
334 self.proc.write(inputTxt) |
|
335 |
|
336 self.input.clear() |
|
337 self.passwordCheckBox.setChecked(False) |
|
338 |
|
339 def on_input_returnPressed(self): |
|
340 """ |
|
341 Private slot to handle the press of the return key in the input field. |
|
342 """ |
|
343 self.intercept = True |
|
344 self.on_sendButton_clicked() |
|
345 |
|
346 def keyPressEvent(self, evt): |
|
347 """ |
|
348 Protected slot to handle a key press event. |
|
349 |
|
350 @param evt the key press event (QKeyEvent) |
|
351 """ |
|
352 if self.intercept: |
|
353 self.intercept = False |
|
354 evt.accept() |
|
355 return |
|
356 |
|
357 super(DjangoDialog, self).keyPressEvent(evt) |