UI/CompareDialog.py

changeset 5765
39d8b26ff557
parent 5651
982465f8389c
child 6048
82ad8ec9548c
equal deleted inserted replaced
5764:51ceecf32585 5765:39d8b26ff557
16 16
17 import re 17 import re
18 from difflib import _mdiff, IS_CHARACTER_JUNK 18 from difflib import _mdiff, IS_CHARACTER_JUNK
19 19
20 from PyQt5.QtCore import QTimer, QEvent, pyqtSlot 20 from PyQt5.QtCore import QTimer, QEvent, pyqtSlot
21 from PyQt5.QtGui import QColor, QFontMetrics, QBrush, QTextCursor 21 from PyQt5.QtGui import QFontMetrics, QBrush, QTextCursor
22 from PyQt5.QtWidgets import QWidget, QApplication, QDialogButtonBox 22 from PyQt5.QtWidgets import QWidget, QApplication, QDialogButtonBox
23 23
24 from E5Gui import E5MessageBox 24 from E5Gui import E5MessageBox
25 from E5Gui.E5MainWindow import E5MainWindow 25 from E5Gui.E5MainWindow import E5MainWindow
26 from E5Gui.E5PathPicker import E5PathPickerModes 26 from E5Gui.E5PathPicker import E5PathPickerModes
131 self.vsb2 = self.contents_2.verticalScrollBar() 131 self.vsb2 = self.contents_2.verticalScrollBar()
132 self.hsb2 = self.contents_2.horizontalScrollBar() 132 self.hsb2 = self.contents_2.horizontalScrollBar()
133 133
134 self.on_synchronizeCheckBox_toggled(True) 134 self.on_synchronizeCheckBox_toggled(True)
135 135
136 font = Preferences.getEditorOtherFonts("MonospacedFont") 136 self.__generateFormats()
137 self.contents_1.setFontFamily(font.family())
138 self.contents_1.setFontPointSize(font.pointSize())
139 self.contents_2.setFontFamily(font.family())
140 self.contents_2.setFontPointSize(font.pointSize())
141 self.fontHeight = QFontMetrics(self.contents_1.currentFont()).height()
142
143 self.cNormalFormat = self.contents_1.currentCharFormat()
144 self.cInsertedFormat = self.contents_1.currentCharFormat()
145 self.cInsertedFormat.setBackground(QBrush(QColor(190, 237, 190)))
146 self.cDeletedFormat = self.contents_1.currentCharFormat()
147 self.cDeletedFormat.setBackground(QBrush(QColor(237, 190, 190)))
148 self.cReplacedFormat = self.contents_1.currentCharFormat()
149 self.cReplacedFormat.setBackground(QBrush(QColor(190, 190, 237)))
150 137
151 # connect some of our widgets explicitly 138 # connect some of our widgets explicitly
152 self.file1Picker.textChanged.connect(self.__fileChanged) 139 self.file1Picker.textChanged.connect(self.__fileChanged)
153 self.file2Picker.textChanged.connect(self.__fileChanged) 140 self.file2Picker.textChanged.connect(self.__fileChanged)
154 self.vsb1.valueChanged.connect(self.__scrollBarMoved) 141 self.vsb1.valueChanged.connect(self.__scrollBarMoved)
169 self.diffButton.hide() 156 self.diffButton.hide()
170 QTimer.singleShot(0, self.on_diffButton_clicked) 157 QTimer.singleShot(0, self.on_diffButton_clicked)
171 else: 158 else:
172 self.file1Label.hide() 159 self.file1Label.hide()
173 self.file2Label.hide() 160 self.file2Label.hide()
174 161
162 def __generateFormats(self):
163 """
164 Private method to generate the various text formats.
165 """
166 font = Preferences.getEditorOtherFonts("MonospacedFont")
167 self.contents_1.setFontFamily(font.family())
168 self.contents_1.setFontPointSize(font.pointSize())
169 self.contents_2.setFontFamily(font.family())
170 self.contents_2.setFontPointSize(font.pointSize())
171 self.fontHeight = QFontMetrics(self.contents_1.currentFont()).height()
172
173 self.cNormalFormat = self.contents_1.currentCharFormat()
174 self.cInsertedFormat = self.contents_1.currentCharFormat()
175 self.cInsertedFormat.setBackground(
176 QBrush(Preferences.getDiffColour("AddedColor")))
177 self.cDeletedFormat = self.contents_1.currentCharFormat()
178 self.cDeletedFormat.setBackground(
179 QBrush(Preferences.getDiffColour("RemovedColor")))
180 self.cReplacedFormat = self.contents_1.currentCharFormat()
181 self.cReplacedFormat.setBackground(
182 QBrush(Preferences.getDiffColour("ReplacedColor")))
183
175 def show(self, filename=None): 184 def show(self, filename=None):
176 """ 185 """
177 Public slot to show the dialog. 186 Public slot to show the dialog.
178 187
179 @param filename name of a file to use as the first file (string) 188 @param filename name of a file to use as the first file (string)
293 @param lines1 text to compare against (list of strings) 302 @param lines1 text to compare against (list of strings)
294 @param lines2 text to compare (list of strings) 303 @param lines2 text to compare (list of strings)
295 """ 304 """
296 self.contents_1.clear() 305 self.contents_1.clear()
297 self.contents_2.clear() 306 self.contents_2.clear()
307
308 self.__generateFormats()
298 309
299 # counters for changes 310 # counters for changes
300 added = 0 311 added = 0
301 deleted = 0 312 deleted = 0
302 changed = 0 313 changed = 0

eric ide

mercurial