src/eric7/Plugins/VcsPlugins/vcsMercurial/HgAnnotateDialog.py

branch
eric7
changeset 9209
b99e7fd55fd3
parent 8881
54e42bc2437a
child 9221
bf71ee032bb4
equal deleted inserted replaced
9208:3fc8dfeb6ebe 9209:b99e7fd55fd3
1 # -*- coding: utf-8 -*-
2
3 # Copyright (c) 2010 - 2022 Detlev Offenbach <detlev@die-offenbachs.de>
4 #
5
6 """
7 Module implementing a dialog to show the output of the hg annotate command.
8 """
9
10 import re
11
12 from PyQt6.QtCore import Qt, QCoreApplication
13 from PyQt6.QtWidgets import (
14 QDialog, QDialogButtonBox, QHeaderView, QTreeWidgetItem
15 )
16
17 from .Ui_HgAnnotateDialog import Ui_HgAnnotateDialog
18
19 import Preferences
20
21
22 class HgAnnotateDialog(QDialog, Ui_HgAnnotateDialog):
23 """
24 Class implementing a dialog to show the output of the hg annotate command.
25 """
26 def __init__(self, vcs, parent=None):
27 """
28 Constructor
29
30 @param vcs reference to the vcs object
31 @param parent parent widget (QWidget)
32 """
33 super().__init__(parent)
34 self.setupUi(self)
35 self.setWindowFlags(Qt.WindowType.Window)
36
37 self.buttonBox.button(
38 QDialogButtonBox.StandardButton.Close).setEnabled(False)
39 self.buttonBox.button(
40 QDialogButtonBox.StandardButton.Cancel).setDefault(True)
41
42 self.vcs = vcs
43 self.__hgClient = vcs.getClient()
44
45 self.__annotateRe = re.compile(
46 r"""(.+)\s+(\d+)\s+([0-9a-fA-F]+)\s+([0-9-]+)\s+(.+)""")
47
48 self.annotateList.headerItem().setText(
49 self.annotateList.columnCount(), "")
50 font = Preferences.getEditorOtherFonts("MonospacedFont")
51 self.annotateList.setFont(font)
52
53 self.show()
54 QCoreApplication.processEvents()
55
56 def closeEvent(self, e):
57 """
58 Protected slot implementing a close event handler.
59
60 @param e close event (QCloseEvent)
61 """
62 if self.__hgClient.isExecuting():
63 self.__hgClient.cancel()
64
65 e.accept()
66
67 def start(self, fn):
68 """
69 Public slot to start the annotate command.
70
71 @param fn filename to show the annotation for (string)
72 """
73 self.annotateList.clear()
74 self.errorGroup.hide()
75 self.intercept = False
76 self.activateWindow()
77 self.lineno = 1
78
79 args = self.vcs.initCommand("annotate")
80 args.append('--follow')
81 args.append('--user')
82 args.append('--date')
83 args.append('--number')
84 args.append('--changeset')
85 args.append('--quiet')
86 args.append(fn)
87
88 out, err = self.__hgClient.runcommand(args)
89 if err:
90 self.__showError(err)
91 if out:
92 for line in out.splitlines():
93 self.__processOutputLine(line)
94 if self.__hgClient.wasCanceled():
95 break
96 self.__finish()
97
98 def __finish(self):
99 """
100 Private slot called when the process finished or the user pressed
101 the button.
102 """
103 self.buttonBox.button(
104 QDialogButtonBox.StandardButton.Close).setEnabled(True)
105 self.buttonBox.button(
106 QDialogButtonBox.StandardButton.Cancel).setEnabled(False)
107 self.buttonBox.button(
108 QDialogButtonBox.StandardButton.Close).setDefault(True)
109 self.buttonBox.button(
110 QDialogButtonBox.StandardButton.Close).setFocus(
111 Qt.FocusReason.OtherFocusReason)
112
113 self.__resizeColumns()
114
115 def on_buttonBox_clicked(self, button):
116 """
117 Private slot called by a button of the button box clicked.
118
119 @param button button that was clicked (QAbstractButton)
120 """
121 if button == self.buttonBox.button(
122 QDialogButtonBox.StandardButton.Close
123 ):
124 self.close()
125 elif button == self.buttonBox.button(
126 QDialogButtonBox.StandardButton.Cancel
127 ):
128 if self.__hgClient:
129 self.__hgClient.cancel()
130 else:
131 self.__finish()
132
133 def __resizeColumns(self):
134 """
135 Private method to resize the list columns.
136 """
137 self.annotateList.header().resizeSections(
138 QHeaderView.ResizeMode.ResizeToContents)
139
140 def __generateItem(self, revision, changeset, author, date, text):
141 """
142 Private method to generate an annotate item in the annotation list.
143
144 @param revision revision string (string)
145 @param changeset changeset string (string)
146 @param author author of the change (string)
147 @param date date of the change (string)
148 @param text text of the change (string)
149 """
150 itm = QTreeWidgetItem(
151 self.annotateList,
152 [revision, changeset, author, date, "{0:d}".format(self.lineno),
153 text])
154 self.lineno += 1
155 itm.setTextAlignment(0, Qt.AlignmentFlag.AlignRight)
156 itm.setTextAlignment(4, Qt.AlignmentFlag.AlignRight)
157
158 def __processOutputLine(self, line):
159 """
160 Private method to process the lines of output.
161
162 @param line output line to be processed (string)
163 """
164 try:
165 info, text = line.split(": ", 1)
166 except ValueError:
167 info = line[:-2]
168 text = ""
169 match = self.__annotateRe.match(info)
170 author, rev, changeset, date, file = match.groups()
171 self.__generateItem(rev.strip(), changeset.strip(), author.strip(),
172 date.strip(), text)
173
174 def __showError(self, out):
175 """
176 Private slot to show some error.
177
178 @param out error to be shown (string)
179 """
180 self.errorGroup.show()
181 self.errors.insertPlainText(out)
182 self.errors.ensureCursorVisible()

eric ide

mercurial