9 |
9 |
10 |
10 |
11 import os |
11 import os |
12 |
12 |
13 from PyQt5.QtCore import pyqtSlot, Qt, QProcess, QTimer, QPoint |
13 from PyQt5.QtCore import pyqtSlot, Qt, QProcess, QTimer, QPoint |
14 from PyQt5.QtGui import QCursor |
|
15 from PyQt5.QtWidgets import ( |
14 from PyQt5.QtWidgets import ( |
16 QWidget, QDialogButtonBox, QHeaderView, QTreeWidgetItem, QApplication, |
15 QWidget, QDialogButtonBox, QHeaderView, QTreeWidgetItem, QApplication, |
17 QLineEdit |
16 QLineEdit |
18 ) |
17 ) |
19 |
18 |
20 from E5Gui import E5MessageBox |
19 from E5Gui import E5MessageBox |
|
20 from E5Gui.E5OverrideCursor import E5OverrideCursorProcess |
21 |
21 |
22 from .Ui_GitReflogBrowserDialog import Ui_GitReflogBrowserDialog |
22 from .Ui_GitReflogBrowserDialog import Ui_GitReflogBrowserDialog |
23 |
23 |
24 import Preferences |
24 import Preferences |
25 from Globals import strToQByteArray |
25 from Globals import strToQByteArray |
73 self.__currentCommitId = "" |
73 self.__currentCommitId = "" |
74 |
74 |
75 self.__initData() |
75 self.__initData() |
76 self.__resetUI() |
76 self.__resetUI() |
77 |
77 |
78 self.process = QProcess() |
78 self.__process = E5OverrideCursorProcess() |
79 self.process.finished.connect(self.__procFinished) |
79 self.__process.finished.connect(self.__procFinished) |
80 self.process.readyReadStandardOutput.connect(self.__readStdout) |
80 self.__process.readyReadStandardOutput.connect(self.__readStdout) |
81 self.process.readyReadStandardError.connect(self.__readStderr) |
81 self.__process.readyReadStandardError.connect(self.__readStderr) |
82 |
82 |
83 def __initData(self): |
83 def __initData(self): |
84 """ |
84 """ |
85 Private method to (re-)initialize some data. |
85 Private method to (re-)initialize some data. |
86 """ |
86 """ |
93 Protected slot implementing a close event handler. |
93 Protected slot implementing a close event handler. |
94 |
94 |
95 @param e close event (QCloseEvent) |
95 @param e close event (QCloseEvent) |
96 """ |
96 """ |
97 if ( |
97 if ( |
98 self.process is not None and |
98 self.__process is not None and |
99 self.process.state() != QProcess.NotRunning |
99 self.__process.state() != QProcess.NotRunning |
100 ): |
100 ): |
101 self.process.terminate() |
101 self.__process.terminate() |
102 QTimer.singleShot(2000, self.process.kill) |
102 QTimer.singleShot(2000, self.__process.kill) |
103 self.process.waitForFinished(3000) |
103 self.__process.waitForFinished(3000) |
104 |
104 |
105 self.__position = self.pos() |
105 self.__position = self.pos() |
106 |
106 |
107 e.accept() |
107 e.accept() |
108 |
108 |
163 self.buttonBox.button(QDialogButtonBox.Close).setEnabled(False) |
163 self.buttonBox.button(QDialogButtonBox.Close).setEnabled(False) |
164 self.buttonBox.button(QDialogButtonBox.Cancel).setEnabled(True) |
164 self.buttonBox.button(QDialogButtonBox.Cancel).setEnabled(True) |
165 self.buttonBox.button(QDialogButtonBox.Cancel).setDefault(True) |
165 self.buttonBox.button(QDialogButtonBox.Cancel).setDefault(True) |
166 QApplication.processEvents() |
166 QApplication.processEvents() |
167 |
167 |
168 QApplication.setOverrideCursor(QCursor(Qt.WaitCursor)) |
|
169 QApplication.processEvents() |
|
170 |
|
171 self.buf = [] |
168 self.buf = [] |
172 self.cancelled = False |
169 self.cancelled = False |
173 self.errors.clear() |
170 self.errors.clear() |
174 self.intercept = False |
171 self.intercept = False |
175 |
172 |
179 args.append('--abbrev={0}'.format( |
176 args.append('--abbrev={0}'.format( |
180 self.vcs.getPlugin().getPreferences("CommitIdLength"))) |
177 self.vcs.getPlugin().getPreferences("CommitIdLength"))) |
181 args.append('--format={0}'.format(self.__formatTemplate)) |
178 args.append('--format={0}'.format(self.__formatTemplate)) |
182 args.append('--skip={0}'.format(skip)) |
179 args.append('--skip={0}'.format(skip)) |
183 |
180 |
184 self.process.kill() |
181 self.__process.kill() |
185 |
182 |
186 self.process.setWorkingDirectory(self.repodir) |
183 self.__process.setWorkingDirectory(self.repodir) |
187 |
184 |
188 self.inputGroup.setEnabled(True) |
185 self.inputGroup.setEnabled(True) |
189 self.inputGroup.show() |
186 self.inputGroup.show() |
190 |
187 |
191 self.process.start('git', args) |
188 self.__process.start('git', args) |
192 procStarted = self.process.waitForStarted(5000) |
189 procStarted = self.__process.waitForStarted(5000) |
193 if not procStarted: |
190 if not procStarted: |
194 self.inputGroup.setEnabled(False) |
191 self.inputGroup.setEnabled(False) |
195 self.inputGroup.hide() |
192 self.inputGroup.hide() |
196 E5MessageBox.critical( |
193 E5MessageBox.critical( |
197 self, |
194 self, |
240 """ |
237 """ |
241 Private slot called when the process finished or the user pressed |
238 Private slot called when the process finished or the user pressed |
242 the button. |
239 the button. |
243 """ |
240 """ |
244 if ( |
241 if ( |
245 self.process is not None and |
242 self.__process is not None and |
246 self.process.state() != QProcess.NotRunning |
243 self.__process.state() != QProcess.NotRunning |
247 ): |
244 ): |
248 self.process.terminate() |
245 self.__process.terminate() |
249 QTimer.singleShot(2000, self.process.kill) |
246 QTimer.singleShot(2000, self.__process.kill) |
250 self.process.waitForFinished(3000) |
247 self.__process.waitForFinished(3000) |
251 |
|
252 QApplication.restoreOverrideCursor() |
|
253 |
248 |
254 self.buttonBox.button(QDialogButtonBox.Close).setEnabled(True) |
249 self.buttonBox.button(QDialogButtonBox.Close).setEnabled(True) |
255 self.buttonBox.button(QDialogButtonBox.Cancel).setEnabled(False) |
250 self.buttonBox.button(QDialogButtonBox.Cancel).setEnabled(False) |
256 self.buttonBox.button(QDialogButtonBox.Close).setDefault(True) |
251 self.buttonBox.button(QDialogButtonBox.Close).setDefault(True) |
257 |
252 |
311 """ |
306 """ |
312 Private slot to handle the readyReadStandardOutput signal. |
307 Private slot to handle the readyReadStandardOutput signal. |
313 |
308 |
314 It reads the output of the process and inserts it into a buffer. |
309 It reads the output of the process and inserts it into a buffer. |
315 """ |
310 """ |
316 self.process.setReadChannel(QProcess.StandardOutput) |
311 self.__process.setReadChannel(QProcess.StandardOutput) |
317 |
312 |
318 while self.process.canReadLine(): |
313 while self.__process.canReadLine(): |
319 line = str(self.process.readLine(), |
314 line = str(self.__process.readLine(), |
320 Preferences.getSystem("IOEncoding"), |
315 Preferences.getSystem("IOEncoding"), |
321 'replace') |
316 'replace') |
322 self.buf.append(line) |
317 self.buf.append(line) |
323 |
318 |
324 def __readStderr(self): |
319 def __readStderr(self): |
326 Private slot to handle the readyReadStandardError signal. |
321 Private slot to handle the readyReadStandardError signal. |
327 |
322 |
328 It reads the error output of the process and inserts it into the |
323 It reads the error output of the process and inserts it into the |
329 error pane. |
324 error pane. |
330 """ |
325 """ |
331 if self.process is not None: |
326 if self.__process is not None: |
332 s = str(self.process.readAllStandardError(), |
327 s = str(self.__process.readAllStandardError(), |
333 Preferences.getSystem("IOEncoding"), |
328 Preferences.getSystem("IOEncoding"), |
334 'replace') |
329 'replace') |
335 self.__showError(s) |
330 self.__showError(s) |
336 |
331 |
337 def __showError(self, out): |
332 def __showError(self, out): |
397 else: |
392 else: |
398 self.errors.insertPlainText(inputTxt) |
393 self.errors.insertPlainText(inputTxt) |
399 self.errors.ensureCursorVisible() |
394 self.errors.ensureCursorVisible() |
400 self.errorGroup.show() |
395 self.errorGroup.show() |
401 |
396 |
402 self.process.write(strToQByteArray(inputTxt)) |
397 self.__process.write(strToQByteArray(inputTxt)) |
403 |
398 |
404 self.passwordCheckBox.setChecked(False) |
399 self.passwordCheckBox.setChecked(False) |
405 self.input.clear() |
400 self.input.clear() |
406 |
401 |
407 def on_input_returnPressed(self): |
402 def on_input_returnPressed(self): |