--- a/UI/DiffDialog.py Tue Oct 15 22:03:54 2013 +0200 +++ b/UI/DiffDialog.py Fri Oct 18 23:00:41 2013 +0200 @@ -110,7 +110,7 @@ def context_diff(a, b, fromfile='', tofile='', fromfiledate='', tofiledate='', n=3, lineterm='\n'): - """ + r""" Compare two sequences of lines; generate the delta as a context diff. Context diffs are a compact way of showing line changes and a few @@ -135,7 +135,8 @@ Example: <pre> - >>> print ''.join(context_diff('one\ntwo\nthree\nfour\n'.splitlines(1), + >>> print ''.join( + ... context_diff('one\ntwo\nthree\nfour\n'.splitlines(1), ... 'zero\none\ntree\nfour\n'.splitlines(1), 'Original', 'Current', ... 'Sat Jan 26 23:30:50 1991', 'Fri Jun 06 10:22:46 2003')), *** Original Sat Jan 26 23:30:50 1991 @@ -163,9 +164,9 @@ @param lineterm line termination string (string) @return a generator yielding lines of differences """ - started = False - prefixmap = {'insert': '+ ', 'delete': '- ', 'replace': '! ', 'equal': ' '} + prefixmap = {'insert': '+ ', 'delete': '- ', 'replace': '! ', + 'equal': ' '} for group in SequenceMatcher(None, a, b).get_grouped_opcodes(n): if not started: yield '*** {0}\t{1}{2}'.format(fromfile, fromfiledate, lineterm) @@ -174,7 +175,8 @@ yield '***************{0}'.format(lineterm) if group[-1][2] - group[0][1] >= 2: - yield '*** {0:d},{1:d} ****{2}'.format(group[0][1] + 1, group[-1][2], lineterm) + yield '*** {0:d},{1:d} ****{2}'.format( + group[0][1] + 1, group[-1][2], lineterm) else: yield '*** {0:d} ****{1}'.format(group[-1][2], lineterm) visiblechanges = [e for e in group if e[0] in ('replace', 'delete')] @@ -185,7 +187,8 @@ yield prefixmap[tag] + line if group[-1][4] - group[0][3] >= 2: - yield '--- {0:d},{1:d} ----{2}'.format(group[0][3] + 1, group[-1][4], lineterm) + yield '--- {0:d},{1:d} ----{2}'.format( + group[0][3] + 1, group[-1][4], lineterm) else: yield '--- {0:d} ----{1}'.format(group[-1][4], lineterm) visiblechanges = [e for e in group if e[0] in ('replace', 'insert')] @@ -203,6 +206,8 @@ def __init__(self, parent=None): """ Constructor + + @param parent reference to the parent widget (QWidget) """ super(DiffDialog, self).__init__(parent) self.setupUi(self) @@ -210,13 +215,14 @@ self.file1Completer = E5FileCompleter(self.file1Edit) self.file2Completer = E5FileCompleter(self.file2Edit) - self.diffButton = \ - self.buttonBox.addButton(self.trUtf8("Compare"), QDialogButtonBox.ActionRole) + self.diffButton = self.buttonBox.addButton( + self.trUtf8("Compare"), QDialogButtonBox.ActionRole) self.diffButton.setToolTip( self.trUtf8("Press to perform the comparison of the two files")) - self.saveButton = \ - self.buttonBox.addButton(self.trUtf8("Save"), QDialogButtonBox.ActionRole) - self.saveButton.setToolTip(self.trUtf8("Save the output to a patch file")) + self.saveButton = self.buttonBox.addButton( + self.trUtf8("Save"), QDialogButtonBox.ActionRole) + self.saveButton.setToolTip( + self.trUtf8("Save the output to a patch file")) self.diffButton.setEnabled(False) self.saveButton.setEnabled(False) self.diffButton.setDefault(True) @@ -314,10 +320,11 @@ pass f.close() except IOError as why: - E5MessageBox.critical(self, self.trUtf8('Save Diff'), - self.trUtf8('<p>The patch file <b>{0}</b> could not be saved.<br />' - 'Reason: {1}</p>') - .format(fname, str(why))) + E5MessageBox.critical( + self, self.trUtf8('Save Diff'), + self.trUtf8( + '<p>The patch file <b>{0}</b> could not be saved.<br />' + 'Reason: {1}</p>').format(fname, str(why))) @pyqtSlot() def on_diffButton_clicked(self): @@ -336,7 +343,8 @@ except IOError: E5MessageBox.critical(self, self.trUtf8("Compare Files"), - self.trUtf8("""<p>The file <b>{0}</b> could not be read.</p>""") + self.trUtf8( + """<p>The file <b>{0}</b> could not be read.</p>""") .format(self.filename1)) return @@ -352,7 +360,8 @@ except IOError: E5MessageBox.critical(self, self.trUtf8("Compare Files"), - self.trUtf8("""<p>The file <b>{0}</b> could not be read.</p>""") + self.trUtf8( + """<p>The file <b>{0}</b> could not be read.</p>""") .format(self.filename2)) return @@ -360,11 +369,13 @@ self.saveButton.setEnabled(False) if self.unifiedRadioButton.isChecked(): - self.__generateUnifiedDiff(lines1, lines2, self.filename1, self.filename2, - filemtime1, filemtime2) + self.__generateUnifiedDiff( + lines1, lines2, self.filename1, self.filename2, + filemtime1, filemtime2) else: - self.__generateContextDiff(lines1, lines2, self.filename1, self.filename2, - filemtime1, filemtime2) + self.__generateContextDiff( + lines1, lines2, self.filename1, self.filename2, + filemtime1, filemtime2) tc = self.contents.textCursor() tc.movePosition(QTextCursor.Start) @@ -415,7 +426,8 @@ QApplication.processEvents() if paras == 0: - self.__appendText(self.trUtf8('There is no difference.'), self.cNormalFormat) + self.__appendText( + self.trUtf8('There is no difference.'), self.cNormalFormat) def __generateContextDiff(self, a, b, fromfile, tofile, fromfiledate, tofiledate): @@ -438,7 +450,8 @@ format = self.cRemovedFormat elif line.startswith('! '): format = self.cReplacedFormat - elif (line.startswith('*** ') or line.startswith('--- ')) and paras > 1: + elif (line.startswith('*** ') or line.startswith('--- ')) and \ + paras > 1: format = self.cLineNoFormat else: format = self.cNormalFormat @@ -448,7 +461,8 @@ QApplication.processEvents() if paras == 0: - self.__appendText(self.trUtf8('There is no difference.'), self.cNormalFormat) + self.__appendText( + self.trUtf8('There is no difference.'), self.cNormalFormat) def __fileChanged(self): """ @@ -503,7 +517,8 @@ """ super(DiffWindow, self).__init__(parent) - self.setStyle(Preferences.getUI("Style"), Preferences.getUI("StyleSheet")) + self.setStyle(Preferences.getUI("Style"), + Preferences.getUI("StyleSheet")) self.cw = DiffDialog(self) self.cw.installEventFilter(self)