--- a/ProjectDjango/DjangoDialog.py Sun Apr 23 17:20:47 2017 +0200 +++ b/ProjectDjango/DjangoDialog.py Thu Apr 27 19:35:14 2017 +0200 @@ -13,9 +13,11 @@ except NameError: pass +import os + from PyQt5.QtCore import pyqtSlot, QProcess, QTimer, QFileInfo from PyQt5.QtWidgets import QDialog, QDialogButtonBox, QAbstractButton, \ - QTextEdit + QTextEdit, QLineEdit from E5Gui import E5MessageBox, E5FileDialog @@ -36,7 +38,7 @@ """ def __init__(self, text, fixed=False, linewrap=True, msgSuccess=None, msgError=None, - saveFilters=None, + saveFilters=None, showInput=False, parent=None): """ Constructor @@ -49,6 +51,7 @@ @keyparam msgError optional string to show upon unsuccessful execution (string) @keyparam saveFilters filename filter string (string) + @keyparam showInput flag indicating to show the input widgets (bool) @keyparam parent parent widget (QWidget) """ super(DjangoDialog, self).__init__(parent) @@ -69,6 +72,7 @@ self.msgSuccess = msgSuccess self.msgError = msgError self.fileFilters = saveFilters + self.showInput = showInput self.outputGroup.setTitle(text) @@ -111,6 +115,9 @@ self.buttonBox.button(QDialogButtonBox.Close).setDefault(True) self.buttonBox.button(QDialogButtonBox.Save).setEnabled(True) + self.inputGroup.setEnabled(False) + self.inputGroup.hide() + self.proc = None if self.argsLists: @@ -177,6 +184,7 @@ procStarted = self.proc.waitForStarted() if not procStarted: self.buttonBox.setFocus() + self.inputGroup.setEnabled(False) E5MessageBox.critical( self, self.tr('Process Generation Error'), @@ -184,6 +192,14 @@ 'The process {0} could not be started. ' 'Ensure, that it is in the search path.' ).format(prog)) + else: + if self.showInput: + self.inputGroup.setEnabled(True) + self.inputGroup.show() + else: + self.inputGroup.setEnabled(False) + self.inputGroup.hide() + return procStarted def startBatchProcesses(self, argsLists, workingDir=None, @@ -288,3 +304,54 @@ self.tr("""<p>The data could not be written""" """ to <b>{0}</b></p><p>Reason: {1}</p>""") .format(fname, str(err))) + + def on_passwordCheckBox_toggled(self, isOn): + """ + Private slot to handle the password checkbox toggled. + + @param isOn flag indicating the status of the check box (boolean) + """ + if isOn: + self.input.setEchoMode(QLineEdit.Password) + else: + self.input.setEchoMode(QLineEdit.Normal) + + @pyqtSlot() + def on_sendButton_clicked(self): + """ + Private slot to send the input to the manage.py process. + """ + inputTxt = self.input.text() + inputTxt += os.linesep + + if self.passwordCheckBox.isChecked(): + self.errors.insertPlainText(os.linesep) + self.errors.ensureCursorVisible() + else: + self.errors.insertPlainText(inputTxt) + self.errors.ensureCursorVisible() + + self.proc.write(inputTxt) + + self.input.clear() + self.passwordCheckBox.setChecked(False) + + def on_input_returnPressed(self): + """ + Private slot to handle the press of the return key in the input field. + """ + self.intercept = True + self.on_sendButton_clicked() + + def keyPressEvent(self, evt): + """ + Protected slot to handle a key press event. + + @param evt the key press event (QKeyEvent) + """ + if self.intercept: + self.intercept = False + evt.accept() + return + + super(DjangoDialog, self).keyPressEvent(evt)