|
1 # -*- coding: utf-8 -*- |
|
2 |
|
3 # Copyright (c) 2003 - 2009 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 import sys |
|
12 |
|
13 import pysvn |
|
14 |
|
15 from PyQt4.QtCore import * |
|
16 from PyQt4.QtGui import * |
|
17 |
|
18 from SvnDialogMixin import SvnDialogMixin |
|
19 from Ui_SvnBlameDialog import Ui_SvnBlameDialog |
|
20 |
|
21 import Utilities |
|
22 |
|
23 class SvnBlameDialog(QDialog, SvnDialogMixin, Ui_SvnBlameDialog): |
|
24 """ |
|
25 Class implementing a dialog to show the output of the svn blame command. |
|
26 """ |
|
27 def __init__(self, vcs, parent = None): |
|
28 """ |
|
29 Constructor |
|
30 |
|
31 @param vcs reference to the vcs object |
|
32 @param parent parent widget (QWidget) |
|
33 """ |
|
34 QDialog.__init__(self, parent) |
|
35 self.setupUi(self) |
|
36 SvnDialogMixin.__init__(self) |
|
37 |
|
38 self.buttonBox.button(QDialogButtonBox.Close).setEnabled(False) |
|
39 self.buttonBox.button(QDialogButtonBox.Cancel).setDefault(True) |
|
40 |
|
41 self.vcs = vcs |
|
42 |
|
43 self.blameList.headerItem().setText(self.blameList.columnCount(), "") |
|
44 font = QFont(self.blameList.font()) |
|
45 if Utilities.isWindowsPlatform(): |
|
46 font.setFamily("Lucida Console") |
|
47 else: |
|
48 font.setFamily("Monospace") |
|
49 self.blameList.setFont(font) |
|
50 |
|
51 self.client = self.vcs.getClient() |
|
52 self.client.callback_cancel = \ |
|
53 self._clientCancelCallback |
|
54 self.client.callback_get_login = \ |
|
55 self._clientLoginCallback |
|
56 self.client.callback_ssl_server_trust_prompt = \ |
|
57 self._clientSslServerTrustPromptCallback |
|
58 |
|
59 def start(self, fn): |
|
60 """ |
|
61 Public slot to start the svn status command. |
|
62 |
|
63 @param fn filename to show the log for (string) |
|
64 """ |
|
65 self.errorGroup.hide() |
|
66 self.activateWindow() |
|
67 |
|
68 dname, fname = self.vcs.splitPath(fn) |
|
69 |
|
70 locker = QMutexLocker(self.vcs.vcsExecutionMutex) |
|
71 cwd = os.getcwd() |
|
72 os.chdir(dname) |
|
73 try: |
|
74 annotations = self.client.annotate(fname) |
|
75 locker.unlock() |
|
76 for annotation in annotations: |
|
77 self.__generateItem(annotation["revision"].number, |
|
78 annotation["author"], annotation["number"] + 1, annotation["line"]) |
|
79 except pysvn.ClientError, e: |
|
80 locker.unlock() |
|
81 self.__showError(e.args[0]+'\n') |
|
82 self.__finish() |
|
83 os.chdir(cwd) |
|
84 |
|
85 def __finish(self): |
|
86 """ |
|
87 Private slot called when the process finished or the user pressed the button. |
|
88 """ |
|
89 self.buttonBox.button(QDialogButtonBox.Close).setEnabled(True) |
|
90 self.buttonBox.button(QDialogButtonBox.Cancel).setEnabled(False) |
|
91 self.buttonBox.button(QDialogButtonBox.Close).setDefault(True) |
|
92 |
|
93 self.blameList.doItemsLayout() |
|
94 self.__resizeColumns() |
|
95 |
|
96 self._cancel() |
|
97 |
|
98 def on_buttonBox_clicked(self, button): |
|
99 """ |
|
100 Private slot called by a button of the button box clicked. |
|
101 |
|
102 @param button button that was clicked (QAbstractButton) |
|
103 """ |
|
104 if button == self.buttonBox.button(QDialogButtonBox.Close): |
|
105 self.close() |
|
106 elif button == self.buttonBox.button(QDialogButtonBox.Cancel): |
|
107 self.__finish() |
|
108 |
|
109 def __resizeColumns(self): |
|
110 """ |
|
111 Private method to resize the list columns. |
|
112 """ |
|
113 self.blameList.header().resizeSections(QHeaderView.ResizeToContents) |
|
114 self.blameList.header().setStretchLastSection(True) |
|
115 |
|
116 def __generateItem(self, revision, author, lineno, text): |
|
117 """ |
|
118 Private method to generate a tag item in the taglist. |
|
119 |
|
120 @param revision revision string (integer) |
|
121 @param author author of the tag (string) |
|
122 @param lineno line number (integer) |
|
123 @param text text of the line (string) |
|
124 """ |
|
125 itm = QTreeWidgetItem(self.blameList, |
|
126 ["%d" % revision, author, "%d" % lineno, text]) |
|
127 itm.setTextAlignment(0, Qt.AlignRight) |
|
128 itm.setTextAlignment(2, Qt.AlignRight) |
|
129 |
|
130 def __showError(self, msg): |
|
131 """ |
|
132 Private slot to show an error message. |
|
133 |
|
134 @param msg error message to show (string) |
|
135 """ |
|
136 self.errorGroup.show() |
|
137 self.errors.insertPlainText(msg) |
|
138 self.errors.ensureCursorVisible() |