|
1 # -*- coding: utf-8 -*- |
|
2 |
|
3 # Copyright (c) 2016 - 2021 Detlev Offenbach <detlev@die-offenbachs.de> |
|
4 # |
|
5 |
|
6 |
|
7 """ |
|
8 Module implementing the Hex Editor configuration page. |
|
9 """ |
|
10 |
|
11 from PyQt5.QtCore import pyqtSlot |
|
12 from PyQt5.QtWidgets import QFontDialog |
|
13 |
|
14 from .ConfigurationPageBase import ConfigurationPageBase |
|
15 from .Ui_HexEditorPage import Ui_HexEditorPage |
|
16 |
|
17 import Preferences |
|
18 |
|
19 try: |
|
20 MonospacedFontsOption = QFontDialog.FontDialogOption.MonospacedFonts |
|
21 except AttributeError: |
|
22 MonospacedFontsOption = QFontDialog.FontDialogOptions(0x10) |
|
23 |
|
24 |
|
25 class HexEditorPage(ConfigurationPageBase, Ui_HexEditorPage): |
|
26 """ |
|
27 Class implementing the Hex Editor configuration page. |
|
28 """ |
|
29 def __init__(self): |
|
30 """ |
|
31 Constructor |
|
32 """ |
|
33 super().__init__() |
|
34 self.setupUi(self) |
|
35 self.setObjectName("HexEditorPage") |
|
36 |
|
37 # set initial values |
|
38 self.readOnlyCheckBox.setChecked(Preferences.getHexEditor( |
|
39 "OpenReadOnly")) |
|
40 self.overwriteCheckBox.setChecked(Preferences.getHexEditor( |
|
41 "OpenInOverwriteMode")) |
|
42 self.addressAreaCheckBox.setChecked(Preferences.getHexEditor( |
|
43 "ShowAddressArea")) |
|
44 self.addressAreaWidthSpinBox.setValue(Preferences.getHexEditor( |
|
45 "AddressAreaWidth")) |
|
46 self.asciiAreaCheckBox.setChecked(Preferences.getHexEditor( |
|
47 "ShowAsciiArea")) |
|
48 self.highlightingCheckBox.setChecked(Preferences.getHexEditor( |
|
49 "HighlightChanges")) |
|
50 self.recentFilesSpinBox.setValue(Preferences.getHexEditor( |
|
51 "RecentNumber")) |
|
52 |
|
53 # font |
|
54 self.monospacedFont = Preferences.getHexEditor("Font") |
|
55 self.monospacedFontSample.setFont(self.monospacedFont) |
|
56 |
|
57 # colours |
|
58 self.initColour("HighlightingBackGround", |
|
59 self.highlightingBackGroundButton, |
|
60 Preferences.getHexEditor) |
|
61 self.initColour("HighlightingForeGround", |
|
62 self.highlightingForeGroundButton, |
|
63 Preferences.getHexEditor) |
|
64 self.initColour("SelectionBackGround", |
|
65 self.selectionBackGroundButton, |
|
66 Preferences.getHexEditor) |
|
67 self.initColour("SelectionForeGround", |
|
68 self.selectionForeGroundButton, |
|
69 Preferences.getHexEditor) |
|
70 self.initColour("AddressAreaBackGround", |
|
71 self.addressAreaBackGroundButton, |
|
72 Preferences.getHexEditor) |
|
73 self.initColour("AddressAreaForeGround", |
|
74 self.addressAreaForeGroundButton, |
|
75 Preferences.getHexEditor) |
|
76 |
|
77 def save(self): |
|
78 """ |
|
79 Public slot to save the IRC configuration. |
|
80 """ |
|
81 Preferences.setHexEditor( |
|
82 "OpenReadOnly", self.readOnlyCheckBox.isChecked()) |
|
83 Preferences.setHexEditor( |
|
84 "OpenInOverwriteMode", self.overwriteCheckBox.isChecked()) |
|
85 Preferences.setHexEditor( |
|
86 "ShowAddressArea", self.addressAreaCheckBox.isChecked()) |
|
87 Preferences.setHexEditor( |
|
88 "AddressAreaWidth", self.addressAreaWidthSpinBox.value()) |
|
89 Preferences.setHexEditor( |
|
90 "ShowAsciiArea", self.asciiAreaCheckBox.isChecked()) |
|
91 Preferences.setHexEditor( |
|
92 "HighlightChanges", self.highlightingCheckBox.isChecked()) |
|
93 Preferences.setHexEditor( |
|
94 "Font", self.monospacedFont) |
|
95 Preferences.setHexEditor( |
|
96 "RecentNumber", self.recentFilesSpinBox.value()) |
|
97 |
|
98 # colours |
|
99 self.saveColours(Preferences.setHexEditor) |
|
100 |
|
101 @pyqtSlot() |
|
102 def on_monospacedFontButton_clicked(self): |
|
103 """ |
|
104 Private method used to select the font to be used. |
|
105 """ |
|
106 self.monospacedFont = self.selectFont( |
|
107 self.monospacedFontSample, self.monospacedFont, |
|
108 options=MonospacedFontsOption) |
|
109 |
|
110 def polishPage(self): |
|
111 """ |
|
112 Public slot to perform some polishing actions. |
|
113 """ |
|
114 self.monospacedFontSample.setFont(self.monospacedFont) |
|
115 |
|
116 |
|
117 def create(dlg): |
|
118 """ |
|
119 Module function to create the configuration page. |
|
120 |
|
121 @param dlg reference to the configuration dialog |
|
122 @return reference to the instantiated page (ConfigurationPageBase) |
|
123 """ |
|
124 page = HexEditorPage() |
|
125 return page |