eric6/Plugins/VcsPlugins/vcsGit/GitStashBrowserDialog.py

changeset 7771
787a6b3f8c9f
parent 7360
9190402e4505
child 7780
41420f82c0ac
equal deleted inserted replaced
7770:49f3377aebf1 7771:787a6b3f8c9f
9 9
10 10
11 import os 11 import os
12 12
13 from PyQt5.QtCore import pyqtSlot, Qt, QPoint, QProcess, QTimer 13 from PyQt5.QtCore import pyqtSlot, Qt, QPoint, QProcess, QTimer
14 from PyQt5.QtGui import QCursor
15 from PyQt5.QtWidgets import ( 14 from PyQt5.QtWidgets import (
16 QWidget, QDialogButtonBox, QTreeWidgetItem, QAbstractButton, QMenu, 15 QWidget, QDialogButtonBox, QTreeWidgetItem, QAbstractButton, QMenu,
17 QHeaderView, QApplication, QLineEdit 16 QHeaderView, QApplication, 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_GitStashBrowserDialog import Ui_GitStashBrowserDialog 22 from .Ui_GitStashBrowserDialog import Ui_GitStashBrowserDialog
23 23
24 import Preferences 24 import Preferences
25 from Globals import strToQByteArray 25 from Globals import strToQByteArray
67 self.vcs = vcs 67 self.vcs = vcs
68 self.__resetUI() 68 self.__resetUI()
69 69
70 self.__ioEncoding = Preferences.getSystem("IOEncoding") 70 self.__ioEncoding = Preferences.getSystem("IOEncoding")
71 71
72 self.process = QProcess() 72 self.__process = E5OverrideCursorProcess()
73 self.process.finished.connect(self.__procFinished) 73 self.__process.finished.connect(self.__procFinished)
74 self.process.readyReadStandardOutput.connect(self.__readStdout) 74 self.__process.readyReadStandardOutput.connect(self.__readStdout)
75 self.process.readyReadStandardError.connect(self.__readStderr) 75 self.__process.readyReadStandardError.connect(self.__readStderr)
76 76
77 self.__contextMenu = QMenu() 77 self.__contextMenu = QMenu()
78 self.__differencesAct = self.__contextMenu.addAction( 78 self.__differencesAct = self.__contextMenu.addAction(
79 self.tr("Show"), self.__showPatch) 79 self.tr("Show"), self.__showPatch)
80 self.__contextMenu.addSeparator() 80 self.__contextMenu.addSeparator()
96 Protected slot implementing a close event handler. 96 Protected slot implementing a close event handler.
97 97
98 @param e close event (QCloseEvent) 98 @param e close event (QCloseEvent)
99 """ 99 """
100 if ( 100 if (
101 self.process is not None and 101 self.__process is not None and
102 self.process.state() != QProcess.NotRunning 102 self.__process.state() != QProcess.NotRunning
103 ): 103 ):
104 self.process.terminate() 104 self.__process.terminate()
105 QTimer.singleShot(2000, self.process.kill) 105 QTimer.singleShot(2000, self.__process.kill)
106 self.process.waitForFinished(3000) 106 self.__process.waitForFinished(3000)
107 107
108 self.__position = self.pos() 108 self.__position = self.pos()
109 109
110 e.accept() 110 e.accept()
111 111
152 152
153 self.inputGroup.setEnabled(True) 153 self.inputGroup.setEnabled(True)
154 self.inputGroup.show() 154 self.inputGroup.show()
155 self.refreshButton.setEnabled(False) 155 self.refreshButton.setEnabled(False)
156 156
157 QApplication.setOverrideCursor(QCursor(Qt.WaitCursor))
158 QApplication.processEvents()
159
160 self.buf = [] 157 self.buf = []
161 self.errors.clear() 158 self.errors.clear()
162 self.intercept = False 159 self.intercept = False
163 160
164 args = self.vcs.initCommand("stash") 161 args = self.vcs.initCommand("stash")
165 args.append("list") 162 args.append("list")
166 args.append("--format=format:%gd{0}%ai{0}%gs%n".format(self.Separator)) 163 args.append("--format=format:%gd{0}%ai{0}%gs%n".format(self.Separator))
167 164
168 self.process.kill() 165 self.__process.kill()
169 166
170 self.process.setWorkingDirectory(self.repodir) 167 self.__process.setWorkingDirectory(self.repodir)
171 168
172 self.inputGroup.setEnabled(True) 169 self.inputGroup.setEnabled(True)
173 self.inputGroup.show() 170 self.inputGroup.show()
174 171
175 self.process.start('git', args) 172 self.__process.start('git', args)
176 procStarted = self.process.waitForStarted(5000) 173 procStarted = self.__process.waitForStarted(5000)
177 if not procStarted: 174 if not procStarted:
178 self.inputGroup.setEnabled(False) 175 self.inputGroup.setEnabled(False)
179 self.inputGroup.hide() 176 self.inputGroup.hide()
180 E5MessageBox.critical( 177 E5MessageBox.critical(
181 self, 178 self,
224 """ 221 """
225 Private slot called when the process finished or the user pressed 222 Private slot called when the process finished or the user pressed
226 the button. 223 the button.
227 """ 224 """
228 if ( 225 if (
229 self.process is not None and 226 self.__process is not None and
230 self.process.state() != QProcess.NotRunning 227 self.__process.state() != QProcess.NotRunning
231 ): 228 ):
232 self.process.terminate() 229 self.__process.terminate()
233 QTimer.singleShot(2000, self.process.kill) 230 QTimer.singleShot(2000, self.__process.kill)
234 self.process.waitForFinished(3000) 231 self.__process.waitForFinished(3000)
235
236 QApplication.restoreOverrideCursor()
237 232
238 self.buttonBox.button(QDialogButtonBox.Close).setEnabled(True) 233 self.buttonBox.button(QDialogButtonBox.Close).setEnabled(True)
239 self.buttonBox.button(QDialogButtonBox.Cancel).setEnabled(False) 234 self.buttonBox.button(QDialogButtonBox.Cancel).setEnabled(False)
240 self.buttonBox.button(QDialogButtonBox.Close).setDefault(True) 235 self.buttonBox.button(QDialogButtonBox.Close).setDefault(True)
241 236
262 """ 257 """
263 Private slot to handle the readyReadStandardOutput signal. 258 Private slot to handle the readyReadStandardOutput signal.
264 259
265 It reads the output of the process and inserts it into a buffer. 260 It reads the output of the process and inserts it into a buffer.
266 """ 261 """
267 self.process.setReadChannel(QProcess.StandardOutput) 262 self.__process.setReadChannel(QProcess.StandardOutput)
268 263
269 while self.process.canReadLine(): 264 while self.__process.canReadLine():
270 line = str(self.process.readLine(), self.__ioEncoding, 265 line = str(self.__process.readLine(), self.__ioEncoding,
271 'replace').strip() 266 'replace').strip()
272 if line: 267 if line:
273 self.buf.append(line) 268 self.buf.append(line)
274 269
275 def __readStderr(self): 270 def __readStderr(self):
277 Private slot to handle the readyReadStandardError signal. 272 Private slot to handle the readyReadStandardError signal.
278 273
279 It reads the error output of the process and inserts it into the 274 It reads the error output of the process and inserts it into the
280 error pane. 275 error pane.
281 """ 276 """
282 if self.process is not None: 277 if self.__process is not None:
283 s = str(self.process.readAllStandardError(), 278 s = str(self.__process.readAllStandardError(),
284 self.__ioEncoding, 'replace') 279 self.__ioEncoding, 'replace')
285 self.errorGroup.show() 280 self.errorGroup.show()
286 self.errors.insertPlainText(s) 281 self.errors.insertPlainText(s)
287 self.errors.ensureCursorVisible() 282 self.errors.ensureCursorVisible()
288 283
411 else: 406 else:
412 self.errors.insertPlainText(inputTxt) 407 self.errors.insertPlainText(inputTxt)
413 self.errors.ensureCursorVisible() 408 self.errors.ensureCursorVisible()
414 self.errorGroup.show() 409 self.errorGroup.show()
415 410
416 self.process.write(strToQByteArray(inputTxt)) 411 self.__process.write(strToQByteArray(inputTxt))
417 412
418 self.passwordCheckBox.setChecked(False) 413 self.passwordCheckBox.setChecked(False)
419 self.input.clear() 414 self.input.clear()
420 415
421 @pyqtSlot() 416 @pyqtSlot()

eric ide

mercurial