# -*- coding: utf-8 -*-
# Copyright (c) 2002, 2003 Detlev Offenbach <detlev@die-offenbachs.de>
#
"""
Module implementing a dialog to show the output of the cvs diff command process.
"""
from qt import *
from LogForm import LogForm
class CvsDiffDialog(LogForm):
"""
Class implementing a dialog to show the output of the cvs diff command process.
"""
def __init__(self, vcs, parent = None):
"""
Constructor
Arguments
vcs -- reference to the vcs object
parent -- parent widget (QWidget)
"""
LogForm.__init__(self, parent)
self.contentsLabel.setText(self.trUtf8('Difference:'))
self.setCaption(self.trUtf8('CVS Diff'))
QWhatsThis.add(self.contents,self.tr("<b>CVS Diff</b>\n"
"<p>This shows the output of the cvs diff command.</p>"
))
QWhatsThis.add(self.errors,self.tr("<b>CVS diff errors</b>\n"
"<p>This shows possible error messages of the cvs diff"
" command.</p>"
))
self.setWFlags(self.getWFlags() | Qt.WDestructiveClose)
self.process = QProcess(self)
self.vcs = vcs
self.cAdded = QColor(190, 237, 190)
self.cRemoved = QColor(237, 190, 190)
self.connect(self.process, SIGNAL('readyReadStdout()'),
self.handleReadStdout)
self.connect(self.process, SIGNAL('readyReadStderr()'),
self.handleReadStderr)
self.connect(self.process, SIGNAL('processExited()'),
self.handleProcessExited)
def closeEvent(self, e):
"""
Private slot implementing a close event handler.
Arguments
e -- close event (QCloseEvent)
"""
if self.process is not None:
self.process.tryTerminate()
QTimer.singleShot(2000, self.process, SLOT('kill()'))
e.accept()
def start(self, fn, versions=None):
"""
Public slot to start the cvs diff command.
Arguments
fn -- filename to be diffed (string)
versions -- list of versions to be diffed (list of 2 int or None)
"""
self.filename = fn
dname, fname = self.vcs.splitPath(fn)
self.process.kill()
self.contents.clear()
self.process.clearArguments()
self.process.addArgument('cvs')
self.vcs.addArguments(self.process, self.vcs.options['global'])
self.process.addArgument('diff')
self.vcs.addArguments(self.process, self.vcs.options['diff'])
if versions is not None:
self.process.addArgument('-r')
self.process.addArgument(versions[0])
self.process.addArgument('-r')
self.process.addArgument(versions[1])
self.process.addArgument(fname)
self.process.setWorkingDirectory(QDir(dname))
self.process.start()
self.setCaption(self.trUtf8('CVS Diff %1').arg(self.filename))
def handleProcessExited(self):
"""
Private slot to handle the processExited signal.
After the process has exited, the contents pane is colored.
"""
paras = self.contents.paragraphs()
if paras == 1:
self.contents.append(\
self.trUtf8('There is no difference.'))
return
for i in range(paras):
txt = self.contents.text(i)
if txt.length() > 0:
if txt.startsWith('+') or txt.startsWith('>'):
self.contents.setParagraphBackgroundColor(i, self.cAdded)
elif txt.startsWith('-') or txt.startsWith('<'):
self.contents.setParagraphBackgroundColor(i, self.cRemoved)
def handleReadStdout(self):
"""
Private slot to handle the readyReadStdout signal.
It reads the output of the process, formats it and inserts it into
the contents pane.
"""
self.contents.setTextFormat(QTextBrowser.PlainText)
while self.process.canReadLineStdout():
s = self.process.readLineStdout()
self.contents.append(s)
def handleReadStderr(self):
"""
Private slot to handle the readyReadStderr signal.
It reads the error output of the process and inserts it into the
error pane.
"""
while self.process.canReadLineStderr():
s = self.process.readLineStderr()
self.errors.append(s)
|