56 linenumberformat = "%%%dd" % linenumberwidth |
56 linenumberformat = "%%%dd" % linenumberwidth |
57 emptylineno = ' ' * linenumberwidth |
57 emptylineno = ' ' * linenumberwidth |
58 |
58 |
59 for (ln1, l1), (ln2, l2), flag in _mdiff(a, b, None, None, IS_CHARACTER_JUNK): |
59 for (ln1, l1), (ln2, l2), flag in _mdiff(a, b, None, None, IS_CHARACTER_JUNK): |
60 if not flag: |
60 if not flag: |
61 yield ('e', str(linenumberformat % ln1), l1, |
61 yield ('e', linenumberformat % ln1, l1, |
62 str(linenumberformat % ln2), l2) |
62 linenumberformat % ln2, l2) |
63 continue |
63 continue |
64 if ln2 == "" and l2 == "\n": |
64 if ln2 == "" and l2 == "\n": |
65 yield ('d', str(linenumberformat % ln1), removeMarkers(l1), |
65 yield ('d', linenumberformat % ln1, removeMarkers(l1), |
66 emptylineno, '\n') |
66 emptylineno, '\n') |
67 continue |
67 continue |
68 if ln1 == "" and l1 == "\n": |
68 if ln1 == "" and l1 == "\n": |
69 yield ('i', emptylineno, '\n', |
69 yield ('i', emptylineno, '\n', |
70 str(linenumberformat % ln2), removeMarkers(l2)) |
70 linenumberformat % ln2, removeMarkers(l2)) |
71 continue |
71 continue |
72 yield ('r', str(linenumberformat % ln1), l1, |
72 yield ('r', linenumberformat % ln1, l1, |
73 str(linenumberformat % ln2), l2) |
73 linenumberformat % ln2, l2) |
74 |
74 |
75 class CompareDialog(QWidget, Ui_CompareDialog): |
75 class CompareDialog(QWidget, Ui_CompareDialog): |
76 """ |
76 """ |
77 Class implementing a dialog to compare two files and show the result side by side. |
77 Class implementing a dialog to compare two files and show the result side by side. |
78 """ |
78 """ |
219 """ |
219 """ |
220 Private slot to handle the Compare button press. |
220 Private slot to handle the Compare button press. |
221 """ |
221 """ |
222 filename1 = Utilities.toNativeSeparators(self.file1Edit.text()) |
222 filename1 = Utilities.toNativeSeparators(self.file1Edit.text()) |
223 try: |
223 try: |
224 f1 = open(filename1, "rb") |
224 f1 = open(filename1, "r") |
225 lines1 = f1.readlines() |
225 lines1 = f1.readlines() |
226 f1.close() |
226 f1.close() |
227 except IOError: |
227 except IOError: |
228 QMessageBox.critical(self, |
228 QMessageBox.critical(self, |
229 self.trUtf8("Compare Files"), |
229 self.trUtf8("Compare Files"), |
231 .format(filename1)) |
231 .format(filename1)) |
232 return |
232 return |
233 |
233 |
234 filename2 = Utilities.toNativeSeparators(self.file2Edit.text()) |
234 filename2 = Utilities.toNativeSeparators(self.file2Edit.text()) |
235 try: |
235 try: |
236 f2 = open(filename2, "rb") |
236 f2 = open(filename2, "r") |
237 lines2 = f2.readlines() |
237 lines2 = f2.readlines() |
238 f2.close() |
238 f2.close() |
239 except IOError: |
239 except IOError: |
240 QMessageBox.critical(self, |
240 QMessageBox.critical(self, |
241 self.trUtf8("Compare Files"), |
241 self.trUtf8("Compare Files"), |