|
1 # -*- coding: utf-8 -*- |
|
2 |
|
3 # Copyright (c) 2006 - 2019 Detlev Offenbach <detlev@die-offenbachs.de> |
|
4 # |
|
5 |
|
6 """ |
|
7 Module implementing the Help Viewers configuration page. |
|
8 """ |
|
9 |
|
10 from __future__ import unicode_literals |
|
11 |
|
12 from PyQt5.QtCore import pyqtSlot |
|
13 from PyQt5.QtWidgets import QFontDialog |
|
14 |
|
15 from E5Gui.E5PathPicker import E5PathPickerModes |
|
16 |
|
17 from .ConfigurationPageBase import ConfigurationPageBase |
|
18 from .Ui_HelpAppearancePage import Ui_HelpAppearancePage |
|
19 |
|
20 import Preferences |
|
21 |
|
22 try: |
|
23 MonospacedFontsOption = QFontDialog.MonospacedFonts |
|
24 except AttributeError: |
|
25 MonospacedFontsOption = QFontDialog.FontDialogOptions(0x10) |
|
26 |
|
27 |
|
28 class HelpAppearancePage(ConfigurationPageBase, Ui_HelpAppearancePage): |
|
29 """ |
|
30 Class implementing the Help Viewer Appearance page. |
|
31 """ |
|
32 def __init__(self): |
|
33 """ |
|
34 Constructor |
|
35 """ |
|
36 super(HelpAppearancePage, self).__init__() |
|
37 self.setupUi(self) |
|
38 self.setObjectName("HelpAppearancePage") |
|
39 |
|
40 self.styleSheetPicker.setMode(E5PathPickerModes.OpenFileMode) |
|
41 self.styleSheetPicker.setFilters(self.tr( |
|
42 "Cascading Style Sheets (*.css);;All files (*)")) |
|
43 |
|
44 self.__displayMode = None |
|
45 |
|
46 # set initial values |
|
47 self.standardFont = Preferences.getHelp("StandardFont") |
|
48 self.standardFontSample.setFont(self.standardFont) |
|
49 self.standardFontSample.setText( |
|
50 "{0} {1}".format(self.standardFont.family(), |
|
51 self.standardFont.pointSize())) |
|
52 |
|
53 self.fixedFont = Preferences.getHelp("FixedFont") |
|
54 self.fixedFontSample.setFont(self.fixedFont) |
|
55 self.fixedFontSample.setText( |
|
56 "{0} {1}".format(self.fixedFont.family(), |
|
57 self.fixedFont.pointSize())) |
|
58 |
|
59 self.initColour("SaveUrlColor", self.secureURLsColourButton, |
|
60 Preferences.getHelp) |
|
61 |
|
62 self.autoLoadImagesCheckBox.setChecked( |
|
63 Preferences.getHelp("AutoLoadImages")) |
|
64 |
|
65 self.styleSheetPicker.setText(Preferences.getHelp("UserStyleSheet")) |
|
66 |
|
67 self.tabsCloseButtonCheckBox.setChecked( |
|
68 Preferences.getUI("SingleCloseButton")) |
|
69 self.warnOnMultipleCloseCheckBox.setChecked( |
|
70 Preferences.getHelp("WarnOnMultipleClose")) |
|
71 |
|
72 def setMode(self, displayMode): |
|
73 """ |
|
74 Public method to perform mode dependent setups. |
|
75 |
|
76 @param displayMode mode of the configuration dialog |
|
77 (ConfigurationWidget.DefaultMode, |
|
78 ConfigurationWidget.HelpBrowserMode, |
|
79 ConfigurationWidget.TrayStarterMode) |
|
80 """ |
|
81 from ..ConfigurationDialog import ConfigurationWidget |
|
82 assert displayMode in ( |
|
83 ConfigurationWidget.DefaultMode, |
|
84 ConfigurationWidget.HelpBrowserMode, |
|
85 ConfigurationWidget.TrayStarterMode |
|
86 ) |
|
87 |
|
88 self.__displayMode = displayMode |
|
89 if self.__displayMode != ConfigurationWidget.HelpBrowserMode: |
|
90 self.tabsGroupBox.hide() |
|
91 |
|
92 def save(self): |
|
93 """ |
|
94 Public slot to save the Help Viewers configuration. |
|
95 """ |
|
96 Preferences.setHelp("StandardFont", self.standardFont) |
|
97 Preferences.setHelp("FixedFont", self.fixedFont) |
|
98 |
|
99 Preferences.setHelp( |
|
100 "AutoLoadImages", |
|
101 self.autoLoadImagesCheckBox.isChecked()) |
|
102 |
|
103 Preferences.setHelp("UserStyleSheet", self.styleSheetPicker.text()) |
|
104 |
|
105 self.saveColours(Preferences.setHelp) |
|
106 |
|
107 from ..ConfigurationDialog import ConfigurationWidget |
|
108 if self.__displayMode == ConfigurationWidget.HelpBrowserMode: |
|
109 Preferences.setUI( |
|
110 "SingleCloseButton", |
|
111 self.tabsCloseButtonCheckBox.isChecked()) |
|
112 |
|
113 Preferences.setHelp( |
|
114 "WarnOnMultipleClose", |
|
115 self.warnOnMultipleCloseCheckBox.isChecked()) |
|
116 |
|
117 @pyqtSlot() |
|
118 def on_standardFontButton_clicked(self): |
|
119 """ |
|
120 Private method used to select the standard font. |
|
121 """ |
|
122 self.standardFont = \ |
|
123 self.selectFont(self.standardFontSample, self.standardFont, True) |
|
124 |
|
125 @pyqtSlot() |
|
126 def on_fixedFontButton_clicked(self): |
|
127 """ |
|
128 Private method used to select the fixed-width font. |
|
129 """ |
|
130 self.fixedFont = self.selectFont( |
|
131 self.fixedFontSample, self.fixedFont, True, |
|
132 options=MonospacedFontsOption) |
|
133 |
|
134 |
|
135 def create(dlg): |
|
136 """ |
|
137 Module function to create the configuration page. |
|
138 |
|
139 @param dlg reference to the configuration dialog |
|
140 @return reference to the instantiated page (ConfigurationPageBase) |
|
141 """ |
|
142 page = HelpAppearancePage() |
|
143 return page |