36 def __init__(self, files=None, parent=None): |
36 def __init__(self, files=None, parent=None): |
37 """ |
37 """ |
38 Constructor |
38 Constructor |
39 |
39 |
40 @param files list of two file names to be diffed |
40 @param files list of two file names to be diffed |
41 @type list of two str |
41 @type list of [str, str] |
42 @param parent reference to the parent widget |
42 @param parent reference to the parent widget |
43 @type QWidget |
43 @type QWidget |
44 """ |
44 """ |
45 super().__init__(parent) |
45 super().__init__(parent) |
46 self.setupUi(self) |
46 self.setupUi(self) |
85 |
85 |
86 def show(self, filename=None): |
86 def show(self, filename=None): |
87 """ |
87 """ |
88 Public slot to show the dialog. |
88 Public slot to show the dialog. |
89 |
89 |
90 @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 |
|
91 @type str |
91 """ |
92 """ |
92 if filename: |
93 if filename: |
93 self.file1Picker.setText(filename) |
94 self.file1Picker.setText(filename) |
94 super().show() |
95 super().show() |
95 |
96 |
96 def on_buttonBox_clicked(self, button): |
97 def on_buttonBox_clicked(self, button): |
97 """ |
98 """ |
98 Private slot called by a button of the button box clicked. |
99 Private slot called by a button of the button box clicked. |
99 |
100 |
100 @param button button that was clicked (QAbstractButton) |
101 @param button button that was clicked |
|
102 @type QAbstractButton |
101 """ |
103 """ |
102 if button == self.diffButton: |
104 if button == self.diffButton: |
103 self.on_diffButton_clicked() |
105 self.on_diffButton_clicked() |
104 elif button == self.saveButton: |
106 elif button == self.saveButton: |
105 self.on_saveButton_clicked() |
107 self.on_saveButton_clicked() |
223 |
225 |
224 def __appendText(self, txt): |
226 def __appendText(self, txt): |
225 """ |
227 """ |
226 Private method to append text to the end of the contents pane. |
228 Private method to append text to the end of the contents pane. |
227 |
229 |
228 @param txt text to insert (string) |
230 @param txt text to insert |
|
231 @type str |
229 """ |
232 """ |
230 tc = self.contents.textCursor() |
233 tc = self.contents.textCursor() |
231 tc.movePosition(QTextCursor.MoveOperation.End) |
234 tc.movePosition(QTextCursor.MoveOperation.End) |
232 self.contents.setTextCursor(tc) |
235 self.contents.setTextCursor(tc) |
233 self.contents.insertPlainText(txt) |
236 self.contents.insertPlainText(txt) |
234 |
237 |
235 def __generateUnifiedDiff(self, a, b, fromfile, tofile, fromfiledate, tofiledate): |
238 def __generateUnifiedDiff(self, a, b, fromfile, tofile, fromfiledate, tofiledate): |
236 """ |
239 """ |
237 Private slot to generate a unified diff output. |
240 Private slot to generate a unified diff output. |
238 |
241 |
239 @param a first sequence of lines (list of strings) |
242 @param a first sequence of lines |
240 @param b second sequence of lines (list of strings) |
243 @type list of str |
241 @param fromfile filename of the first file (string) |
244 @param b second sequence of lines |
242 @param tofile filename of the second file (string) |
245 @type list of str |
243 @param fromfiledate modification time of the first file (string) |
246 @param fromfile filename of the first file |
244 @param tofiledate modification time of the second file (string) |
247 @type str |
|
248 @param tofile filename of the second file |
|
249 @type str |
|
250 @param fromfiledate modification time of the first file |
|
251 @type str |
|
252 @param tofiledate modification time of the second file |
|
253 @type str |
245 """ |
254 """ |
246 for paras, line in enumerate( |
255 for paras, line in enumerate( |
247 unified_diff(a, b, fromfile, tofile, fromfiledate, tofiledate) |
256 unified_diff(a, b, fromfile, tofile, fromfiledate, tofiledate) |
248 ): |
257 ): |
249 self.__appendText(line) |
258 self.__appendText(line) |
255 |
264 |
256 def __generateContextDiff(self, a, b, fromfile, tofile, fromfiledate, tofiledate): |
265 def __generateContextDiff(self, a, b, fromfile, tofile, fromfiledate, tofiledate): |
257 """ |
266 """ |
258 Private slot to generate a context diff output. |
267 Private slot to generate a context diff output. |
259 |
268 |
260 @param a first sequence of lines (list of strings) |
269 @param a first sequence of lines |
261 @param b second sequence of lines (list of strings) |
270 @type list of str |
262 @param fromfile filename of the first file (string) |
271 @param b second sequence of lines |
263 @param tofile filename of the second file (string) |
272 @type list of str |
264 @param fromfiledate modification time of the first file (string) |
273 @param fromfile filename of the first file |
265 @param tofiledate modification time of the second file (string) |
274 @type str |
|
275 @param tofile filename of the second file |
|
276 @type str |
|
277 @param fromfiledate modification time of the first file |
|
278 @type str |
|
279 @param tofiledate modification time of the second file |
|
280 @type str |
266 """ |
281 """ |
267 for paras, line in enumerate( |
282 for paras, line in enumerate( |
268 context_diff(a, b, fromfile, tofile, fromfiledate, tofiledate) |
283 context_diff(a, b, fromfile, tofile, fromfiledate, tofiledate) |
269 ): |
284 ): |
270 self.__appendText(line) |
285 self.__appendText(line) |
292 def __init__(self, files=None, parent=None): |
307 def __init__(self, files=None, parent=None): |
293 """ |
308 """ |
294 Constructor |
309 Constructor |
295 |
310 |
296 @param files list of two file names to be diffed |
311 @param files list of two file names to be diffed |
297 @type list of two str |
312 @type list of [str, str] |
298 @param parent reference to the parent widget |
313 @param parent reference to the parent widget |
299 @type QWidget |
314 @type QWidget |
300 """ |
315 """ |
301 super().__init__(parent) |
316 super().__init__(parent) |
302 |
317 |
310 |
325 |
311 def eventFilter(self, obj, event): |
326 def eventFilter(self, obj, event): |
312 """ |
327 """ |
313 Public method to filter events. |
328 Public method to filter events. |
314 |
329 |
315 @param obj reference to the object the event is meant for (QObject) |
330 @param obj reference to the object the event is meant for |
316 @param event reference to the event object (QEvent) |
331 @type QObject |
317 @return flag indicating, whether the event was handled (boolean) |
332 @param event reference to the event object |
|
333 @type QEvent |
|
334 @return flag indicating, whether the event was handled |
|
335 @rtype bool |
318 """ |
336 """ |
319 if event.type() == QEvent.Type.Close: |
337 if event.type() == QEvent.Type.Close: |
320 QApplication.exit() |
338 QApplication.exit() |
321 return True |
339 return True |
322 |
340 |