17 |
17 |
18 |
18 |
19 class HgDialog(QDialog, Ui_HgDialog): |
19 class HgDialog(QDialog, Ui_HgDialog): |
20 """ |
20 """ |
21 Class implementing a dialog starting a process and showing its output. |
21 Class implementing a dialog starting a process and showing its output. |
22 |
22 |
23 It starts a QProcess and displays a dialog that |
23 It starts a QProcess and displays a dialog that |
24 shows the output of the process. The dialog is modal, |
24 shows the output of the process. The dialog is modal, |
25 which causes a synchronized execution of the process. |
25 which causes a synchronized execution of the process. |
26 """ |
26 """ |
|
27 |
27 def __init__(self, text, hg=None, useClient=True, parent=None): |
28 def __init__(self, text, hg=None, useClient=True, parent=None): |
28 """ |
29 """ |
29 Constructor |
30 Constructor |
30 |
31 |
31 @param text text to be shown by the label (string) |
32 @param text text to be shown by the label (string) |
32 @param hg reference to the Mercurial interface object (Hg) |
33 @param hg reference to the Mercurial interface object (Hg) |
33 @param useClient flag indicating to use the command server client |
34 @param useClient flag indicating to use the command server client |
34 if possible (boolean) |
35 if possible (boolean) |
35 @param parent parent widget (QWidget) |
36 @param parent parent widget (QWidget) |
36 """ |
37 """ |
37 super().__init__(parent) |
38 super().__init__(parent) |
38 self.setupUi(self) |
39 self.setupUi(self) |
39 self.setWindowFlags(Qt.WindowType.Window) |
40 self.setWindowFlags(Qt.WindowType.Window) |
40 |
41 |
41 self.buttonBox.button( |
42 self.buttonBox.button(QDialogButtonBox.StandardButton.Close).setEnabled(False) |
42 QDialogButtonBox.StandardButton.Close).setEnabled(False) |
43 self.buttonBox.button(QDialogButtonBox.StandardButton.Cancel).setDefault(True) |
43 self.buttonBox.button( |
44 |
44 QDialogButtonBox.StandardButton.Cancel).setDefault(True) |
45 self.username = "" |
45 |
46 self.password = "" |
46 self.username = '' |
|
47 self.password = '' |
|
48 self.vcs = hg |
47 self.vcs = hg |
49 |
48 |
50 self.outputGroup.setTitle(text) |
49 self.outputGroup.setTitle(text) |
51 |
50 |
52 self.show() |
51 self.show() |
53 QCoreApplication.processEvents() |
52 QCoreApplication.processEvents() |
54 |
53 |
55 def __finish(self): |
54 def __finish(self): |
56 """ |
55 """ |
57 Private slot called when the process finished or the user pressed |
56 Private slot called when the process finished or the user pressed |
58 the button. |
57 the button. |
59 """ |
58 """ |
60 self.buttonBox.button( |
59 self.buttonBox.button(QDialogButtonBox.StandardButton.Close).setEnabled(True) |
61 QDialogButtonBox.StandardButton.Close).setEnabled(True) |
60 self.buttonBox.button(QDialogButtonBox.StandardButton.Cancel).setEnabled(False) |
62 self.buttonBox.button( |
61 self.buttonBox.button(QDialogButtonBox.StandardButton.Close).setDefault(True) |
63 QDialogButtonBox.StandardButton.Cancel).setEnabled(False) |
62 self.buttonBox.button(QDialogButtonBox.StandardButton.Close).setFocus( |
64 self.buttonBox.button( |
63 Qt.FocusReason.OtherFocusReason |
65 QDialogButtonBox.StandardButton.Close).setDefault(True) |
64 ) |
66 self.buttonBox.button( |
65 |
67 QDialogButtonBox.StandardButton.Close).setFocus( |
|
68 Qt.FocusReason.OtherFocusReason) |
|
69 |
|
70 if ( |
66 if ( |
71 Preferences.getVCS("AutoClose") and |
67 Preferences.getVCS("AutoClose") |
72 self.normal and |
68 and self.normal |
73 self.errors.toPlainText() == "" |
69 and self.errors.toPlainText() == "" |
74 ): |
70 ): |
75 self.accept() |
71 self.accept() |
76 |
72 |
77 def on_buttonBox_clicked(self, button): |
73 def on_buttonBox_clicked(self, button): |
78 """ |
74 """ |
79 Private slot called by a button of the button box clicked. |
75 Private slot called by a button of the button box clicked. |
80 |
76 |
81 @param button button that was clicked (QAbstractButton) |
77 @param button button that was clicked (QAbstractButton) |
82 """ |
78 """ |
83 if button == self.buttonBox.button( |
79 if button == self.buttonBox.button(QDialogButtonBox.StandardButton.Close): |
84 QDialogButtonBox.StandardButton.Close |
|
85 ): |
|
86 self.close() |
80 self.close() |
87 elif button == self.buttonBox.button( |
81 elif button == self.buttonBox.button(QDialogButtonBox.StandardButton.Cancel): |
88 QDialogButtonBox.StandardButton.Cancel |
|
89 ): |
|
90 self.vcs.getClient().cancel() |
82 self.vcs.getClient().cancel() |
91 |
83 |
92 def startProcess(self, args, showArgs=True, environment=None, client=None): |
84 def startProcess(self, args, showArgs=True, environment=None, client=None): |
93 """ |
85 """ |
94 Public slot used to start the process. |
86 Public slot used to start the process. |
95 |
87 |
96 @param args list of arguments for the process |
88 @param args list of arguments for the process |
97 @type list of str |
89 @type list of str |
98 @param showArgs flag indicating to show the arguments |
90 @param showArgs flag indicating to show the arguments |
99 @type bool |
91 @type bool |
100 @param environment dictionary of environment settings to add |
92 @param environment dictionary of environment settings to add |
106 @rtype bool |
98 @rtype bool |
107 """ |
99 """ |
108 self.errorGroup.hide() |
100 self.errorGroup.hide() |
109 self.inputGroup.hide() |
101 self.inputGroup.hide() |
110 self.normal = False |
102 self.normal = False |
111 |
103 |
112 self.__hasAddOrDelete = False |
104 self.__hasAddOrDelete = False |
113 if ( |
105 if args[0] in [ |
114 args[0] in ["qpush", "qpop", "qgoto", "rebase", |
106 "qpush", |
115 "update", "import", "revert", "graft", "shelve", |
107 "qpop", |
116 "unshelve", "strip", "histedit"] or |
108 "qgoto", |
117 (args[0] in ["pull", "unbundle"] and |
109 "rebase", |
118 ("--update" in args[1:] or "--rebase" in args[1:])) |
110 "update", |
|
111 "import", |
|
112 "revert", |
|
113 "graft", |
|
114 "shelve", |
|
115 "unshelve", |
|
116 "strip", |
|
117 "histedit", |
|
118 ] or ( |
|
119 args[0] in ["pull", "unbundle"] |
|
120 and ("--update" in args[1:] or "--rebase" in args[1:]) |
119 ): |
121 ): |
120 self.__updateCommand = True |
122 self.__updateCommand = True |
121 else: |
123 else: |
122 self.__updateCommand = False |
124 self.__updateCommand = False |
123 |
125 |
124 if showArgs: |
126 if showArgs: |
125 self.resultbox.append(' '.join(args)) |
127 self.resultbox.append(" ".join(args)) |
126 self.resultbox.append('') |
128 self.resultbox.append("") |
127 |
129 |
128 if client is None: |
130 if client is None: |
129 client = self.vcs.getClient() |
131 client = self.vcs.getClient() |
130 out, err = client.runcommand( |
132 out, err = client.runcommand( |
131 args, |
133 args, |
132 prompt=self.__getInput, |
134 prompt=self.__getInput, |
133 output=self.__showOutput, |
135 output=self.__showOutput, |
134 error=self.__showError |
136 error=self.__showError, |
135 ) |
137 ) |
136 |
138 |
137 if err: |
139 if err: |
138 self.__showError(err) |
140 self.__showError(err) |
139 if out: |
141 if out: |
140 self.__showOutput(out) |
142 self.__showOutput(out) |
141 |
143 |
142 self.normal = True |
144 self.normal = True |
143 |
145 |
144 self.__finish() |
146 self.__finish() |
145 |
147 |
146 return True |
148 return True |
147 |
149 |
148 def normalExit(self): |
150 def normalExit(self): |
149 """ |
151 """ |
150 Public method to check for a normal process termination. |
152 Public method to check for a normal process termination. |
151 |
153 |
152 @return flag indicating normal process termination (boolean) |
154 @return flag indicating normal process termination (boolean) |
153 """ |
155 """ |
154 return self.normal |
156 return self.normal |
155 |
157 |
156 def normalExitWithoutErrors(self): |
158 def normalExitWithoutErrors(self): |
157 """ |
159 """ |
158 Public method to check for a normal process termination without |
160 Public method to check for a normal process termination without |
159 error messages. |
161 error messages. |
160 |
162 |
161 @return flag indicating normal process termination (boolean) |
163 @return flag indicating normal process termination (boolean) |
162 """ |
164 """ |
163 return self.normal and self.errors.toPlainText() == "" |
165 return self.normal and self.errors.toPlainText() == "" |
164 |
166 |
165 def __showOutput(self, out): |
167 def __showOutput(self, out): |
166 """ |
168 """ |
167 Private slot to show some output. |
169 Private slot to show some output. |
168 |
170 |
169 @param out output to be shown (string) |
171 @param out output to be shown (string) |
170 """ |
172 """ |
171 self.resultbox.insertPlainText(Utilities.filterAnsiSequences(out)) |
173 self.resultbox.insertPlainText(Utilities.filterAnsiSequences(out)) |
172 self.resultbox.ensureCursorVisible() |
174 self.resultbox.ensureCursorVisible() |
173 |
175 |
174 # check for a changed project file |
176 # check for a changed project file |
175 if self.__updateCommand: |
177 if self.__updateCommand: |
176 for line in out.splitlines(): |
178 for line in out.splitlines(): |
177 if ( |
179 if ".epj" in line or ".e4p" in line: |
178 '.epj' in line or |
|
179 '.e4p' in line |
|
180 ): |
|
181 self.__hasAddOrDelete = True |
180 self.__hasAddOrDelete = True |
182 break |
181 break |
183 |
182 |
184 QCoreApplication.processEvents() |
183 QCoreApplication.processEvents() |
185 |
184 |
186 def __showError(self, out): |
185 def __showError(self, out): |
187 """ |
186 """ |
188 Private slot to show some error. |
187 Private slot to show some error. |
189 |
188 |
190 @param out error to be shown (string) |
189 @param out error to be shown (string) |
191 """ |
190 """ |
192 self.errorGroup.show() |
191 self.errorGroup.show() |
193 self.errors.insertPlainText(Utilities.filterAnsiSequences(out)) |
192 self.errors.insertPlainText(Utilities.filterAnsiSequences(out)) |
194 self.errors.ensureCursorVisible() |
193 self.errors.ensureCursorVisible() |
195 |
194 |
196 QCoreApplication.processEvents() |
195 QCoreApplication.processEvents() |
197 |
196 |
198 def hasAddOrDelete(self): |
197 def hasAddOrDelete(self): |
199 """ |
198 """ |
200 Public method to check, if the last action contained an add or delete. |
199 Public method to check, if the last action contained an add or delete. |
201 |
200 |
202 @return flag indicating the presence of an add or delete (boolean) |
201 @return flag indicating the presence of an add or delete (boolean) |
203 """ |
202 """ |
204 return self.__hasAddOrDelete |
203 return self.__hasAddOrDelete |
205 |
204 |
206 def __getInput(self, size, message): |
205 def __getInput(self, size, message): |
207 """ |
206 """ |
208 Private method to get some input from the user. |
207 Private method to get some input from the user. |
209 |
208 |
210 @param size maximum length of the requested input |
209 @param size maximum length of the requested input |
211 @type int |
210 @type int |
212 @param message message sent by the server |
211 @param message message sent by the server |
213 @type str |
212 @type str |
214 @return tuple containing data entered by the user and |
213 @return tuple containing data entered by the user and |
219 self.input.setMaxLength(size) |
218 self.input.setMaxLength(size) |
220 self.input.setFocus(Qt.FocusReason.OtherFocusReason) |
219 self.input.setFocus(Qt.FocusReason.OtherFocusReason) |
221 |
220 |
222 self.resultbox.ensureCursorVisible() |
221 self.resultbox.ensureCursorVisible() |
223 self.errors.ensureCursorVisible() |
222 self.errors.ensureCursorVisible() |
224 |
223 |
225 from PyQt6.QtCore import QEventLoop |
224 from PyQt6.QtCore import QEventLoop |
|
225 |
226 loop = QEventLoop(self) |
226 loop = QEventLoop(self) |
227 self.sendButton.clicked[bool].connect(loop.quit) |
227 self.sendButton.clicked[bool].connect(loop.quit) |
228 self.input.returnPressed.connect(loop.quit) |
228 self.input.returnPressed.connect(loop.quit) |
229 loop.exec() |
229 loop.exec() |
230 message = self.input.text() + "\n" |
230 message = self.input.text() + "\n" |
231 isPassword = self.passwordCheckBox.isChecked() |
231 isPassword = self.passwordCheckBox.isChecked() |
232 |
232 |
233 self.input.clear() |
233 self.input.clear() |
234 self.inputGroup.hide() |
234 self.inputGroup.hide() |
235 |
235 |
236 return message, isPassword |
236 return message, isPassword |