ProjectFlask/FlaskCommandDialog.py

changeset 15
3f5c05eb2d5f
parent 11
da6ef8ab8268
child 16
dd3f6bfb85f7
equal deleted inserted replaced
14:d2da14b2a233 15:3f5c05eb2d5f
33 33
34 self.__project = project 34 self.__project = project
35 35
36 self.__process = None 36 self.__process = None
37 37
38 self.successMessage = ""
39 self.errorMessage = ""
40
38 self.buttonBox.button(QDialogButtonBox.Close).setEnabled(True) 41 self.buttonBox.button(QDialogButtonBox.Close).setEnabled(True)
39 self.buttonBox.button(QDialogButtonBox.Close).setDefault(True) 42 self.buttonBox.button(QDialogButtonBox.Close).setDefault(True)
40 self.buttonBox.button(QDialogButtonBox.Cancel).setEnabled(False) 43 self.buttonBox.button(QDialogButtonBox.Cancel).setEnabled(False)
41 44
42 def startCommand(self, command, args=None): 45 def startFlaskCommand(self, command, args=None):
43 """ 46 """
44 Public method to start a flask command and show its output. 47 Public method to start a flask command and show its output.
45 48
46 @param command flask command to be run 49 @param command flask command to be run
47 @type str 50 @type str
84 else: 87 else:
85 ok = False 88 ok = False
86 89
87 return ok 90 return ok
88 91
92 def startBabelCommand(self, command, args, title, msgSuccess="",
93 msgError=""):
94 """
95 Public method to start a pybabel command and show its output.
96
97 @param command pybabel command to be run
98 @type str
99 @param args list of command line arguments for the command
100 @type list of str
101 @param title window title of the dialog
102 @type str
103 @param msgSuccess success message to be shown
104 @type str
105 @param msgError message to be shown on error
106 @type str
107 @return flag indicating a successful start
108 @rtype bool
109 """
110 self.setWindowTitle(title)
111
112 self.successMessage = msgSuccess
113 self.errorMessage = msgError
114
115 workdir, _ = self.__project.getApplication()
116 babelCommand = self.__project.getBabelCommand()
117
118 self.__process = QProcess()
119 self.__process.setWorkingDirectory(workdir)
120 self.__process.setProcessChannelMode(QProcess.MergedChannels)
121
122 self.__process.readyReadStandardOutput.connect(self.__readStdOut)
123 self.__process.finished.connect(self.__processFinished)
124
125 self.outputEdit.clear()
126
127 babelArgs = [command]
128 if args:
129 babelArgs += args
130
131 self.__process.start(babelCommand, babelArgs)
132 ok = self.__process.waitForStarted(10000)
133 if not ok:
134 E5MessageBox.critical(
135 None,
136 self.tr("Execute PyBabel Command"),
137 self.tr("""The pybabel process could not be started."""))
138 else:
139 self.buttonBox.button(QDialogButtonBox.Close).setEnabled(False)
140 self.buttonBox.button(QDialogButtonBox.Cancel).setDefault(True)
141 self.buttonBox.button(QDialogButtonBox.Cancel).setEnabled(True)
142 self.buttonBox.button(QDialogButtonBox.Cancel).setFocus(
143 Qt.OtherFocusReason)
144
145 return ok
146
89 def closeEvent(self, evt): 147 def closeEvent(self, evt):
90 """ 148 """
91 Protected method handling the close event of the dialog. 149 Protected method handling the close event of the dialog.
92 150
93 @param evt reference to the close event object 151 @param evt reference to the close event object
103 """ 161 """
104 if self.__process is not None: 162 if self.__process is not None:
105 out = str(self.__process.readAllStandardOutput(), "utf-8") 163 out = str(self.__process.readAllStandardOutput(), "utf-8")
106 self.outputEdit.insertPlainText(out) 164 self.outputEdit.insertPlainText(out)
107 165
108 @pyqtSlot() 166 def __processFinished(self, exitCode, exitStatus):
109 def __processFinished(self): 167 """
110 """ 168 Private slot connected to the finished signal.
111 Private slot handling the finishing of the server process. 169
112 """ 170 @param exitCode exit code of the process
171 @type int
172 @param exitStatus exit status of the process
173 @type QProcess.ExitStatus
174 """
175 normal = (exitStatus == QProcess.NormalExit) and (exitCode == 0)
113 self.__cancelProcess() 176 self.__cancelProcess()
114 177
115 self.buttonBox.button(QDialogButtonBox.Cancel).setEnabled(False) 178 self.buttonBox.button(QDialogButtonBox.Cancel).setEnabled(False)
116 self.buttonBox.button(QDialogButtonBox.Close).setEnabled(True) 179 self.buttonBox.button(QDialogButtonBox.Close).setEnabled(True)
117 self.buttonBox.button(QDialogButtonBox.Close).setDefault(True) 180 self.buttonBox.button(QDialogButtonBox.Close).setDefault(True)
118 self.buttonBox.button(QDialogButtonBox.Close).setFocus( 181 self.buttonBox.button(QDialogButtonBox.Close).setFocus(
119 Qt.OtherFocusReason) 182 Qt.OtherFocusReason)
183
184 if normal and self.successMessage:
185 self.outputEdit.insertPlainText(self.successMessage)
186 elif not normal and self.errorMessage:
187 self.outputEdit.insertPlainText(self.errorMessage)
120 188
121 @pyqtSlot() 189 @pyqtSlot()
122 def __cancelProcess(self): 190 def __cancelProcess(self):
123 """ 191 """
124 Private slot to terminate the current process. 192 Private slot to terminate the current process.

eric ide

mercurial