eric6/Plugins/VcsPlugins/vcsMercurial/HgBookmarksInOutDialog.py

changeset 7370
5fb53279f2df
parent 7360
9190402e4505
child 7923
91e843545d9a
equal deleted inserted replaced
7369:dbeeed55df08 7370:5fb53279f2df
5 5
6 """ 6 """
7 Module implementing a dialog to show a list of incoming or outgoing bookmarks. 7 Module implementing a dialog to show a list of incoming or outgoing bookmarks.
8 """ 8 """
9 9
10
11 import os 10 import os
12 11
13 from PyQt5.QtCore import pyqtSlot, QProcess, Qt, QTimer, QCoreApplication 12 from PyQt5.QtCore import Qt, QCoreApplication
14 from PyQt5.QtWidgets import ( 13 from PyQt5.QtWidgets import (
15 QDialog, QDialogButtonBox, QHeaderView, QTreeWidgetItem, QLineEdit 14 QDialog, QDialogButtonBox, QHeaderView, QTreeWidgetItem
16 ) 15 )
17 16
18 from E5Gui import E5MessageBox
19
20 from .Ui_HgBookmarksInOutDialog import Ui_HgBookmarksInOutDialog 17 from .Ui_HgBookmarksInOutDialog import Ui_HgBookmarksInOutDialog
21
22 from Globals import strToQByteArray
23 18
24 19
25 class HgBookmarksInOutDialog(QDialog, Ui_HgBookmarksInOutDialog): 20 class HgBookmarksInOutDialog(QDialog, Ui_HgBookmarksInOutDialog):
26 """ 21 """
27 Class implementing a dialog to show a list of incoming or outgoing 22 Class implementing a dialog to show a list of incoming or outgoing
52 if mode == self.INCOMING: 47 if mode == self.INCOMING:
53 self.setWindowTitle(self.tr("Mercurial Incoming Bookmarks")) 48 self.setWindowTitle(self.tr("Mercurial Incoming Bookmarks"))
54 elif mode == self.OUTGOING: 49 elif mode == self.OUTGOING:
55 self.setWindowTitle(self.tr("Mercurial Outgoing Bookmarks")) 50 self.setWindowTitle(self.tr("Mercurial Outgoing Bookmarks"))
56 51
57 self.process = QProcess()
58 self.vcs = vcs 52 self.vcs = vcs
59 self.mode = mode 53 self.mode = mode
60 self.__hgClient = vcs.getClient() 54 self.__hgClient = vcs.getClient()
61 55
62 self.bookmarksList.headerItem().setText( 56 self.bookmarksList.headerItem().setText(
63 self.bookmarksList.columnCount(), "") 57 self.bookmarksList.columnCount(), "")
64 self.bookmarksList.header().setSortIndicator(3, Qt.AscendingOrder) 58 self.bookmarksList.header().setSortIndicator(3, Qt.AscendingOrder)
65
66 self.process.finished.connect(self.__procFinished)
67 self.process.readyReadStandardOutput.connect(self.__readStdout)
68 self.process.readyReadStandardError.connect(self.__readStderr)
69 59
70 self.show() 60 self.show()
71 QCoreApplication.processEvents() 61 QCoreApplication.processEvents()
72 62
73 def closeEvent(self, e): 63 def closeEvent(self, e):
74 """ 64 """
75 Protected slot implementing a close event handler. 65 Protected slot implementing a close event handler.
76 66
77 @param e close event (QCloseEvent) 67 @param e close event (QCloseEvent)
78 """ 68 """
79 if self.__hgClient: 69 if self.__hgClient.isExecuting():
80 if self.__hgClient.isExecuting(): 70 self.__hgClient.cancel()
81 self.__hgClient.cancel()
82 else:
83 if (
84 self.process is not None and
85 self.process.state() != QProcess.NotRunning
86 ):
87 self.process.terminate()
88 QTimer.singleShot(2000, self.process.kill)
89 self.process.waitForFinished(3000)
90 71
91 e.accept() 72 e.accept()
92 73
93 def start(self, path): 74 def start(self, path):
94 """ 75 """
117 args = self.vcs.initCommand("outgoing") 98 args = self.vcs.initCommand("outgoing")
118 else: 99 else:
119 raise ValueError("Bad value for mode") 100 raise ValueError("Bad value for mode")
120 args.append('--bookmarks') 101 args.append('--bookmarks')
121 102
122 if self.__hgClient: 103 out, err = self.__hgClient.runcommand(args)
123 self.inputGroup.setEnabled(False) 104 if err:
124 self.inputGroup.hide() 105 self.__showError(err)
125 106 if out:
126 out, err = self.__hgClient.runcommand(args) 107 for line in out.splitlines():
127 if err: 108 self.__processOutputLine(line)
128 self.__showError(err) 109 if self.__hgClient.wasCanceled():
129 if out: 110 break
130 for line in out.splitlines(): 111 self.__finish()
131 self.__processOutputLine(line)
132 if self.__hgClient.wasCanceled():
133 break
134 self.__finish()
135 else:
136 self.process.kill()
137 self.process.setWorkingDirectory(repodir)
138
139 self.process.start('hg', args)
140 procStarted = self.process.waitForStarted(5000)
141 if not procStarted:
142 self.inputGroup.setEnabled(False)
143 self.inputGroup.hide()
144 E5MessageBox.critical(
145 self,
146 self.tr('Process Generation Error'),
147 self.tr(
148 'The process {0} could not be started. '
149 'Ensure, that it is in the search path.'
150 ).format('hg'))
151 else:
152 self.inputGroup.setEnabled(True)
153 self.inputGroup.show()
154 112
155 def __finish(self): 113 def __finish(self):
156 """ 114 """
157 Private slot called when the process finished or the user pressed 115 Private slot called when the process finished or the user pressed
158 the button. 116 the button.
159 """ 117 """
160 if (
161 self.process is not None and
162 self.process.state() != QProcess.NotRunning
163 ):
164 self.process.terminate()
165 QTimer.singleShot(2000, self.process.kill)
166 self.process.waitForFinished(3000)
167
168 self.inputGroup.setEnabled(False)
169 self.inputGroup.hide()
170
171 self.buttonBox.button(QDialogButtonBox.Close).setEnabled(True) 118 self.buttonBox.button(QDialogButtonBox.Close).setEnabled(True)
172 self.buttonBox.button(QDialogButtonBox.Cancel).setEnabled(False) 119 self.buttonBox.button(QDialogButtonBox.Cancel).setEnabled(False)
173 self.buttonBox.button(QDialogButtonBox.Close).setDefault(True) 120 self.buttonBox.button(QDialogButtonBox.Close).setDefault(True)
174 self.buttonBox.button(QDialogButtonBox.Close).setFocus( 121 self.buttonBox.button(QDialogButtonBox.Close).setFocus(
175 Qt.OtherFocusReason) 122 Qt.OtherFocusReason)
191 elif button == self.buttonBox.button(QDialogButtonBox.Cancel): 138 elif button == self.buttonBox.button(QDialogButtonBox.Cancel):
192 if self.__hgClient: 139 if self.__hgClient:
193 self.__hgClient.cancel() 140 self.__hgClient.cancel()
194 else: 141 else:
195 self.__finish() 142 self.__finish()
196
197 def __procFinished(self, exitCode, exitStatus):
198 """
199 Private slot connected to the finished signal.
200
201 @param exitCode exit code of the process (integer)
202 @param exitStatus exit status of the process (QProcess.ExitStatus)
203 """
204 self.__finish()
205 143
206 def __resort(self): 144 def __resort(self):
207 """ 145 """
208 Private method to resort the tree. 146 Private method to resort the tree.
209 """ 147 """
228 """ 166 """
229 QTreeWidgetItem(self.bookmarksList, [ 167 QTreeWidgetItem(self.bookmarksList, [
230 name, 168 name,
231 changeset]) 169 changeset])
232 170
233 def __readStdout(self):
234 """
235 Private slot to handle the readyReadStdout signal.
236
237 It reads the output of the process, formats it and inserts it into
238 the contents pane.
239 """
240 self.process.setReadChannel(QProcess.StandardOutput)
241
242 while self.process.canReadLine():
243 s = str(self.process.readLine(), self.vcs.getEncoding(), 'replace')
244 self.__processOutputLine(s)
245
246 def __processOutputLine(self, line): 171 def __processOutputLine(self, line):
247 """ 172 """
248 Private method to process the lines of output. 173 Private method to process the lines of output.
249 174
250 @param line output line to be processed (string) 175 @param line output line to be processed (string)
254 changeset = li[-1] 179 changeset = li[-1]
255 del li[-1] 180 del li[-1]
256 name = " ".join(li) 181 name = " ".join(li)
257 self.__generateItem(changeset, name) 182 self.__generateItem(changeset, name)
258 183
259 def __readStderr(self):
260 """
261 Private slot to handle the readyReadStderr signal.
262
263 It reads the error output of the process and inserts it into the
264 error pane.
265 """
266 if self.process is not None:
267 s = str(self.process.readAllStandardError(),
268 self.vcs.getEncoding(), 'replace')
269 self.__showError(s)
270
271 def __showError(self, out): 184 def __showError(self, out):
272 """ 185 """
273 Private slot to show some error. 186 Private slot to show some error.
274 187
275 @param out error to be shown (string) 188 @param out error to be shown (string)
276 """ 189 """
277 self.errorGroup.show() 190 self.errorGroup.show()
278 self.errors.insertPlainText(out) 191 self.errors.insertPlainText(out)
279 self.errors.ensureCursorVisible() 192 self.errors.ensureCursorVisible()
280
281 def on_passwordCheckBox_toggled(self, isOn):
282 """
283 Private slot to handle the password checkbox toggled.
284
285 @param isOn flag indicating the status of the check box (boolean)
286 """
287 if isOn:
288 self.input.setEchoMode(QLineEdit.Password)
289 else:
290 self.input.setEchoMode(QLineEdit.Normal)
291
292 @pyqtSlot()
293 def on_sendButton_clicked(self):
294 """
295 Private slot to send the input to the subversion process.
296 """
297 inputTxt = self.input.text()
298 inputTxt += os.linesep
299
300 if self.passwordCheckBox.isChecked():
301 self.errors.insertPlainText(os.linesep)
302 self.errors.ensureCursorVisible()
303 else:
304 self.errors.insertPlainText(inputTxt)
305 self.errors.ensureCursorVisible()
306
307 self.process.write(strToQByteArray(inputTxt))
308
309 self.passwordCheckBox.setChecked(False)
310 self.input.clear()
311
312 def on_input_returnPressed(self):
313 """
314 Private slot to handle the press of the return key in the input field.
315 """
316 self.intercept = True
317 self.on_sendButton_clicked()
318
319 def keyPressEvent(self, evt):
320 """
321 Protected slot to handle a key press event.
322
323 @param evt the key press event (QKeyEvent)
324 """
325 if self.intercept:
326 self.intercept = False
327 evt.accept()
328 return
329 super(HgBookmarksInOutDialog, self).keyPressEvent(evt)

eric ide

mercurial