eric6/Plugins/VcsPlugins/vcsMercurial/HgBookmarksListDialog.py

changeset 7370
5fb53279f2df
parent 7360
9190402e4505
child 7533
88261c96484b
equal deleted inserted replaced
7369:dbeeed55df08 7370:5fb53279f2df
5 5
6 """ 6 """
7 Module implementing a dialog to show a list of bookmarks. 7 Module implementing a dialog to show a list of bookmarks.
8 """ 8 """
9 9
10
11 import os 10 import os
12 11
13 from PyQt5.QtCore import ( 12 from PyQt5.QtCore import pyqtSlot, Qt, QCoreApplication, QPoint
14 pyqtSlot, QProcess, Qt, QTimer, QCoreApplication, QPoint
15 )
16 from PyQt5.QtWidgets import ( 13 from PyQt5.QtWidgets import (
17 QDialog, QDialogButtonBox, QHeaderView, QTreeWidgetItem, QLineEdit, QMenu, 14 QDialog, QDialogButtonBox, QHeaderView, QTreeWidgetItem, QLineEdit, QMenu,
18 QInputDialog 15 QInputDialog
19 ) 16 )
20 17
22 from E5Gui import E5MessageBox 19 from E5Gui import E5MessageBox
23 20
24 from .Ui_HgBookmarksListDialog import Ui_HgBookmarksListDialog 21 from .Ui_HgBookmarksListDialog import Ui_HgBookmarksListDialog
25 22
26 import UI.PixmapCache 23 import UI.PixmapCache
27 from Globals import strToQByteArray
28 24
29 25
30 class HgBookmarksListDialog(QDialog, Ui_HgBookmarksListDialog): 26 class HgBookmarksListDialog(QDialog, Ui_HgBookmarksListDialog):
31 """ 27 """
32 Class implementing a dialog to show a list of bookmarks. 28 Class implementing a dialog to show a list of bookmarks.
48 self.tr("Press to refresh the bookmarks display")) 44 self.tr("Press to refresh the bookmarks display"))
49 self.refreshButton.setEnabled(False) 45 self.refreshButton.setEnabled(False)
50 self.buttonBox.button(QDialogButtonBox.Close).setEnabled(False) 46 self.buttonBox.button(QDialogButtonBox.Close).setEnabled(False)
51 self.buttonBox.button(QDialogButtonBox.Cancel).setDefault(True) 47 self.buttonBox.button(QDialogButtonBox.Cancel).setDefault(True)
52 48
53 self.process = QProcess()
54 self.vcs = vcs 49 self.vcs = vcs
55 self.__bookmarksList = None 50 self.__bookmarksList = None
56 self.__repoDir = None 51 self.__repoDir = None
57 self.__hgClient = vcs.getClient() 52 self.__hgClient = vcs.getClient()
58 self.__bookmarksDefined = False 53 self.__bookmarksDefined = False
60 55
61 self.bookmarksList.headerItem().setText( 56 self.bookmarksList.headerItem().setText(
62 self.bookmarksList.columnCount(), "") 57 self.bookmarksList.columnCount(), "")
63 self.bookmarksList.header().setSortIndicator(3, Qt.AscendingOrder) 58 self.bookmarksList.header().setSortIndicator(3, Qt.AscendingOrder)
64 59
65 self.process.finished.connect(self.__procFinished)
66 self.process.readyReadStandardOutput.connect(self.__readStdout)
67 self.process.readyReadStandardError.connect(self.__readStderr)
68
69 self.show() 60 self.show()
70 QCoreApplication.processEvents() 61 QCoreApplication.processEvents()
71 62
72 def closeEvent(self, e): 63 def closeEvent(self, e):
73 """ 64 """
74 Protected slot implementing a close event handler. 65 Protected slot implementing a close event handler.
75 66
76 @param e close event (QCloseEvent) 67 @param e close event (QCloseEvent)
77 """ 68 """
78 if self.__hgClient: 69 if self.__hgClient.isExecuting():
79 if self.__hgClient.isExecuting(): 70 self.__hgClient.cancel()
80 self.__hgClient.cancel()
81 else:
82 if (
83 self.process is not None and
84 self.process.state() != QProcess.NotRunning
85 ):
86 self.process.terminate()
87 QTimer.singleShot(2000, self.process.kill)
88 self.process.waitForFinished(3000)
89 71
90 e.accept() 72 e.accept()
91 73
92 def start(self, path, bookmarksList): 74 def start(self, path, bookmarksList):
93 """ 75 """
118 return 100 return
119 self.__repoDir = repodir 101 self.__repoDir = repodir
120 102
121 args = self.vcs.initCommand("bookmarks") 103 args = self.vcs.initCommand("bookmarks")
122 104
123 if self.__hgClient: 105 self.refreshButton.setEnabled(False)
124 self.inputGroup.setEnabled(False) 106
125 self.inputGroup.hide() 107 out, err = self.__hgClient.runcommand(args)
126 self.refreshButton.setEnabled(False) 108 if err:
127 109 self.__showError(err)
128 out, err = self.__hgClient.runcommand(args) 110 if out:
129 if err: 111 for line in out.splitlines():
130 self.__showError(err) 112 self.__processOutputLine(line)
131 if out: 113 if self.__hgClient.wasCanceled():
132 for line in out.splitlines(): 114 break
133 self.__processOutputLine(line) 115 self.__finish()
134 if self.__hgClient.wasCanceled():
135 break
136 self.__finish()
137 else:
138 self.process.kill()
139 self.process.setWorkingDirectory(repodir)
140
141 self.process.start('hg', args)
142 procStarted = self.process.waitForStarted(5000)
143 if not procStarted:
144 self.inputGroup.setEnabled(False)
145 self.inputGroup.hide()
146 E5MessageBox.critical(
147 self,
148 self.tr('Process Generation Error'),
149 self.tr(
150 'The process {0} could not be started. '
151 'Ensure, that it is in the search path.'
152 ).format('hg'))
153 else:
154 self.buttonBox.button(QDialogButtonBox.Close).setEnabled(False)
155 self.buttonBox.button(QDialogButtonBox.Cancel).setEnabled(True)
156 self.buttonBox.button(QDialogButtonBox.Cancel).setDefault(True)
157
158 self.inputGroup.setEnabled(True)
159 self.inputGroup.show()
160 self.refreshButton.setEnabled(False)
161 116
162 def __finish(self): 117 def __finish(self):
163 """ 118 """
164 Private slot called when the process finished or the user pressed 119 Private slot called when the process finished or the user pressed
165 the button. 120 the button.
166 """ 121 """
167 if (
168 self.process is not None and
169 self.process.state() != QProcess.NotRunning
170 ):
171 self.process.terminate()
172 QTimer.singleShot(2000, self.process.kill)
173 self.process.waitForFinished(3000)
174
175 self.inputGroup.setEnabled(False)
176 self.inputGroup.hide()
177 self.refreshButton.setEnabled(True) 122 self.refreshButton.setEnabled(True)
178 123
179 self.buttonBox.button(QDialogButtonBox.Close).setEnabled(True) 124 self.buttonBox.button(QDialogButtonBox.Close).setEnabled(True)
180 self.buttonBox.button(QDialogButtonBox.Cancel).setEnabled(False) 125 self.buttonBox.button(QDialogButtonBox.Cancel).setEnabled(False)
181 self.buttonBox.button(QDialogButtonBox.Close).setDefault(True) 126 self.buttonBox.button(QDialogButtonBox.Close).setDefault(True)
215 self.__hgClient.cancel() 160 self.__hgClient.cancel()
216 else: 161 else:
217 self.__finish() 162 self.__finish()
218 elif button == self.refreshButton: 163 elif button == self.refreshButton:
219 self.on_refreshButton_clicked() 164 self.on_refreshButton_clicked()
220
221 def __procFinished(self, exitCode, exitStatus):
222 """
223 Private slot connected to the finished signal.
224
225 @param exitCode exit code of the process (integer)
226 @param exitStatus exit status of the process (QProcess.ExitStatus)
227 """
228 self.__finish()
229 165
230 def __resort(self): 166 def __resort(self):
231 """ 167 """
232 Private method to resort the tree. 168 Private method to resort the tree.
233 """ 169 """
263 itm.setTextAlignment(1, Qt.AlignRight) 199 itm.setTextAlignment(1, Qt.AlignRight)
264 itm.setTextAlignment(2, Qt.AlignHCenter) 200 itm.setTextAlignment(2, Qt.AlignHCenter)
265 else: 201 else:
266 # error message 202 # error message
267 itm.setData(0, Qt.DisplayRole, revision) 203 itm.setData(0, Qt.DisplayRole, revision)
268
269 def __readStdout(self):
270 """
271 Private slot to handle the readyReadStdout signal.
272
273 It reads the output of the process, formats it and inserts it into
274 the contents pane.
275 """
276 self.process.setReadChannel(QProcess.StandardOutput)
277
278 while self.process.canReadLine():
279 s = str(self.process.readLine(), self.vcs.getEncoding(),
280 'replace').strip()
281 self.__processOutputLine(s)
282 204
283 def __processOutputLine(self, line): 205 def __processOutputLine(self, line):
284 """ 206 """
285 Private method to process the lines of output. 207 Private method to process the lines of output.
286 208
299 name = " ".join(li) 221 name = " ".join(li)
300 self.__generateItem(rev, changeset, status, name) 222 self.__generateItem(rev, changeset, status, name)
301 if self.__bookmarksList is not None: 223 if self.__bookmarksList is not None:
302 self.__bookmarksList.append(name) 224 self.__bookmarksList.append(name)
303 225
304 def __readStderr(self):
305 """
306 Private slot to handle the readyReadStderr signal.
307
308 It reads the error output of the process and inserts it into the
309 error pane.
310 """
311 if self.process is not None:
312 s = str(self.process.readAllStandardError(),
313 self.vcs.getEncoding(), 'replace')
314 self.__showError(s)
315
316 def __showError(self, out): 226 def __showError(self, out):
317 """ 227 """
318 Private slot to show some error. 228 Private slot to show some error.
319 229
320 @param out error to be shown (string) 230 @param out error to be shown (string)
321 """ 231 """
322 self.errorGroup.show() 232 self.errorGroup.show()
323 self.errors.insertPlainText(out) 233 self.errors.insertPlainText(out)
324 self.errors.ensureCursorVisible() 234 self.errors.ensureCursorVisible()
325
326 def on_passwordCheckBox_toggled(self, isOn):
327 """
328 Private slot to handle the password checkbox toggled.
329
330 @param isOn flag indicating the status of the check box (boolean)
331 """
332 if isOn:
333 self.input.setEchoMode(QLineEdit.Password)
334 else:
335 self.input.setEchoMode(QLineEdit.Normal)
336
337 @pyqtSlot()
338 def on_sendButton_clicked(self):
339 """
340 Private slot to send the input to the subversion process.
341 """
342 inputTxt = self.input.text()
343 inputTxt += os.linesep
344
345 if self.passwordCheckBox.isChecked():
346 self.errors.insertPlainText(os.linesep)
347 self.errors.ensureCursorVisible()
348 else:
349 self.errors.insertPlainText(inputTxt)
350 self.errors.ensureCursorVisible()
351
352 self.process.write(strToQByteArray(inputTxt))
353
354 self.passwordCheckBox.setChecked(False)
355 self.input.clear()
356
357 def on_input_returnPressed(self):
358 """
359 Private slot to handle the press of the return key in the input field.
360 """
361 self.intercept = True
362 self.on_sendButton_clicked()
363
364 def keyPressEvent(self, evt):
365 """
366 Protected slot to handle a key press event.
367
368 @param evt the key press event (QKeyEvent)
369 """
370 if self.intercept:
371 self.intercept = False
372 evt.accept()
373 return
374 super(HgBookmarksListDialog, self).keyPressEvent(evt)
375 235
376 @pyqtSlot() 236 @pyqtSlot()
377 def on_refreshButton_clicked(self): 237 def on_refreshButton_clicked(self):
378 """ 238 """
379 Private slot to refresh the status display. 239 Private slot to refresh the status display.

eric ide

mercurial