Plugins/VcsPlugins/vcsPySvn/SvnPropListDialog.py

changeset 0
de9c2efb9d02
child 12
1d8dd9706f46
equal deleted inserted replaced
-1:000000000000 0:de9c2efb9d02
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 proplist command process.
8 """
9
10 import os
11 import types
12
13 import pysvn
14
15 from PyQt4.QtCore import *
16 from PyQt4.QtGui import *
17
18 from SvnDialogMixin import SvnDialogMixin
19 from Ui_SvnPropListDialog import Ui_SvnPropListDialog
20
21 class SvnPropListDialog(QWidget, SvnDialogMixin, Ui_SvnPropListDialog):
22 """
23 Class implementing a dialog to show the output of the svn proplist command process.
24 """
25 def __init__(self, vcs, parent = None):
26 """
27 Constructor
28
29 @param vcs reference to the vcs object
30 @param parent parent widget (QWidget)
31 """
32 QWidget.__init__(self, parent)
33 self.setupUi(self)
34 SvnDialogMixin.__init__(self)
35
36 self.buttonBox.button(QDialogButtonBox.Close).setEnabled(False)
37 self.buttonBox.button(QDialogButtonBox.Cancel).setDefault(True)
38
39 self.vcs = vcs
40
41 self.propsList.headerItem().setText(self.propsList.columnCount(), "")
42 self.propsList.header().setSortIndicator(0, Qt.AscendingOrder)
43
44 self.client = self.vcs.getClient()
45 self.client.callback_cancel = \
46 self._clientCancelCallback
47 self.client.callback_get_login = \
48 self._clientLoginCallback
49 self.client.callback_ssl_server_trust_prompt = \
50 self._clientSslServerTrustPromptCallback
51
52 def __resort(self):
53 """
54 Private method to resort the tree.
55 """
56 self.propsList.sortItems(self.propsList.sortColumn(),
57 self.propsList.header().sortIndicatorOrder())
58
59 def __resizeColumns(self):
60 """
61 Private method to resize the list columns.
62 """
63 self.propsList.header().resizeSections(QHeaderView.ResizeToContents)
64 self.propsList.header().setStretchLastSection(True)
65
66 def __generateItem(self, path, propName, propValue):
67 """
68 Private method to generate a properties item in the properties list.
69
70 @param path file/directory name the property applies to (string)
71 @param propName name of the property (string)
72 @param propValue value of the property (string)
73 """
74 QTreeWidgetItem(self.propsList, [path, propName, propValue])
75
76 def start(self, fn, recursive = False):
77 """
78 Public slot to start the svn status command.
79
80 @param fn filename(s) (string or list of strings)
81 @param recursive flag indicating a recursive list is requested
82 """
83 self.errorGroup.hide()
84
85 QApplication.processEvents()
86 self.propsFound = False
87 if type(fn) is types.ListType:
88 dname, fnames = self.vcs.splitPathList(fn)
89 else:
90 dname, fname = self.vcs.splitPath(fn)
91 fnames = [fname]
92
93 locker = QMutexLocker(self.vcs.vcsExecutionMutex)
94 cwd = os.getcwd()
95 os.chdir(dname)
96 try:
97 for name in fnames:
98 proplist = self.client.proplist(name, recurse = recursive)
99 counter = 0
100 for path, prop in proplist:
101 for propName, propVal in prop.items():
102 self.__generateItem(path, propName, propVal)
103 self.propsFound = True
104 counter += 1
105 if counter == 30:
106 # check for cancel every 30 items
107 counter = 0
108 if self._clientCancelCallback():
109 break
110 if self._clientCancelCallback():
111 break
112 except pysvn.ClientError, e:
113 self.__showError(e.args[0])
114 locker.unlock()
115 self.__finish()
116 os.chdir(cwd)
117
118 def __finish(self):
119 """
120 Private slot called when the process finished or the user pressed the button.
121 """
122 if not self.propsFound:
123 self.__generateItem("", self.trUtf8("None"), "")
124
125 self.__resort()
126 self.__resizeColumns()
127
128 self.buttonBox.button(QDialogButtonBox.Close).setEnabled(True)
129 self.buttonBox.button(QDialogButtonBox.Cancel).setEnabled(False)
130 self.buttonBox.button(QDialogButtonBox.Close).setDefault(True)
131
132 self._cancel()
133
134 def on_buttonBox_clicked(self, button):
135 """
136 Private slot called by a button of the button box clicked.
137
138 @param button button that was clicked (QAbstractButton)
139 """
140 if button == self.buttonBox.button(QDialogButtonBox.Close):
141 self.close()
142 elif button == self.buttonBox.button(QDialogButtonBox.Cancel):
143 self.__finish()
144
145 def __showError(self, msg):
146 """
147 Private slot to show an error message.
148
149 @param msg error message to show (string)
150 """
151 self.errorGroup.show()
152 self.errors.insertPlainText(msg)
153 self.errors.ensureCursorVisible()

eric ide

mercurial