|
1 # -*- coding: utf-8 -*- |
|
2 |
|
3 # Copyright (c) 2011 Detlev Offenbach <detlev@die-offenbachs.de> |
|
4 # |
|
5 |
|
6 """ |
|
7 Module implementing a dialog to show the commit message of the current patch. |
|
8 """ |
|
9 |
|
10 import os |
|
11 |
|
12 from PyQt4.QtCore import QProcess, QTimer, Qt |
|
13 from PyQt4.QtGui import QDialog, QDialogButtonBox |
|
14 |
|
15 from E5Gui import E5MessageBox |
|
16 |
|
17 from .Ui_HgQueuesHeaderDialog import Ui_HgQueuesHeaderDialog |
|
18 |
|
19 import Preferences |
|
20 |
|
21 |
|
22 class HgQueuesHeaderDialog(QDialog, Ui_HgQueuesHeaderDialog): |
|
23 """ |
|
24 Class implementing a dialog to show the commit message of the current patch. |
|
25 """ |
|
26 def __init__(self, vcs, parent=None): |
|
27 """ |
|
28 Constructor |
|
29 |
|
30 @param vcs reference to the vcs object |
|
31 @param parent reference to the parent widget (QWidget) |
|
32 """ |
|
33 QDialog.__init__(self, parent) |
|
34 self.setupUi(self) |
|
35 |
|
36 self.buttonBox.button(QDialogButtonBox.Close).setEnabled(False) |
|
37 self.buttonBox.button(QDialogButtonBox.Cancel).setDefault(True) |
|
38 |
|
39 self.process = QProcess() |
|
40 self.vcs = vcs |
|
41 |
|
42 self.process.finished.connect(self.__procFinished) |
|
43 self.process.readyReadStandardOutput.connect(self.__readStdout) |
|
44 self.process.readyReadStandardError.connect(self.__readStderr) |
|
45 |
|
46 def closeEvent(self, e): |
|
47 """ |
|
48 Private slot implementing a close event handler. |
|
49 |
|
50 @param e close event (QCloseEvent) |
|
51 """ |
|
52 if self.process is not None and \ |
|
53 self.process.state() != QProcess.NotRunning: |
|
54 self.process.terminate() |
|
55 QTimer.singleShot(2000, self.process.kill) |
|
56 self.process.waitForFinished(3000) |
|
57 |
|
58 e.accept() |
|
59 |
|
60 def start(self, path): |
|
61 """ |
|
62 Public slot to start the list command. |
|
63 |
|
64 @param path name of directory to be listed (string) |
|
65 """ |
|
66 self.activateWindow() |
|
67 |
|
68 dname, fname = self.vcs.splitPath(path) |
|
69 |
|
70 # find the root of the repo |
|
71 repodir = dname |
|
72 while not os.path.isdir(os.path.join(repodir, self.vcs.adminDir)): |
|
73 repodir = os.path.dirname(repodir) |
|
74 if repodir == os.sep: |
|
75 return |
|
76 |
|
77 args = [] |
|
78 args.append('qheader') |
|
79 |
|
80 self.process.kill() |
|
81 self.process.setWorkingDirectory(repodir) |
|
82 |
|
83 self.process.start('hg', args) |
|
84 procStarted = self.process.waitForStarted() |
|
85 if not procStarted: |
|
86 E5MessageBox.critical(self, |
|
87 self.trUtf8('Process Generation Error'), |
|
88 self.trUtf8( |
|
89 'The process {0} could not be started. ' |
|
90 'Ensure, that it is in the search path.' |
|
91 ).format('hg')) |
|
92 |
|
93 def __finish(self): |
|
94 """ |
|
95 Private slot called when the process finished or the user pressed the button. |
|
96 """ |
|
97 if self.process is not None and \ |
|
98 self.process.state() != QProcess.NotRunning: |
|
99 self.process.terminate() |
|
100 QTimer.singleShot(2000, self.process.kill) |
|
101 self.process.waitForFinished(3000) |
|
102 |
|
103 self.buttonBox.button(QDialogButtonBox.Close).setEnabled(True) |
|
104 self.buttonBox.button(QDialogButtonBox.Cancel).setEnabled(False) |
|
105 self.buttonBox.button(QDialogButtonBox.Close).setDefault(True) |
|
106 self.buttonBox.button(QDialogButtonBox.Close).setFocus(Qt.OtherFocusReason) |
|
107 |
|
108 self.process = None |
|
109 |
|
110 def on_buttonBox_clicked(self, button): |
|
111 """ |
|
112 Private slot called by a button of the button box clicked. |
|
113 |
|
114 @param button button that was clicked (QAbstractButton) |
|
115 """ |
|
116 if button == self.buttonBox.button(QDialogButtonBox.Close): |
|
117 self.close() |
|
118 elif button == self.buttonBox.button(QDialogButtonBox.Cancel): |
|
119 self.__finish() |
|
120 |
|
121 def __procFinished(self, exitCode, exitStatus): |
|
122 """ |
|
123 Private slot connected to the finished signal. |
|
124 |
|
125 @param exitCode exit code of the process (integer) |
|
126 @param exitStatus exit status of the process (QProcess.ExitStatus) |
|
127 """ |
|
128 self.__finish() |
|
129 |
|
130 def __readStdout(self): |
|
131 """ |
|
132 Private slot to handle the readyReadStdout signal. |
|
133 |
|
134 It reads the output of the process, formats it and inserts it into |
|
135 the contents pane. |
|
136 """ |
|
137 if self.process is not None: |
|
138 s = str(self.process.readAllStandardOutput(), |
|
139 Preferences.getSystem("IOEncoding"), |
|
140 'replace') |
|
141 self.messageEdit.appendPlainText(s) |
|
142 |
|
143 def __readStderr(self): |
|
144 """ |
|
145 Private slot to handle the readyReadStderr signal. |
|
146 |
|
147 It reads the error output of the process and inserts it into the |
|
148 error pane. |
|
149 """ |
|
150 if self.process is not None: |
|
151 s = str(self.process.readAllStandardError(), |
|
152 Preferences.getSystem("IOEncoding"), |
|
153 'replace') |
|
154 self.messageEdit.appendPlainText(self.trUtf8("Error: ")) |
|
155 self.messageEdit.appendPlainText(s) |