eric6/Plugins/VcsPlugins/vcsPySvn/SvnBlameDialog.py

changeset 6942
2602857055c5
parent 6645
ad476851d7e0
child 7192
a22eee00b052
equal deleted inserted replaced
6941:f99d60d6b59b 6942:2602857055c5
1 # -*- coding: utf-8 -*-
2
3 # Copyright (c) 2003 - 2019 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 from __future__ import unicode_literals
11
12 import os
13 import sys
14
15 import pysvn
16
17 from PyQt5.QtCore import QMutexLocker, Qt
18 from PyQt5.QtWidgets import QHeaderView, QDialog, QDialogButtonBox, \
19 QTreeWidgetItem
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(SvnBlameDialog, self).__init__(parent)
39 self.setupUi(self)
40 SvnDialogMixin.__init__(self)
41 self.setWindowFlags(Qt.Window)
42
43 self.buttonBox.button(QDialogButtonBox.Close).setEnabled(False)
44 self.buttonBox.button(QDialogButtonBox.Cancel).setDefault(True)
45
46 self.vcs = vcs
47
48 self.blameList.headerItem().setText(self.blameList.columnCount(), "")
49 font = Preferences.getEditorOtherFonts("MonospacedFont")
50 self.blameList.setFont(font)
51
52 self.client = self.vcs.getClient()
53 self.client.callback_cancel = \
54 self._clientCancelCallback
55 self.client.callback_get_login = \
56 self._clientLoginCallback
57 self.client.callback_ssl_server_trust_prompt = \
58 self._clientSslServerTrustPromptCallback
59
60 def start(self, fn):
61 """
62 Public slot to start the svn blame command.
63
64 @param fn filename to show the blame for (string)
65 """
66 self.blameList.clear()
67 self.errorGroup.hide()
68 self.activateWindow()
69
70 dname, fname = self.vcs.splitPath(fn)
71
72 locker = QMutexLocker(self.vcs.vcsExecutionMutex)
73 cwd = os.getcwd()
74 os.chdir(dname)
75 try:
76 annotations = self.client.annotate(fname)
77 locker.unlock()
78 for annotation in annotations:
79 author = annotation["author"]
80 line = annotation["line"]
81 if sys.version_info[0] == 2:
82 author = author.decode('utf-8')
83 line = line.decode('utf-8')
84 self.__generateItem(
85 annotation["revision"].number, author,
86 annotation["number"] + 1, line)
87 except pysvn.ClientError as e:
88 locker.unlock()
89 self.__showError(e.args[0] + '\n')
90 self.__finish()
91 os.chdir(cwd)
92
93 def __finish(self):
94 """
95 Private slot called when the process finished or the user pressed the
96 button.
97 """
98 self.buttonBox.button(QDialogButtonBox.Close).setEnabled(True)
99 self.buttonBox.button(QDialogButtonBox.Cancel).setEnabled(False)
100 self.buttonBox.button(QDialogButtonBox.Close).setDefault(True)
101
102 self.__resizeColumns()
103
104 self._cancel()
105
106 def on_buttonBox_clicked(self, button):
107 """
108 Private slot called by a button of the button box clicked.
109
110 @param button button that was clicked (QAbstractButton)
111 """
112 if button == self.buttonBox.button(QDialogButtonBox.Close):
113 self.close()
114 elif button == self.buttonBox.button(QDialogButtonBox.Cancel):
115 self.__finish()
116
117 def __resizeColumns(self):
118 """
119 Private method to resize the list columns.
120 """
121 self.blameList.header().resizeSections(QHeaderView.ResizeToContents)
122
123 def __generateItem(self, revision, author, lineno, text):
124 """
125 Private method to generate a blame item in the blame list.
126
127 @param revision revision string (string)
128 @param author author of the change (string)
129 @param lineno linenumber (string)
130 @param text line of text from the annotated file (string)
131 """
132 itm = QTreeWidgetItem(
133 self.blameList,
134 ["{0:d}".format(revision), author, "{0:d}".format(lineno), text])
135 itm.setTextAlignment(0, Qt.AlignRight)
136 itm.setTextAlignment(2, Qt.AlignRight)
137
138 def __showError(self, msg):
139 """
140 Private slot to show an error message.
141
142 @param msg error message to show (string)
143 """
144 self.errorGroup.show()
145 self.errors.insertPlainText(msg)
146 self.errors.ensureCursorVisible()

eric ide

mercurial