eric6/Plugins/VcsPlugins/vcsPySvn/SvnPropListDialog.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 proplist command
8 process.
9 """
10
11 from __future__ import unicode_literals
12
13 import os
14 import sys
15
16 import pysvn
17
18 from PyQt5.QtCore import pyqtSlot, QMutexLocker, Qt
19 from PyQt5.QtWidgets import QWidget, QHeaderView, QApplication, \
20 QDialogButtonBox, QTreeWidgetItem
21
22 from .SvnDialogMixin import SvnDialogMixin
23 from .Ui_SvnPropListDialog import Ui_SvnPropListDialog
24
25
26 class SvnPropListDialog(QWidget, SvnDialogMixin, Ui_SvnPropListDialog):
27 """
28 Class implementing a dialog to show the output of the svn proplist command
29 process.
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(SvnPropListDialog, self).__init__(parent)
39 self.setupUi(self)
40 SvnDialogMixin.__init__(self)
41
42 self.refreshButton = \
43 self.buttonBox.addButton(self.tr("Refresh"),
44 QDialogButtonBox.ActionRole)
45 self.refreshButton.setToolTip(
46 self.tr("Press to refresh the properties display"))
47 self.refreshButton.setEnabled(False)
48 self.buttonBox.button(QDialogButtonBox.Close).setEnabled(False)
49 self.buttonBox.button(QDialogButtonBox.Cancel).setDefault(True)
50
51 self.vcs = vcs
52
53 self.propsList.headerItem().setText(self.propsList.columnCount(), "")
54 self.propsList.header().setSortIndicator(0, Qt.AscendingOrder)
55
56 self.client = self.vcs.getClient()
57 self.client.callback_cancel = \
58 self._clientCancelCallback
59 self.client.callback_get_login = \
60 self._clientLoginCallback
61 self.client.callback_ssl_server_trust_prompt = \
62 self._clientSslServerTrustPromptCallback
63
64 def __resort(self):
65 """
66 Private method to resort the tree.
67 """
68 self.propsList.sortItems(
69 self.propsList.sortColumn(),
70 self.propsList.header().sortIndicatorOrder())
71
72 def __resizeColumns(self):
73 """
74 Private method to resize the list columns.
75 """
76 self.propsList.header().resizeSections(QHeaderView.ResizeToContents)
77 self.propsList.header().setStretchLastSection(True)
78
79 def __generateItem(self, path, propName, propValue):
80 """
81 Private method to generate a properties item in the properties list.
82
83 @param path file/directory name the property applies to (string)
84 @param propName name of the property (string)
85 @param propValue value of the property (string)
86 """
87 QTreeWidgetItem(self.propsList, [path, propName, propValue])
88
89 def start(self, fn, recursive=False):
90 """
91 Public slot to start the svn status command.
92
93 @param fn filename(s) (string or list of strings)
94 @param recursive flag indicating a recursive list is requested
95 """
96 self.errorGroup.hide()
97
98 self.propsList.clear()
99
100 self.__args = fn
101 self.__recursive = recursive
102
103 self.buttonBox.button(QDialogButtonBox.Close).setEnabled(False)
104 self.buttonBox.button(QDialogButtonBox.Cancel).setEnabled(True)
105 self.buttonBox.button(QDialogButtonBox.Cancel).setDefault(True)
106 self.refreshButton.setEnabled(False)
107
108 QApplication.processEvents()
109 self.propsFound = False
110 if isinstance(fn, list):
111 dname, fnames = self.vcs.splitPathList(fn)
112 else:
113 dname, fname = self.vcs.splitPath(fn)
114 fnames = [fname]
115
116 locker = QMutexLocker(self.vcs.vcsExecutionMutex)
117 cwd = os.getcwd()
118 os.chdir(dname)
119 try:
120 for name in fnames:
121 proplist = self.client.proplist(name, recurse=recursive)
122 counter = 0
123 for path, prop in proplist:
124 if sys.version_info[0] == 2:
125 path = path.decode('utf-8')
126 for propName, propVal in list(prop.items()):
127 if sys.version_info[0] == 2:
128 propName = propName.decode('utf-8')
129 propVal = propVal.decode('utf-8')
130 self.__generateItem(path, propName, propVal)
131 self.propsFound = True
132 counter += 1
133 if counter == 30:
134 # check for cancel every 30 items
135 counter = 0
136 if self._clientCancelCallback():
137 break
138 if self._clientCancelCallback():
139 break
140 except pysvn.ClientError as e:
141 self.__showError(e.args[0])
142 locker.unlock()
143 self.__finish()
144 os.chdir(cwd)
145
146 def __finish(self):
147 """
148 Private slot called when the process finished or the user pressed the
149 button.
150 """
151 if not self.propsFound:
152 self.__generateItem("", self.tr("None"), "")
153
154 self.__resort()
155 self.__resizeColumns()
156
157 self.buttonBox.button(QDialogButtonBox.Close).setEnabled(True)
158 self.buttonBox.button(QDialogButtonBox.Cancel).setEnabled(False)
159 self.buttonBox.button(QDialogButtonBox.Close).setDefault(True)
160
161 self.refreshButton.setEnabled(True)
162
163 self._cancel()
164
165 def on_buttonBox_clicked(self, button):
166 """
167 Private slot called by a button of the button box clicked.
168
169 @param button button that was clicked (QAbstractButton)
170 """
171 if button == self.buttonBox.button(QDialogButtonBox.Close):
172 self.close()
173 elif button == self.buttonBox.button(QDialogButtonBox.Cancel):
174 self.__finish()
175 elif button == self.refreshButton:
176 self.on_refreshButton_clicked()
177
178 @pyqtSlot()
179 def on_refreshButton_clicked(self):
180 """
181 Private slot to refresh the status display.
182 """
183 self.start(self.__args, recursive=self.__recursive)
184
185 def __showError(self, msg):
186 """
187 Private slot to show an error message.
188
189 @param msg error message to show (string)
190 """
191 self.errorGroup.show()
192 self.errors.insertPlainText(msg)
193 self.errors.ensureCursorVisible()

eric ide

mercurial