src/eric7/UI/DiffDialog.py

branch
eric7
changeset 10303
ee1aadab1215
parent 9653
e67609152c5e
child 10433
328f3ec4b77a
equal deleted inserted replaced
10302:8cb0dabf852f 10303:ee1aadab1215
12 import pathlib 12 import pathlib
13 import time 13 import time
14 14
15 from difflib import context_diff, unified_diff 15 from difflib import context_diff, unified_diff
16 16
17 from PyQt6.QtCore import QEvent, pyqtSlot 17 from PyQt6.QtCore import QEvent, QTimer, pyqtSlot
18 from PyQt6.QtGui import QTextCursor 18 from PyQt6.QtGui import QTextCursor
19 from PyQt6.QtWidgets import QApplication, QDialogButtonBox, QWidget 19 from PyQt6.QtWidgets import QApplication, QDialogButtonBox, QWidget
20 20
21 from eric7 import Preferences 21 from eric7 import Preferences
22 from eric7.EricWidgets import EricFileDialog, EricMessageBox 22 from eric7.EricWidgets import EricFileDialog, EricMessageBox
31 class DiffDialog(QWidget, Ui_DiffDialog): 31 class DiffDialog(QWidget, Ui_DiffDialog):
32 """ 32 """
33 Class implementing a dialog to compare two files. 33 Class implementing a dialog to compare two files.
34 """ 34 """
35 35
36 def __init__(self, parent=None): 36 def __init__(self, files=None, parent=None):
37 """ 37 """
38 Constructor 38 Constructor
39 39
40 @param parent reference to the parent widget (QWidget) 40 @param files list of two file names to be diffed
41 @type list of two str
42 @param parent reference to the parent widget
43 @type QWidget
41 """ 44 """
42 super().__init__(parent) 45 super().__init__(parent)
43 self.setupUi(self) 46 self.setupUi(self)
44 47
45 self.file1Picker.setMode(EricPathPickerModes.OPEN_FILE_MODE) 48 self.file1Picker.setMode(EricPathPickerModes.OPEN_FILE_MODE)
73 76
74 # connect some of our widgets explicitly 77 # connect some of our widgets explicitly
75 self.file1Picker.textChanged.connect(self.__fileChanged) 78 self.file1Picker.textChanged.connect(self.__fileChanged)
76 self.file2Picker.textChanged.connect(self.__fileChanged) 79 self.file2Picker.textChanged.connect(self.__fileChanged)
77 80
81 if len(files) == 2:
82 self.file1Picker.setText(files[0])
83 self.file2Picker.setText(files[1])
84 QTimer.singleShot(0, self.on_diffButton_clicked)
85
78 def show(self, filename=None): 86 def show(self, filename=None):
79 """ 87 """
80 Public slot to show the dialog. 88 Public slot to show the dialog.
81 89
82 @param filename name of a file to use as the first file (string) 90 @param filename name of a file to use as the first file (string)
279 class DiffWindow(EricMainWindow): 287 class DiffWindow(EricMainWindow):
280 """ 288 """
281 Main window class for the standalone dialog. 289 Main window class for the standalone dialog.
282 """ 290 """
283 291
284 def __init__(self, parent=None): 292 def __init__(self, files=None, parent=None):
285 """ 293 """
286 Constructor 294 Constructor
287 295
288 @param parent reference to the parent widget (QWidget) 296 @param files list of two file names to be diffed
297 @type list of two str
298 @param parent reference to the parent widget
299 @type QWidget
289 """ 300 """
290 super().__init__(parent) 301 super().__init__(parent)
291 302
292 self.setStyle(Preferences.getUI("Style"), Preferences.getUI("StyleSheet")) 303 self.setStyle(Preferences.getUI("Style"), Preferences.getUI("StyleSheet"))
293 304
294 self.cw = DiffDialog(self) 305 self.cw = DiffDialog(files=files, parent=self)
295 self.cw.installEventFilter(self) 306 self.cw.installEventFilter(self)
296 size = self.cw.size() 307 size = self.cw.size()
297 self.setCentralWidget(self.cw) 308 self.setCentralWidget(self.cw)
298 self.resize(size) 309 self.resize(size)
299 310

eric ide

mercurial