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