src/eric7/Plugins/VcsPlugins/vcsPySvn/SvnBlameDialog.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) 2003 - 2022 Detlev Offenbach <detlev@die-offenbachs.de>
4 #
5
6 """
7 Module implementing a dialog to show the output of the svn blame command.
8 """
9
10 import os
11
12 import pysvn
13
14 from PyQt6.QtCore import Qt
15 from PyQt6.QtWidgets import (
16 QHeaderView, QDialog, QDialogButtonBox, QTreeWidgetItem
17 )
18
19 from EricUtilities.EricMutexLocker import EricMutexLocker
20
21 from .SvnDialogMixin import SvnDialogMixin
22 from .Ui_SvnBlameDialog import Ui_SvnBlameDialog
23
24 import Preferences
25
26
27 class SvnBlameDialog(QDialog, SvnDialogMixin, Ui_SvnBlameDialog):
28 """
29 Class implementing a dialog to show the output of the svn blame command.
30 """
31 def __init__(self, vcs, parent=None):
32 """
33 Constructor
34
35 @param vcs reference to the vcs object
36 @param parent parent widget (QWidget)
37 """
38 super().__init__(parent)
39 self.setupUi(self)
40 SvnDialogMixin.__init__(self)
41 self.setWindowFlags(Qt.WindowType.Window)
42
43 self.buttonBox.button(
44 QDialogButtonBox.StandardButton.Close).setEnabled(False)
45 self.buttonBox.button(
46 QDialogButtonBox.StandardButton.Cancel).setDefault(True)
47
48 self.vcs = vcs
49
50 self.blameList.headerItem().setText(self.blameList.columnCount(), "")
51 font = Preferences.getEditorOtherFonts("MonospacedFont")
52 self.blameList.setFont(font)
53
54 self.client = self.vcs.getClient()
55 self.client.callback_cancel = self._clientCancelCallback
56 self.client.callback_get_login = self._clientLoginCallback
57 self.client.callback_ssl_server_trust_prompt = (
58 self._clientSslServerTrustPromptCallback
59 )
60
61 def start(self, fn):
62 """
63 Public slot to start the svn blame command.
64
65 @param fn filename to show the blame for (string)
66 """
67 self.blameList.clear()
68 self.errorGroup.hide()
69 self.activateWindow()
70
71 dname, fname = self.vcs.splitPath(fn)
72
73 cwd = os.getcwd()
74 os.chdir(dname)
75 try:
76 with EricMutexLocker(self.vcs.vcsExecutionMutex):
77 annotations = self.client.annotate(fname)
78 for annotation in annotations:
79 author = annotation["author"]
80 line = annotation["line"]
81 self.__generateItem(
82 annotation["revision"].number, author,
83 annotation["number"] + 1, line)
84 except pysvn.ClientError as e:
85 self.__showError(e.args[0] + '\n')
86 self.__finish()
87 os.chdir(cwd)
88
89 def __finish(self):
90 """
91 Private slot called when the process finished or the user pressed the
92 button.
93 """
94 self.buttonBox.button(
95 QDialogButtonBox.StandardButton.Close).setEnabled(True)
96 self.buttonBox.button(
97 QDialogButtonBox.StandardButton.Cancel).setEnabled(False)
98 self.buttonBox.button(
99 QDialogButtonBox.StandardButton.Close).setDefault(True)
100
101 self.__resizeColumns()
102
103 self._cancel()
104
105 def on_buttonBox_clicked(self, button):
106 """
107 Private slot called by a button of the button box clicked.
108
109 @param button button that was clicked (QAbstractButton)
110 """
111 if button == self.buttonBox.button(
112 QDialogButtonBox.StandardButton.Close
113 ):
114 self.close()
115 elif button == self.buttonBox.button(
116 QDialogButtonBox.StandardButton.Cancel
117 ):
118 self.__finish()
119
120 def __resizeColumns(self):
121 """
122 Private method to resize the list columns.
123 """
124 self.blameList.header().resizeSections(
125 QHeaderView.ResizeMode.ResizeToContents)
126
127 def __generateItem(self, revision, author, lineno, text):
128 """
129 Private method to generate a blame item in the blame list.
130
131 @param revision revision string (string)
132 @param author author of the change (string)
133 @param lineno linenumber (string)
134 @param text line of text from the annotated file (string)
135 """
136 itm = QTreeWidgetItem(
137 self.blameList,
138 ["{0:d}".format(revision), author, "{0:d}".format(lineno), text])
139 itm.setTextAlignment(0, Qt.AlignmentFlag.AlignRight)
140 itm.setTextAlignment(2, Qt.AlignmentFlag.AlignRight)
141
142 def __showError(self, msg):
143 """
144 Private slot to show an error message.
145
146 @param msg error message to show (string)
147 """
148 self.errorGroup.show()
149 self.errors.insertPlainText(msg)
150 self.errors.ensureCursorVisible()

eric ide

mercurial