|
1 # -*- coding: utf-8 -*- |
|
2 |
|
3 # Copyright (c) 2022 Detlev Offenbach <detlev@die-offenbachs.de> |
|
4 # |
|
5 |
|
6 """ |
|
7 Module implementing a window to show a unified diff.. |
|
8 """ |
|
9 |
|
10 from PyQt6.QtWidgets import QWidget |
|
11 |
|
12 from .Ui_BlackDiffWidget import Ui_BlackDiffWidget |
|
13 |
|
14 from UI.DiffHighlighter import DiffHighlighter |
|
15 |
|
16 import Preferences |
|
17 |
|
18 |
|
19 class BlackDiffWidget(QWidget, Ui_BlackDiffWidget): |
|
20 """ |
|
21 Class implementing a window to show a unified diff.. |
|
22 """ |
|
23 def __init__(self, parent=None): |
|
24 """ |
|
25 Constructor |
|
26 |
|
27 @param parent reference to the parent widget (defaults to None) |
|
28 @type QWidget (optional) |
|
29 """ |
|
30 super().__init__(parent) |
|
31 self.setupUi(self) |
|
32 |
|
33 font = Preferences.getEditorOtherFonts("MonospacedFont") |
|
34 self.diffEdit.document().setDefaultFont(font) |
|
35 |
|
36 self.__highlighter = DiffHighlighter(self.diffEdit.document()) |
|
37 self.__savedGeometry = None |
|
38 |
|
39 def showDiff(self, diff): |
|
40 """ |
|
41 Public method to show the given diff. |
|
42 |
|
43 @param diff text containing the unified diff |
|
44 @type str |
|
45 """ |
|
46 self.diffEdit.clear() |
|
47 self.__highlighter.regenerateRules() |
|
48 |
|
49 if diff: |
|
50 self.diffEdit.setPlainText(diff) |
|
51 else: |
|
52 self.diffEdit.setPlainText(self.tr('There is no difference.')) |
|
53 |
|
54 if self.__savedGeometry is not None: |
|
55 self.restoreGeometry(self.__savedGeometry) |
|
56 |
|
57 self.show() |
|
58 |
|
59 def closeEvent(self, evt): |
|
60 """ |
|
61 Protected slot implementing a close event handler. |
|
62 |
|
63 @param evt reference to the close event |
|
64 @type QCloseEvent |
|
65 """ |
|
66 self.__savedGeometry = self.saveGeometry() |