8 """ |
8 """ |
9 |
9 |
10 |
10 |
11 import os |
11 import os |
12 |
12 |
13 from PyQt5.QtCore import QProcess, QTimer, Qt, QCoreApplication |
13 from PyQt5.QtCore import Qt, QCoreApplication |
14 from PyQt5.QtWidgets import QDialog, QDialogButtonBox |
14 from PyQt5.QtWidgets import QDialog, QDialogButtonBox |
15 |
|
16 from E5Gui import E5MessageBox |
|
17 |
15 |
18 from .Ui_HgQueuesHeaderDialog import Ui_HgQueuesHeaderDialog |
16 from .Ui_HgQueuesHeaderDialog import Ui_HgQueuesHeaderDialog |
19 |
17 |
20 import Utilities |
18 import Utilities |
21 |
19 |
39 self.buttonBox.button(QDialogButtonBox.Cancel).setDefault(True) |
37 self.buttonBox.button(QDialogButtonBox.Cancel).setDefault(True) |
40 |
38 |
41 self.vcs = vcs |
39 self.vcs = vcs |
42 self.__hgClient = vcs.getClient() |
40 self.__hgClient = vcs.getClient() |
43 |
41 |
44 if self.__hgClient: |
|
45 self.process = None |
|
46 else: |
|
47 self.process = QProcess() |
|
48 self.process.finished.connect(self.__procFinished) |
|
49 self.process.readyReadStandardOutput.connect(self.__readStdout) |
|
50 self.process.readyReadStandardError.connect(self.__readStderr) |
|
51 |
|
52 self.show() |
42 self.show() |
53 QCoreApplication.processEvents() |
43 QCoreApplication.processEvents() |
54 |
44 |
55 def closeEvent(self, e): |
45 def closeEvent(self, e): |
56 """ |
46 """ |
57 Protected slot implementing a close event handler. |
47 Protected slot implementing a close event handler. |
58 |
48 |
59 @param e close event (QCloseEvent) |
49 @param e close event (QCloseEvent) |
60 """ |
50 """ |
61 if self.__hgClient: |
51 if self.__hgClient.isExecuting(): |
62 if self.__hgClient.isExecuting(): |
52 self.__hgClient.cancel() |
63 self.__hgClient.cancel() |
|
64 else: |
|
65 if ( |
|
66 self.process is not None and |
|
67 self.process.state() != QProcess.NotRunning |
|
68 ): |
|
69 self.process.terminate() |
|
70 QTimer.singleShot(2000, self.process.kill) |
|
71 self.process.waitForFinished(3000) |
|
72 |
53 |
73 e.accept() |
54 e.accept() |
74 |
55 |
75 def start(self, path): |
56 def start(self, path): |
76 """ |
57 """ |
89 if os.path.splitdrive(repodir)[1] == os.sep: |
70 if os.path.splitdrive(repodir)[1] == os.sep: |
90 return |
71 return |
91 |
72 |
92 args = self.vcs.initCommand("qheader") |
73 args = self.vcs.initCommand("qheader") |
93 |
74 |
94 if self.__hgClient: |
75 out, err = self.__hgClient.runcommand( |
95 out, err = self.__hgClient.runcommand( |
76 args, output=self.__showOutput, error=self.__showError) |
96 args, output=self.__showOutput, error=self.__showError) |
77 if err: |
97 if err: |
78 self.__showError(err) |
98 self.__showError(err) |
79 if out: |
99 if out: |
80 self.__showOutPut(out) |
100 self.__showOutPut(out) |
81 self.__finish() |
101 self.__finish() |
|
102 else: |
|
103 self.process.kill() |
|
104 self.process.setWorkingDirectory(repodir) |
|
105 |
|
106 self.process.start('hg', args) |
|
107 procStarted = self.process.waitForStarted(5000) |
|
108 if not procStarted: |
|
109 E5MessageBox.critical( |
|
110 self, |
|
111 self.tr('Process Generation Error'), |
|
112 self.tr( |
|
113 'The process {0} could not be started. ' |
|
114 'Ensure, that it is in the search path.' |
|
115 ).format('hg')) |
|
116 |
82 |
117 def __finish(self): |
83 def __finish(self): |
118 """ |
84 """ |
119 Private slot called when the process finished or the user pressed |
85 Private slot called when the process finished or the user pressed |
120 the button. |
86 the button. |
121 """ |
87 """ |
122 if ( |
|
123 self.process is not None and |
|
124 self.process.state() != QProcess.NotRunning |
|
125 ): |
|
126 self.process.terminate() |
|
127 QTimer.singleShot(2000, self.process.kill) |
|
128 self.process.waitForFinished(3000) |
|
129 |
|
130 self.buttonBox.button(QDialogButtonBox.Close).setEnabled(True) |
88 self.buttonBox.button(QDialogButtonBox.Close).setEnabled(True) |
131 self.buttonBox.button(QDialogButtonBox.Cancel).setEnabled(False) |
89 self.buttonBox.button(QDialogButtonBox.Cancel).setEnabled(False) |
132 self.buttonBox.button(QDialogButtonBox.Close).setDefault(True) |
90 self.buttonBox.button(QDialogButtonBox.Close).setDefault(True) |
133 self.buttonBox.button(QDialogButtonBox.Close).setFocus( |
91 self.buttonBox.button(QDialogButtonBox.Close).setFocus( |
134 Qt.OtherFocusReason) |
92 Qt.OtherFocusReason) |
145 if self.__hgClient: |
103 if self.__hgClient: |
146 self.__hgClient.cancel() |
104 self.__hgClient.cancel() |
147 else: |
105 else: |
148 self.__finish() |
106 self.__finish() |
149 |
107 |
150 def __procFinished(self, exitCode, exitStatus): |
|
151 """ |
|
152 Private slot connected to the finished signal. |
|
153 |
|
154 @param exitCode exit code of the process (integer) |
|
155 @param exitStatus exit status of the process (QProcess.ExitStatus) |
|
156 """ |
|
157 self.__finish() |
|
158 |
|
159 def __readStdout(self): |
|
160 """ |
|
161 Private slot to handle the readyReadStdout signal. |
|
162 |
|
163 It reads the output of the process, formats it and inserts it into |
|
164 the contents pane. |
|
165 """ |
|
166 if self.process is not None: |
|
167 s = str(self.process.readAllStandardOutput(), |
|
168 self.vcs.getEncoding(), 'replace') |
|
169 self.__showOutput(s) |
|
170 |
|
171 def __showOutput(self, out): |
108 def __showOutput(self, out): |
172 """ |
109 """ |
173 Private slot to show some output. |
110 Private slot to show some output. |
174 |
111 |
175 @param out output to be shown (string) |
112 @param out output to be shown (string) |
176 """ |
113 """ |
177 self.messageEdit.appendPlainText(Utilities.filterAnsiSequences(out)) |
114 self.messageEdit.appendPlainText(Utilities.filterAnsiSequences(out)) |
178 |
|
179 def __readStderr(self): |
|
180 """ |
|
181 Private slot to handle the readyReadStderr signal. |
|
182 |
|
183 It reads the error output of the process and inserts it into the |
|
184 error pane. |
|
185 """ |
|
186 if self.process is not None: |
|
187 s = str(self.process.readAllStandardError(), |
|
188 self.vcs.getEncoding(), 'replace') |
|
189 self.__showError(s) |
|
190 |
115 |
191 def __showError(self, out): |
116 def __showError(self, out): |
192 """ |
117 """ |
193 Private slot to show some error. |
118 Private slot to show some error. |
194 |
119 |