~ubuntu-branches/ubuntu/karmic/eric/karmic

« back to all changes in this revision

Viewing changes to eric/VCS/vcsCVS/CvsDialog.py

  • Committer: Bazaar Package Importer
  • Author(s): Scott Kitterman
  • Date: 2008-01-28 18:02:25 UTC
  • mfrom: (1.1.4 upstream)
  • Revision ID: james.westby@ubuntu.com-20080128180225-6nrox6yrworh2c4v
Tags: 4.0.4-1ubuntu1
* Add python-qt3 to build-depends becuase that's where Ubuntu puts 
  pyqtconfig
* Change maintainer to MOTU

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
# -*- coding: utf-8 -*-
 
2
 
 
3
# Copyright (c) 2002 - 2007 Detlev Offenbach <detlev@die-offenbachs.de>
 
4
#
 
5
 
 
6
"""
 
7
Module implementing a dialog starting a process and showing its output.
 
8
"""
 
9
 
 
10
import os
 
11
 
 
12
from PyQt4.QtCore import *
 
13
from PyQt4.QtGui import *
 
14
 
 
15
from KdeQt import KQMessageBox
 
16
 
 
17
from Ui_CvsDialog import Ui_CvsDialog
 
18
 
 
19
import Preferences
 
20
 
 
21
class CvsDialog(QDialog, Ui_CvsDialog):
 
22
    """
 
23
    Module implementing a dialog starting a process and showing its output.
 
24
    
 
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.
 
28
    """
 
29
    def __init__(self, text, parent = None):
 
30
        """
 
31
        Constructor
 
32
        
 
33
        @param text text to be shown by the label (string or QString)
 
34
        @param parent parent widget (QWidget)
 
35
        """
 
36
        QDialog.__init__(self, parent)
 
37
        self.setupUi(self)
 
38
        
 
39
        self.buttonBox.button(QDialogButtonBox.Close).setEnabled(False)
 
40
        self.buttonBox.button(QDialogButtonBox.Cancel).setDefault(True)
 
41
        
 
42
        self.proc = None
 
43
        self.username = ''
 
44
        self.password = ''
 
45
        
 
46
        self.outputGroup.setTitle(text)
 
47
        
 
48
    def __finish(self):
 
49
        """
 
50
        Private slot called when the process finished or the user pressed the button.
 
51
        """
 
52
        if self.proc is not None and \
 
53
           self.proc.state() != QProcess.NotRunning:
 
54
            self.proc.terminate()
 
55
            QTimer.singleShot(2000, self.proc, SLOT('kill()'))
 
56
            self.proc.waitForFinished(3000)
 
57
        
 
58
        self.buttonBox.button(QDialogButtonBox.Close).setEnabled(True)
 
59
        self.buttonBox.button(QDialogButtonBox.Cancel).setEnabled(False)
 
60
        self.buttonBox.button(QDialogButtonBox.Close).setDefault(True)
 
61
        
 
62
        self.inputGroup.setEnabled(False)
 
63
        
 
64
        self.proc = None
 
65
        
 
66
        if Preferences.getVCS("AutoClose") and \
 
67
           self.normal and \
 
68
           not self.errors.length() > 0:
 
69
            self.accept()
 
70
        
 
71
    def on_buttonBox_clicked(self, button):
 
72
        """
 
73
        Private slot called by a button of the button box clicked.
 
74
        
 
75
        @param button button that was clicked (QAbstractButton)
 
76
        """
 
77
        if button == self.buttonBox.button(QDialogButtonBox.Close):
 
78
            self.close()
 
79
        elif button == self.buttonBox.button(QDialogButtonBox.Cancel):
 
80
            self.__finish()
 
81
        
 
82
    def __procFinished(self, exitCode, exitStatus):
 
83
        """
 
84
        Private slot connected to the finished signal.
 
85
        
 
86
        @param exitCode exit code of the process (integer)
 
87
        @param exitStatus exit status of the process (QProcess.ExitStatus)
 
88
        """
 
89
        self.normal = exitStatus == QProcess.NormalExit
 
90
        self.__finish()
 
91
        
 
92
    def startProcess(self, args, workingDir = None):
 
93
        """
 
94
        Public slot used to start the process.
 
95
        
 
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
 
99
        """
 
100
        self.normal = False
 
101
        self.intercept = False
 
