UI/CompareDialog.py

branch
Py2 comp.
changeset 3060
5883ce99ee12
parent 3058
0a02c433f52d
parent 3039
8dd0165d805d
child 3141
72f3bde98c58
equal deleted inserted replaced
3058:0a02c433f52d 3060:5883ce99ee12
66 66
67 for (ln1, l1), (ln2, l2), flag in _mdiff(a, b, None, None, 67 for (ln1, l1), (ln2, l2), flag in _mdiff(a, b, None, None,
68 IS_CHARACTER_JUNK): 68 IS_CHARACTER_JUNK):
69 if not flag: 69 if not flag:
70 yield ('e', linenumberformat.format(ln1), l1, 70 yield ('e', linenumberformat.format(ln1), l1,
71 linenumberformat.format(ln2), l2) 71 linenumberformat.format(ln2), l2)
72 continue 72 continue
73 if ln2 == "" and l2 == "\n": 73 if ln2 == "" and l2 == "\n":
74 yield ('d', linenumberformat.format(ln1), removeMarkers(l1), 74 yield ('d', linenumberformat.format(ln1), removeMarkers(l1),
75 emptylineno, '\n') 75 emptylineno, '\n')
76 continue 76 continue
77 if ln1 == "" and l1 == "\n": 77 if ln1 == "" and l1 == "\n":
78 yield ('i', emptylineno, '\n', 78 yield ('i', emptylineno, '\n',
79 linenumberformat.format(ln2), removeMarkers(l2)) 79 linenumberformat.format(ln2), removeMarkers(l2))
80 continue 80 continue
81 yield ('r', linenumberformat.format(ln1), l1, 81 yield ('r', linenumberformat.format(ln1), l1,
82 linenumberformat.format(ln2), l2) 82 linenumberformat.format(ln2), l2)
83 83
84 84
85 class CompareDialog(QWidget, Ui_CompareDialog): 85 class CompareDialog(QWidget, Ui_CompareDialog):
86 """ 86 """
87 Class implementing a dialog to compare two files and show the result side 87 Class implementing a dialog to compare two files and show the result side
234 E5MessageBox.critical( 234 E5MessageBox.critical(
235 self, 235 self,
236 self.trUtf8("Compare Files"), 236 self.trUtf8("Compare Files"),
237 self.trUtf8( 237 self.trUtf8(
238 """<p>The file <b>{0}</b> could not be read.</p>""") 238 """<p>The file <b>{0}</b> could not be read.</p>""")
239 .format(filename1)) 239 .format(filename1))
240 return 240 return
241 241
242 filename2 = Utilities.toNativeSeparators(self.file2Edit.text()) 242 filename2 = Utilities.toNativeSeparators(self.file2Edit.text())
243 try: 243 try:
244 f2 = open(filename2, "r", encoding="utf-8") 244 f2 = open(filename2, "r", encoding="utf-8")
248 E5MessageBox.critical( 248 E5MessageBox.critical(
249 self, 249 self,
250 self.trUtf8("Compare Files"), 250 self.trUtf8("Compare Files"),
251 self.trUtf8( 251 self.trUtf8(
252 """<p>The file <b>{0}</b> could not be read.</p>""") 252 """<p>The file <b>{0}</b> could not be read.</p>""")
253 .format(filename2)) 253 .format(filename2))
254 return 254 return
255 255
256 self.__compare(lines1, lines2) 256 self.__compare(lines1, lines2)
257 257
258 def compare(self, lines1, lines2, name1="", name2=""): 258 def compare(self, lines1, lines2, name1="", name2=""):
274 self.file2Edit.setText(name2) 274 self.file2Edit.setText(name2)
275 self.file2Edit.setReadOnly(True) 275 self.file2Edit.setReadOnly(True)
276 self.diffButton.setEnabled(False) 276 self.diffButton.setEnabled(False)
277 self.diffButton.hide() 277 self.diffButton.hide()
278 278
279 if type(lines1) == type(""): 279 if isinstance(lines1, str):
280 lines1 = lines1.splitlines(True) 280 lines1 = lines1.splitlines(True)
281 if type(lines2) == type(""): 281 if isinstance(lines2, str):
282 lines2 = lines2.splitlines(True) 282 lines2 = lines2.splitlines(True)
283 283
284 self.__compare(lines1, lines2) 284 self.__compare(lines1, lines2)
285 285
286 def __compare(self, lines1, lines2): 286 def __compare(self, lines1, lines2):
342 self.vsb1.setValue(0) 342 self.vsb1.setValue(0)
343 self.vsb2.setValue(0) 343 self.vsb2.setValue(0)
344 self.firstButton.setEnabled(False) 344 self.firstButton.setEnabled(False)
345 self.upButton.setEnabled(False) 345 self.upButton.setEnabled(False)
346 self.downButton.setEnabled( 346 self.downButton.setEnabled(
347 len(self.diffParas) > 0 and 347 len(self.diffParas) > 0 and
348 (self.vsb1.isVisible() or self.vsb2.isVisible())) 348 (self.vsb1.isVisible() or self.vsb2.isVisible()))
349 self.lastButton.setEnabled( 349 self.lastButton.setEnabled(
350 len(self.diffParas) > 0 and 350 len(self.diffParas) > 0 and
351 (self.vsb1.isVisible() or self.vsb2.isVisible())) 351 (self.vsb1.isVisible() or self.vsb2.isVisible()))
352 352
353 self.totalLabel.setText(self.trUtf8('Total: {0}')\ 353 self.totalLabel.setText(self.trUtf8('Total: {0}')
354 .format(added + deleted + changed)) 354 .format(added + deleted + changed))
355 self.changedLabel.setText(self.trUtf8('Changed: {0}').format(changed)) 355 self.changedLabel.setText(self.trUtf8('Changed: {0}').format(changed))
356 self.addedLabel.setText(self.trUtf8('Added: {0}').format(added)) 356 self.addedLabel.setText(self.trUtf8('Added: {0}').format(added))
357 self.deletedLabel.setText(self.trUtf8('Deleted: {0}').format(deleted)) 357 self.deletedLabel.setText(self.trUtf8('Deleted: {0}').format(deleted))
358 358

eric ide

mercurial