1
# -*- coding: utf-8 -*-
3
# Copyright (c) 2002 - 2007 Detlev Offenbach <detlev@die-offenbachs.de>
7
Module implementing a dialog starting a process and showing its output.
12
from PyQt4.QtCore import *
13
from PyQt4.QtGui import *
15
from KdeQt import KQMessageBox
17
from Ui_CvsDialog import Ui_CvsDialog
21
class CvsDialog(QDialog, Ui_CvsDialog):
23
Module implementing a dialog starting a process and showing its output.
25
It starts a QProcess and display a dialog that
26
shows the output of the process. The dialog is modal,
27
which causes a synchronized execution of the process.
29
def __init__(self, text, parent = None):
33
@param text text to be shown by the label (string or QString)
34
@param parent parent widget (QWidget)
36
QDialog.__init__(self, parent)
39
self.buttonBox.button(QDialogButtonBox.Close).setEnabled(False)
40
self.buttonBox.button(QDialogButtonBox.Cancel).setDefault(True)
46
self.outputGroup.setTitle(text)
50
Private slot called when the process finished or the user pressed the button.
52
if self.proc is not None and \
53
self.proc.state() != QProcess.NotRunning:
55
QTimer.singleShot(2000, self.proc, SLOT('kill()'))
56
self.proc.waitForFinished(3000)
58
self.buttonBox.button(QDialogButtonBox.Close).setEnabled(True)
59
self.buttonBox.button(QDialogButtonBox.Cancel).setEnabled(False)
60
self.buttonBox.button(QDialogButtonBox.Close).setDefault(True)
62
self.inputGroup.setEnabled(False)
66
if Preferences.getVCS("AutoClose") and \
68
not self.errors.length() > 0:
71
def on_buttonBox_clicked(self, button):
73
Private slot called by a button of the button box clicked.
75
@param button button that was clicked (QAbstractButton)
77
if button == self.buttonBox.button(QDialogButtonBox.Close):
79
elif button == self.buttonBox.button(QDialogButtonBox.Cancel):
82
def __procFinished(self, exitCode, exitStatus):
84
Private slot connected to the finished signal.
86
@param exitCode exit code of the process (integer)
87
@param exitStatus exit status of the process (QProcess.ExitStatus)
89
self.normal = exitStatus == QProcess.NormalExit
92
def startProcess(self, args, workingDir = None):
94
Public slot used to start the process.
96
@param args list of arguments for the process (QStringList)
97
@param workingDir working directory for the process (string or QString)
98
@return flag indicating a successful start of the process
101
self.intercept = False
103
self.proc = QProcess()
105
self.resultbox.append(args.join(' '))
106
self.resultbox.append('')
108
self.connect(self.proc, SIGNAL('finished(int, QProcess::ExitStatus)'),
110
self.connect(self.proc, SIGNAL('readyReadStandardOutput()'),
112
self.connect(self.proc, SIGNAL('readyReadStandardError()'),
116
self.proc.setWorkingDirectory(workingDir)
117
self.proc.start('cvs', args)
118
procStarted = self.proc.waitForStarted()
120
self.button.setFocus()
121
self.inputGroup.setEnabled(False)
122
KQMessageBox.critical(None,
123
self.trUtf8('Process Generation Error'),
125
'The process %1 could not be started. '
126
'Ensure, that it is in the search path.'
129
self.inputGroup.setEnabled(True)
132
def normalExit(self):
134
Public method to check for a normal process termination.
136
@return flag indicating normal process termination (boolean)
140
def __readStdout(self):
142
Private slot to handle the readyReadStdout signal.
144
It reads the output of the process, formats it and inserts it into
147
if self.proc is not None:
148
s = QString(self.proc.readAllStandardOutput())
149
self.resultbox.insertPlainText(s)
150
self.resultbox.ensureCursorVisible()
152
def __readStderr(self):
154
Private slot to handle the readyReadStderr signal.
156
It reads the error output of the process and inserts it into the
159
if self.proc is not None:
160
s = QString(self.proc.readAllStandardError())
161
self.errors.insertPlainText(s)
162
self.errors.ensureCursorVisible()
164
def on_passwordCheckBox_toggled(self, isOn):
166
Private slot to handle the password checkbox toggled.
168
@param isOn flag indicating the status of the check box (boolean)
171
self.input.setEchoMode(QLineEdit.Password)
173
self.input.setEchoMode(QLineEdit.Normal)
176
def on_sendButton_clicked(self):
178
Private slot to send the input to the subversion process.
180
input = self.input.text()
181
input.append(os.linesep)
183
if self.passwordCheckBox.isChecked():
184
self.errors.insertPlainText(os.linesep)
185
self.errors.ensureCursorVisible()
187
self.errors.insertPlainText(input)
188
self.errors.ensureCursorVisible()
190
self.proc.write(input.toLocal8Bit())
192
self.passwordCheckBox.setChecked(False)
195
def on_input_returnPressed(self):
197
Private slot to handle the press of the return key in the input field.
199
self.intercept = True
200
self.on_sendButton_clicked()
202
def keyPressEvent(self, evt):
204
Protected slot to handle a key press event.
206
@param evt the key press event (QKeyEvent)
209
self.intercept = False
212
QDialog.keyPressEvent(self, evt)