102
        
 
103
        self.proc = QProcess()
 
104
        
 
105
        self.resultbox.append(args.join(' '))
 
106
        self.resultbox.append('')
 
107
        
 
108
        self.connect(self.proc, SIGNAL('finished(int, QProcess::ExitStatus)'),
 
109
            self.__procFinished)
 
110
        self.connect(self.proc, SIGNAL('readyReadStandardOutput()'),
 
111
            self.__readStdout)
 
112
        self.connect(self.proc, SIGNAL('readyReadStandardError()'),
 
113
            self.__readStderr)
 
114
        
 
115
        if workingDir:
 
116
            self.proc.setWorkingDirectory(workingDir)
 
117
        self.proc.start('cvs', args)
 
118
        procStarted = self.proc.waitForStarted()
 
119
        if not procStarted:
 
120
            self.button.setFocus()
 
121
            self.inputGroup.setEnabled(False)
 
122
            KQMessageBox.critical(None,
 
123
                self.trUtf8('Process Generation Error'),
 
124
                self.trUtf8(
 
125
                    'The process %1 could not be started. '
 
126
                    'Ensure, that it is in the search path.'
 
127
                ).arg('cvs'))
 
128
        else:
 
129
            self.inputGroup.setEnabled(True)
 
130
        return procStarted
 
131
        
 
132
    def normalExit(self):
 
133
        """
 
134
        Public method to check for a normal process termination.
 
135
        
 
136
        @return flag indicating normal process termination (boolean)
 
137
        """
 
138
        return self.normal
 
139
    
 
140
    def __readStdout(self):
 
141
        """
 
142
        Private slot to handle the readyReadStdout signal. 
 
143
        
 
144
        It reads the output of the process, formats it and inserts it into
 
145
        the contents pane.
 
146
        """
 
147
        if self.proc is not None:
 
148
            s = QString(self.proc.readAllStandardOutput())
 
149
            self.resultbox.insertPlainText(s)
 
150
            self.resultbox.ensureCursorVisible()
 
151
        
 
152
    def __readStderr(self):
 
153
        """
 
154
        Private slot to handle the readyReadStderr signal.
 
155
        
 
156
        It reads the error output of the process and inserts it into the
 
157
        error pane.
 
158
        """
 
159
        if self.proc is not None:
 
160
            s = QString(self.proc.readAllStandardError())
 
161
            self.errors.insertPlainText(s)
 
162
            self.errors.ensureCursorVisible()
 
163
        
 
164
    def on_passwordCheckBox_toggled(self, isOn):
 
165
        """
 
166
        Private slot to handle the password checkbox toggled.
 
167
        
 
168
        @param isOn flag indicating the status of the check box (boolean)
 
169
        """
 
170
        if isOn:
 
171
            self.input.setEchoMode(QLineEdit.Password)
 
172
        else:
 
173
            self.input.setEchoMode(QLineEdit.Normal)
 
174
        
 
175
    @pyqtSignature("")
 
176
    def on_sendButton_clicked(self):
 
177
        """
 
178
        Private slot to send the input to the subversion process.
 
179
        """
 
180
        input = self.input.text()
 
181
        input.append(os.linesep)
 
182
        
 
183
        if self.passwordCheckBox.isChecked():
 
184
            self.errors.insertPlainText(os.linesep)
 
185
            self.errors.ensureCursorVisible()
 
186
        else:
 
187
            self.errors.insertPlainText(input)
 
188
            self.errors.ensureCursorVisible()
 
189
        
 
190
        self.proc.write(input.toLocal8Bit())
 
191
        
 
192
        self.passwordCheckBox.setChecked(False)
 
193
        self.input.clear()
 
194
        
 
195
    def on_input_returnPressed(self):
 
196
        """
 
197
        Private slot to handle the press of the return key in the input field.
 
198
        """
 
199
        self.intercept = True
 
200
        self.on_sendButton_clicked()
 
201
        
 
202
    def keyPressEvent(self, evt):
 
203
        """
 
204
        Protected slot to handle a key press event.
 
205
        
 
206
        @param evt the key press event (QKeyEvent)
 
207
        """
 
208
        if self.intercept:
 
209
            self.intercept = False
 
210
            evt.accept()
 
211
            return
 
212
        QDialog.keyPressEvent(self, evt)