UI/DiffDialog.py

branch
Py2 comp.
changeset 3484
645c12de6b0c
parent 3178
f25fc1364c88
parent 3190
a9a94491c4fd
child 3656
441956d8fce5
equal deleted inserted replaced
3456:96232974dcdb 3484:645c12de6b0c
22 22
23 from .Ui_DiffDialog import Ui_DiffDialog 23 from .Ui_DiffDialog import Ui_DiffDialog
24 24
25 import Utilities 25 import Utilities
26 import Preferences 26 import Preferences
27 import UI.PixmapCache
27 28
28 from difflib import SequenceMatcher 29 from difflib import SequenceMatcher
29 30
30 # This function is copied from python 2.3 and slightly modified. 31 # This function is copied from python 2.3 and slightly modified.
31 # The header lines contain a tab after the filename. 32 # The header lines contain a tab after the filename.
210 @param parent reference to the parent widget (QWidget) 211 @param parent reference to the parent widget (QWidget)
211 """ 212 """
212 super(DiffDialog, self).__init__(parent) 213 super(DiffDialog, self).__init__(parent)
213 self.setupUi(self) 214 self.setupUi(self)
214 215
216 self.file1Button.setIcon(UI.PixmapCache.getIcon("open.png"))
217 self.file2Button.setIcon(UI.PixmapCache.getIcon("open.png"))
218
215 self.file1Completer = E5FileCompleter(self.file1Edit) 219 self.file1Completer = E5FileCompleter(self.file1Edit)
216 self.file2Completer = E5FileCompleter(self.file2Edit) 220 self.file2Completer = E5FileCompleter(self.file2Edit)
217 221
218 self.diffButton = self.buttonBox.addButton( 222 self.diffButton = self.buttonBox.addButton(
219 self.trUtf8("Compare"), QDialogButtonBox.ActionRole) 223 self.tr("Compare"), QDialogButtonBox.ActionRole)
220 self.diffButton.setToolTip( 224 self.diffButton.setToolTip(
221 self.trUtf8("Press to perform the comparison of the two files")) 225 self.tr("Press to perform the comparison of the two files"))
222 self.saveButton = self.buttonBox.addButton( 226 self.saveButton = self.buttonBox.addButton(
223 self.trUtf8("Save"), QDialogButtonBox.ActionRole) 227 self.tr("Save"), QDialogButtonBox.ActionRole)
224 self.saveButton.setToolTip( 228 self.saveButton.setToolTip(
225 self.trUtf8("Save the output to a patch file")) 229 self.tr("Save the output to a patch file"))
226 self.diffButton.setEnabled(False) 230 self.diffButton.setEnabled(False)
227 self.saveButton.setEnabled(False) 231 self.saveButton.setEnabled(False)
228 self.diffButton.setDefault(True) 232 self.diffButton.setDefault(True)
229 233
230 self.filename1 = '' 234 self.filename1 = ''
285 else: 289 else:
286 fname = dname 290 fname = dname
287 291
288 fname, selectedFilter = E5FileDialog.getSaveFileNameAndFilter( 292 fname, selectedFilter = E5FileDialog.getSaveFileNameAndFilter(
289 self, 293 self,
290 self.trUtf8("Save Diff"), 294 self.tr("Save Diff"),
291 fname, 295 fname,
292 self.trUtf8("Patch Files (*.diff)"), 296 self.tr("Patch Files (*.diff)"),
293 None, 297 None,
294 E5FileDialog.Options(E5FileDialog.DontConfirmOverwrite)) 298 E5FileDialog.Options(E5FileDialog.DontConfirmOverwrite))
295 299
296 if not fname: 300 if not fname:
297 return 301 return
302 if ex: 306 if ex:
303 fname += ex 307 fname += ex
304 if QFileInfo(fname).exists(): 308 if QFileInfo(fname).exists():
305 res = E5MessageBox.yesNo( 309 res = E5MessageBox.yesNo(
306 self, 310 self,
307 self.trUtf8("Save Diff"), 311 self.tr("Save Diff"),
308 self.trUtf8("<p>The patch file <b>{0}</b> already exists." 312 self.tr("<p>The patch file <b>{0}</b> already exists."
309 " Overwrite it?</p>").format(fname), 313 " Overwrite it?</p>").format(fname),
310 icon=E5MessageBox.Warning) 314 icon=E5MessageBox.Warning)
311 if not res: 315 if not res:
312 return 316 return
313 fname = Utilities.toNativeSeparators(fname) 317 fname = Utilities.toNativeSeparators(fname)
314 318
320 except UnicodeError: 324 except UnicodeError:
321 pass 325 pass
322 f.close() 326 f.close()
323 except IOError as why: 327 except IOError as why:
324 E5MessageBox.critical( 328 E5MessageBox.critical(
325 self, self.trUtf8('Save Diff'), 329 self, self.tr('Save Diff'),
326 self.trUtf8( 330 self.tr(
327 '<p>The patch file <b>{0}</b> could not be saved.<br />' 331 '<p>The patch file <b>{0}</b> could not be saved.<br />'
328 'Reason: {1}</p>').format(fname, str(why))) 332 'Reason: {1}</p>').format(fname, str(why)))
329 333
330 @pyqtSlot() 334 @pyqtSlot()
331 def on_diffButton_clicked(self): 335 def on_diffButton_clicked(self):
342 lines1 = f1.readlines() 346 lines1 = f1.readlines()
343 f1.close() 347 f1.close()
344 except IOError: 348 except IOError:
345 E5MessageBox.critical( 349 E5MessageBox.critical(
346 self, 350 self,
347 self.trUtf8("Compare Files"), 351 self.tr("Compare Files"),
348 self.trUtf8( 352 self.tr(
349 """<p>The file <b>{0}</b> could not be read.</p>""") 353 """<p>The file <b>{0}</b> could not be read.</p>""")
350 .format(self.filename1)) 354 .format(self.filename1))
351 return 355 return
352 356
353 self.filename2 = Utilities.toNativeSeparators(self.file2Edit.text()) 357 self.filename2 = Utilities.toNativeSeparators(self.file2Edit.text())
360 lines2 = f2.readlines() 364 lines2 = f2.readlines()
361 f2.close() 365 f2.close()
362 except IOError: 366 except IOError:
363 E5MessageBox.critical( 367 E5MessageBox.critical(
364 self, 368 self,
365 self.trUtf8("Compare Files"), 369 self.tr("Compare Files"),
366 self.trUtf8( 370 self.tr(
367 """<p>The file <b>{0}</b> could not be read.</p>""") 371 """<p>The file <b>{0}</b> could not be read.</p>""")
368 .format(self.filename2)) 372 .format(self.filename2))
369 return 373 return
370 374
371 self.contents.clear() 375 self.contents.clear()
428 if not (paras % self.updateInterval): 432 if not (paras % self.updateInterval):
429 QApplication.processEvents() 433 QApplication.processEvents()
430 434
431 if paras == 0: 435 if paras == 0:
432 self.__appendText( 436 self.__appendText(
433 self.trUtf8('There is no difference.'), self.cNormalFormat) 437 self.tr('There is no difference.'), self.cNormalFormat)
434 438
435 def __generateContextDiff(self, a, b, fromfile, tofile, 439 def __generateContextDiff(self, a, b, fromfile, tofile,
436 fromfiledate, tofiledate): 440 fromfiledate, tofiledate):
437 """ 441 """
438 Private slot to generate a context diff output. 442 Private slot to generate a context diff output.
463 if not (paras % self.updateInterval): 467 if not (paras % self.updateInterval):
464 QApplication.processEvents() 468 QApplication.processEvents()
465 469
466 if paras == 0: 470 if paras == 0:
467 self.__appendText( 471 self.__appendText(
468 self.trUtf8('There is no difference.'), self.cNormalFormat) 472 self.tr('There is no difference.'), self.cNormalFormat)
469 473
470 def __fileChanged(self): 474 def __fileChanged(self):
471 """ 475 """
472 Private slot to enable/disable the Compare button. 476 Private slot to enable/disable the Compare button.
473 """ 477 """
484 @param lineEdit field for the display of the selected filename 488 @param lineEdit field for the display of the selected filename
485 (QLineEdit) 489 (QLineEdit)
486 """ 490 """
487 filename = E5FileDialog.getOpenFileName( 491 filename = E5FileDialog.getOpenFileName(
488 self, 492 self,
489 self.trUtf8("Select file to compare"), 493 self.tr("Select file to compare"),
490 lineEdit.text(), 494 lineEdit.text(),
491 "") 495 "")
492 496
493 if filename: 497 if filename:
494 lineEdit.setText(Utilities.toNativeSeparators(filename)) 498 lineEdit.setText(Utilities.toNativeSeparators(filename))

eric ide

mercurial