14 |
14 |
15 from PyQt5.QtCore import QFileInfo, QEvent, pyqtSlot |
15 from PyQt5.QtCore import QFileInfo, QEvent, pyqtSlot |
16 from PyQt5.QtGui import QTextCursor |
16 from PyQt5.QtGui import QTextCursor |
17 from PyQt5.QtWidgets import QWidget, QApplication, QDialogButtonBox |
17 from PyQt5.QtWidgets import QWidget, QApplication, QDialogButtonBox |
18 |
18 |
19 from E5Gui.E5Completers import E5FileCompleter |
|
20 from E5Gui import E5MessageBox, E5FileDialog |
19 from E5Gui import E5MessageBox, E5FileDialog |
21 from E5Gui.E5MainWindow import E5MainWindow |
20 from E5Gui.E5MainWindow import E5MainWindow |
|
21 from E5Gui.E5PathPicker import E5PathPickerModes |
22 |
22 |
23 from .Ui_DiffDialog import Ui_DiffDialog |
23 from .Ui_DiffDialog import Ui_DiffDialog |
24 from .DiffHighlighter import DiffHighlighter |
24 from .DiffHighlighter import DiffHighlighter |
25 |
25 |
26 import Utilities |
26 import Utilities |
27 import Preferences |
27 import Preferences |
28 import UI.PixmapCache |
|
29 |
28 |
30 from difflib import SequenceMatcher |
29 from difflib import SequenceMatcher |
31 |
30 |
32 # This function is copied from python 2.3 and slightly modified. |
31 # This function is copied from python 2.3 and slightly modified. |
33 # The header lines contain a tab after the filename. |
32 # The header lines contain a tab after the filename. |
212 @param parent reference to the parent widget (QWidget) |
211 @param parent reference to the parent widget (QWidget) |
213 """ |
212 """ |
214 super(DiffDialog, self).__init__(parent) |
213 super(DiffDialog, self).__init__(parent) |
215 self.setupUi(self) |
214 self.setupUi(self) |
216 |
215 |
217 self.file1Button.setIcon(UI.PixmapCache.getIcon("open.png")) |
216 self.file1Picker.setMode(E5PathPickerModes.OpenFileMode) |
218 self.file2Button.setIcon(UI.PixmapCache.getIcon("open.png")) |
217 self.file2Picker.setMode(E5PathPickerModes.OpenFileMode) |
219 |
|
220 self.file1Completer = E5FileCompleter(self.file1Edit) |
|
221 self.file2Completer = E5FileCompleter(self.file2Edit) |
|
222 |
218 |
223 self.diffButton = self.buttonBox.addButton( |
219 self.diffButton = self.buttonBox.addButton( |
224 self.tr("Compare"), QDialogButtonBox.ActionRole) |
220 self.tr("Compare"), QDialogButtonBox.ActionRole) |
225 self.diffButton.setToolTip( |
221 self.diffButton.setToolTip( |
226 self.tr("Press to perform the comparison of the two files")) |
222 self.tr("Press to perform the comparison of the two files")) |
244 self.contents.setFontPointSize(font.pointSize()) |
240 self.contents.setFontPointSize(font.pointSize()) |
245 |
241 |
246 self.highlighter = DiffHighlighter(self.contents.document()) |
242 self.highlighter = DiffHighlighter(self.contents.document()) |
247 |
243 |
248 # connect some of our widgets explicitly |
244 # connect some of our widgets explicitly |
249 self.file1Edit.textChanged.connect(self.__fileChanged) |
245 self.file1Picker.textChanged.connect(self.__fileChanged) |
250 self.file2Edit.textChanged.connect(self.__fileChanged) |
246 self.file2Picker.textChanged.connect(self.__fileChanged) |
251 |
247 |
252 def show(self, filename=None): |
248 def show(self, filename=None): |
253 """ |
249 """ |
254 Public slot to show the dialog. |
250 Public slot to show the dialog. |
255 |
251 |
256 @param filename name of a file to use as the first file (string) |
252 @param filename name of a file to use as the first file (string) |
257 """ |
253 """ |
258 if filename: |
254 if filename: |
259 self.file1Edit.setText(filename) |
255 self.file1Picker.setText(filename) |
260 super(DiffDialog, self).show() |
256 super(DiffDialog, self).show() |
261 |
257 |
262 def on_buttonBox_clicked(self, button): |
258 def on_buttonBox_clicked(self, button): |
263 """ |
259 """ |
264 Private slot called by a button of the button box clicked. |
260 Private slot called by a button of the button box clicked. |
445 |
441 |
446 def __fileChanged(self): |
442 def __fileChanged(self): |
447 """ |
443 """ |
448 Private slot to enable/disable the Compare button. |
444 Private slot to enable/disable the Compare button. |
449 """ |
445 """ |
450 if not self.file1Edit.text() or \ |
446 if not self.file1Picker.text() or \ |
451 not self.file2Edit.text(): |
447 not self.file2Picker.text(): |
452 self.diffButton.setEnabled(False) |
448 self.diffButton.setEnabled(False) |
453 else: |
449 else: |
454 self.diffButton.setEnabled(True) |
450 self.diffButton.setEnabled(True) |
455 |
|
456 def __selectFile(self, lineEdit): |
|
457 """ |
|
458 Private slot to display a file selection dialog. |
|
459 |
|
460 @param lineEdit field for the display of the selected filename |
|
461 (QLineEdit) |
|
462 """ |
|
463 filename = E5FileDialog.getOpenFileName( |
|
464 self, |
|
465 self.tr("Select file to compare"), |
|
466 lineEdit.text(), |
|
467 "") |
|
468 |
|
469 if filename: |
|
470 lineEdit.setText(Utilities.toNativeSeparators(filename)) |
|
471 |
|
472 @pyqtSlot() |
|
473 def on_file1Button_clicked(self): |
|
474 """ |
|
475 Private slot to handle the file 1 file selection button press. |
|
476 """ |
|
477 self.__selectFile(self.file1Edit) |
|
478 |
|
479 @pyqtSlot() |
|
480 def on_file2Button_clicked(self): |
|
481 """ |
|
482 Private slot to handle the file 2 file selection button press. |
|
483 """ |
|
484 self.__selectFile(self.file2Edit) |
|
485 |
451 |
486 |
452 |
487 class DiffWindow(E5MainWindow): |
453 class DiffWindow(E5MainWindow): |
488 """ |
454 """ |
489 Main window class for the standalone dialog. |
455 Main window class for the standalone dialog. |