4 # |
4 # |
5 |
5 |
6 """ |
6 """ |
7 Module implementing a dialog to show the output of the packager process. |
7 Module implementing a dialog to show the output of the packager process. |
8 """ |
8 """ |
|
9 |
|
10 from __future__ import unicode_literals # __IGNORE_WARNING__ |
|
11 try: |
|
12 str = unicode # __IGNORE_WARNING__ |
|
13 except (NameError): |
|
14 pass |
9 |
15 |
10 import os.path |
16 import os.path |
11 |
17 |
12 from PyQt4.QtCore import pyqtSlot, QProcess, QTimer |
18 from PyQt4.QtCore import pyqtSlot, QProcess, QTimer |
13 from PyQt4.QtGui import QDialog, QDialogButtonBox, QAbstractButton |
19 from PyQt4.QtGui import QDialog, QDialogButtonBox, QAbstractButton |
23 Module implementing a dialog to show the output of the cxfreeze process. |
29 Module implementing a dialog to show the output of the cxfreeze process. |
24 |
30 |
25 This class starts a QProcess and displays a dialog that |
31 This class starts a QProcess and displays a dialog that |
26 shows the output of the packager command process. |
32 shows the output of the packager command process. |
27 """ |
33 """ |
28 def __init__(self, cmdname, parent = None): |
34 def __init__(self, cmdname, parent=None): |
29 """ |
35 """ |
30 Constructor |
36 Constructor |
31 |
37 |
32 @param cmdname name of the packager (string) |
38 @param cmdname name of the packager (string) |
33 @param parent parent widget of this dialog (QWidget) |
39 @param parent parent widget of this dialog (QWidget) |
55 script = os.path.basename(script) |
61 script = os.path.basename(script) |
56 |
62 |
57 self.contents.clear() |
63 self.contents.clear() |
58 self.errors.clear() |
64 self.errors.clear() |
59 |
65 |
60 program = args[0] |
|
61 del args[0] |
|
62 args.append(script) |
66 args.append(script) |
63 |
67 |
64 self.process = QProcess() |
68 self.process = QProcess() |
65 self.process.setWorkingDirectory(dname) |
69 self.process.setWorkingDirectory(dname) |
66 |
70 |
67 self.process.readyReadStandardOutput.connect(self.__readStdout) |
71 self.process.readyReadStandardOutput.connect(self.__readStdout) |
68 self.process.readyReadStandardError.connect(self.__readStderr) |
72 self.process.readyReadStandardError.connect(self.__readStderr) |
69 self.process.finished.connect(self.__finish) |
73 self.process.finished.connect(self.__finish) |
70 |
74 |
71 self.setWindowTitle(self.trUtf8('{0} - {1}').format(self.cmdname, script)) |
75 self.setWindowTitle(self.trUtf8('{0} - {1}').format(self.cmdname, script)) |
72 self.contents.insertPlainText(' '.join(args) + '\n') |
76 self.contents.insertPlainText(' '.join(args) + '\n\n') |
73 self.contents.ensureCursorVisible() |
77 self.contents.ensureCursorVisible() |
74 |
78 |
|
79 program = args.pop(0) |
75 self.process.start(program, args) |
80 self.process.start(program, args) |
76 procStarted = self.process.waitForStarted() |
81 procStarted = self.process.waitForStarted() |
77 if not procStarted: |
82 if not procStarted: |
78 E5MessageBox.critical(None, |
83 E5MessageBox.critical(None, |
79 self.trUtf8('Process Generation Error'), |
84 self.trUtf8('Process Generation Error'), |
118 self.trUtf8('\n{0} finished.\n').format(self.cmdname)) |
123 self.trUtf8('\n{0} finished.\n').format(self.cmdname)) |
119 self.contents.ensureCursorVisible() |
124 self.contents.ensureCursorVisible() |
120 |
125 |
121 def __readStdout(self): |
126 def __readStdout(self): |
122 """ |
127 """ |
123 Private slot to handle the readyReadStandardOutput signal. |
128 Private slot to handle the readyReadStandardOutput signal. |
124 |
129 |
125 It reads the output of the process, formats it and inserts it into |
130 It reads the output of the process, formats it and inserts it into |
126 the contents pane. |
131 the contents pane. |
127 """ |
132 """ |
128 self.process.setReadChannel(QProcess.StandardOutput) |
133 self.process.setReadChannel(QProcess.StandardOutput) |
129 |
134 |
130 while self.process.canReadLine(): |
135 while self.process.canReadLine(): |
131 s = str(self.process.readAllStandardOutput(), |
136 s = str(self.process.readAllStandardOutput(), |
132 Preferences.getSystem("IOEncoding"), |
137 Preferences.getSystem("IOEncoding"), |
133 'replace') |
138 'replace') |
134 self.contents.insertPlainText(s) |
139 self.contents.insertPlainText(s) |
135 self.contents.ensureCursorVisible() |
140 self.contents.ensureCursorVisible() |
136 |
141 |
137 def __readStderr(self): |
142 def __readStderr(self): |
138 """ |
143 """ |
139 Private slot to handle the readyReadStandardError signal. |
144 Private slot to handle the readyReadStandardError signal. |
140 |
145 |
141 It reads the error output of the process and inserts it into the |
146 It reads the error output of the process and inserts it into the |
142 error pane. |
147 error pane. |
143 """ |
148 """ |
144 self.process.setReadChannel(QProcess.StandardError) |
149 self.process.setReadChannel(QProcess.StandardError) |
145 |
150 |
146 while self.process.canReadLine(): |
151 while self.process.canReadLine(): |
147 self.errorGroup.show() |
152 self.errorGroup.show() |
148 s = str(self.process.readAllStandardError(), |
153 s = str(self.process.readAllStandardError(), |
149 Preferences.getSystem("IOEncoding"), |
154 Preferences.getSystem("IOEncoding"), |
150 'replace') |
155 'replace') |
151 self.errors.insertPlainText(s) |
156 self.errors.insertPlainText(s) |
152 self.errors.ensureCursorVisible() |
157 self.errors.ensureCursorVisible() |