ProjectFlask/FlaskCommandDialog.py

changeset 16
dd3f6bfb85f7
parent 15
3f5c05eb2d5f
child 32
80fc8deac8fe
equal deleted inserted replaced
15:3f5c05eb2d5f 16:dd3f6bfb85f7
17 17
18 class FlaskCommandDialog(QDialog, Ui_FlaskCommandDialog): 18 class FlaskCommandDialog(QDialog, Ui_FlaskCommandDialog):
19 """ 19 """
20 Class implementing a dialog to run a flask command and show its output. 20 Class implementing a dialog to run a flask command and show its output.
21 """ 21 """
22 def __init__(self, project, parent=None): 22 def __init__(self, project, title="", msgSuccess="", msgError="",
23 parent=None):
23 """ 24 """
24 Constructor 25 Constructor
25 26
26 @param project reference to the project object 27 @param project reference to the project object
27 @type Project 28 @type Project
29 @param title window title of the dialog
30 @type str
31 @param msgSuccess success message to be shown
32 @type str
33 @param msgError message to be shown on error
34 @type str
28 @param parent reference to the parent widget 35 @param parent reference to the parent widget
29 @type QWidget 36 @type QWidget
30 """ 37 """
31 super(FlaskCommandDialog, self).__init__(parent) 38 super(FlaskCommandDialog, self).__init__(parent)
32 self.setupUi(self) 39 self.setupUi(self)
33 40
41 if title:
42 self.setWindowTitle(title)
43
34 self.__project = project 44 self.__project = project
45 self.__successMessage = msgSuccess
46 self.__errorMessage = msgError
35 47
36 self.__process = None 48 self.__process = None
37
38 self.successMessage = ""
39 self.errorMessage = ""
40 49
41 self.buttonBox.button(QDialogButtonBox.Close).setEnabled(True) 50 self.buttonBox.button(QDialogButtonBox.Close).setEnabled(True)
42 self.buttonBox.button(QDialogButtonBox.Close).setDefault(True) 51 self.buttonBox.button(QDialogButtonBox.Close).setDefault(True)
43 self.buttonBox.button(QDialogButtonBox.Cancel).setEnabled(False) 52 self.buttonBox.button(QDialogButtonBox.Cancel).setEnabled(False)
44 53
45 def startFlaskCommand(self, command, args=None): 54 def startCommand(self, command, args=None):
46 """ 55 """
47 Public method to start a flask command and show its output. 56 Public method to start a flask command and show its output.
48 57
49 @param command flask command to be run 58 @param command flask command to be run
50 @type str 59 @type str
87 else: 96 else:
88 ok = False 97 ok = False
89 98
90 return ok 99 return ok
91 100
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
147 def closeEvent(self, evt): 101 def closeEvent(self, evt):
148 """ 102 """
149 Protected method handling the close event of the dialog. 103 Protected method handling the close event of the dialog.
150 104
151 @param evt reference to the close event object 105 @param evt reference to the close event object
179 self.buttonBox.button(QDialogButtonBox.Close).setEnabled(True) 133 self.buttonBox.button(QDialogButtonBox.Close).setEnabled(True)
180 self.buttonBox.button(QDialogButtonBox.Close).setDefault(True) 134 self.buttonBox.button(QDialogButtonBox.Close).setDefault(True)
181 self.buttonBox.button(QDialogButtonBox.Close).setFocus( 135 self.buttonBox.button(QDialogButtonBox.Close).setFocus(
182 Qt.OtherFocusReason) 136 Qt.OtherFocusReason)
183 137
184 if normal and self.successMessage: 138 if normal and self.__successMessage:
185 self.outputEdit.insertPlainText(self.successMessage) 139 self.outputEdit.insertPlainText(self.__successMessage)
186 elif not normal and self.errorMessage: 140 elif not normal and self.__errorMessage:
187 self.outputEdit.insertPlainText(self.errorMessage) 141 self.outputEdit.insertPlainText(self.__errorMessage)
188 142
189 @pyqtSlot() 143 @pyqtSlot()
190 def __cancelProcess(self): 144 def __cancelProcess(self):
191 """ 145 """
192 Private slot to terminate the current process. 146 Private slot to terminate the current process.

eric ide

mercurial