Plugins/VcsPlugins/vcsPySvn/SvnDialog.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 a pysvn action.
8 """
9
10 import os
11
12 import pysvn
13
14 from PyQt4.QtCore import *
15 from PyQt4.QtGui import *
16
17 from SvnConst import svnNotifyActionMap
18
19 from SvnDialogMixin import SvnDialogMixin
20 from Ui_SvnDialog import Ui_SvnDialog
21
22 import Preferences
23
24 class SvnDialog(QDialog, SvnDialogMixin, Ui_SvnDialog):
25 """
26 Class implementing a dialog to show the output of a pysvn action.
27 """
28 def __init__(self, text, command, pysvnClient, parent = None, log = ""):
29 """
30 Constructor
31
32 @param text text to be shown by the label (string)
33 @param command svn command to be executed (display purposes only)
34 (string)
35 @param pysvnClient reference to the pysvn client object (pysvn.Client)
36 @keyparam parent parent widget (QWidget)
37 @keyparam log optional log message (string)
38 """
39 QDialog.__init__(self, parent)
40 self.setupUi(self)
41 SvnDialogMixin.__init__(self, log)
42
43 self.buttonBox.button(QDialogButtonBox.Close).setEnabled(False)
44 self.buttonBox.button(QDialogButtonBox.Cancel).setDefault(True)
45
46 self.outputGroup.setTitle(text)
47 self.errorGroup.hide()
48
49 pysvnClient.callback_cancel = \
50 self._clientCancelCallback
51
52 pysvnClient.callback_notify = \
53 self._clientNotifyCallback
54 pysvnClient.callback_get_login = \
55 self._clientLoginCallback
56 pysvnClient.callback_ssl_server_trust_prompt = \
57 self._clientSslServerTrustPromptCallback
58 pysvnClient.callback_get_log_message = \
59 self._clientLogCallback
60
61 self.__hasAddOrDelete = False
62
63 if command:
64 self.resultbox.append(command)
65 self.resultbox.append('')
66
67 self.show()
68 QApplication.processEvents()
69
70 def _clientNotifyCallback(self, eventDict):
71 """
72 Protected method called by the client to send events
73
74 @param eventDict dictionary containing the notification event
75 """
76 msg = ""
77 if eventDict["action"] == pysvn.wc_notify_action.update_completed:
78 msg = self.trUtf8("Revision {0}.\n").format(eventDict["revision"].number)
79 elif eventDict["path"] != "" and \
80 svnNotifyActionMap[eventDict["action"]] is not None:
81 mime = eventDict["mime_type"] == "application/octet-stream" and \
82 self.trUtf8(" (binary)") or ""
83 msg = self.trUtf8("{0} {1}{2}\n")\
84 .format(self.trUtf8(svnNotifyActionMap[eventDict["action"]]),
85 eventDict["path"],
86 mime)
87 if eventDict["action"] in \
88 [pysvn.wc_notify_action.add, pysvn.wc_notify_action.commit_added,
89 pysvn.wc_notify_action.commit_deleted, pysvn.wc_notify_action.delete,
90 pysvn.wc_notify_action.update_add, pysvn.wc_notify_action.update_delete]:
91 self.__hasAddOrDelete = True
92 if msg:
93 self.showMessage(msg)
94
95 def showMessage(self, msg):
96 """
97 Public slot to show a message.
98
99 @param msg message to show (string)
100 """
101 self.resultbox.insertPlainText(msg)
102 self.resultbox.ensureCursorVisible()
103 QApplication.processEvents()
104
105 def showError(self, msg):
106 """
107 Public slot to show an error message.
108
109 @param msg error message to show (string)
110 """
111 self.errorGroup.show()
112 self.errors.insertPlainText(msg)
113 self.errors.ensureCursorVisible()
114 QApplication.processEvents()
115
116 def finish(self):
117 """
118 Public slot called when the process finished or the user pressed the button.
119 """
120 self.buttonBox.button(QDialogButtonBox.Close).setEnabled(True)
121 self.buttonBox.button(QDialogButtonBox.Cancel).setEnabled(False)
122 self.buttonBox.button(QDialogButtonBox.Close).setDefault(True)
123
124 self._cancel()
125
126 if Preferences.getVCS("AutoClose"):
127 self.accept()
128
129 def on_buttonBox_clicked(self, button):
130 """
131 Private slot called by a button of the button box clicked.
132
133 @param button button that was clicked (QAbstractButton)
134 """
135 if button == self.buttonBox.button(QDialogButtonBox.Close):
136 self.close()
137 elif button == self.buttonBox.button(QDialogButtonBox.Cancel):
138 self.finish()
139
140 def hasAddOrDelete(self):
141 """
142 Public method to check, if the last action contained an add or delete.
143 """
144 return self.__hasAddOrDelete

eric ide

mercurial