|
1 # -*- coding: utf-8 -*- |
|
2 |
|
3 # Copyright (c) 2006 - 2021 Detlev Offenbach <detlev@die-offenbachs.de> |
|
4 # |
|
5 |
|
6 """ |
|
7 Module implementing the Templates configuration page. |
|
8 """ |
|
9 |
|
10 from PyQt5.QtCore import pyqtSlot |
|
11 from PyQt5.QtWidgets import QFontDialog |
|
12 |
|
13 from .ConfigurationPageBase import ConfigurationPageBase |
|
14 from .Ui_TemplatesPage import Ui_TemplatesPage |
|
15 |
|
16 import Preferences |
|
17 |
|
18 try: |
|
19 MonospacedFontsOption = QFontDialog.FontDialogOption.MonospacedFonts |
|
20 except AttributeError: |
|
21 MonospacedFontsOption = QFontDialog.FontDialogOptions(0x10) |
|
22 |
|
23 |
|
24 class TemplatesPage(ConfigurationPageBase, Ui_TemplatesPage): |
|
25 """ |
|
26 Class implementing the Templates configuration page. |
|
27 """ |
|
28 def __init__(self): |
|
29 """ |
|
30 Constructor |
|
31 """ |
|
32 super().__init__() |
|
33 self.setupUi(self) |
|
34 self.setObjectName("TemplatesPage") |
|
35 |
|
36 # set initial values |
|
37 self.templatesAutoOpenGroupsCheckBox.setChecked( |
|
38 Preferences.getTemplates("AutoOpenGroups")) |
|
39 self.templatesSeparatorCharEdit.setText( |
|
40 Preferences.getTemplates("SeparatorChar")) |
|
41 if Preferences.getTemplates("SingleDialog"): |
|
42 self.templatesSingleDialogButton.setChecked(True) |
|
43 else: |
|
44 self.templatesMultiDialogButton.setChecked(True) |
|
45 self.templatesToolTipCheckBox.setChecked( |
|
46 Preferences.getTemplates("ShowTooltip")) |
|
47 self.editorFont = Preferences.getTemplates("EditorFont") |
|
48 self.editorFontSample.setFont(self.editorFont) |
|
49 |
|
50 def save(self): |
|
51 """ |
|
52 Public slot to save the Templates configuration. |
|
53 """ |
|
54 Preferences.setTemplates( |
|
55 "AutoOpenGroups", |
|
56 self.templatesAutoOpenGroupsCheckBox.isChecked()) |
|
57 sepChar = self.templatesSeparatorCharEdit.text() |
|
58 if sepChar: |
|
59 Preferences.setTemplates("SeparatorChar", sepChar) |
|
60 Preferences.setTemplates( |
|
61 "SingleDialog", |
|
62 self.templatesSingleDialogButton.isChecked()) |
|
63 Preferences.setTemplates( |
|
64 "ShowTooltip", |
|
65 self.templatesToolTipCheckBox.isChecked()) |
|
66 Preferences.setTemplates("EditorFont", self.editorFont) |
|
67 |
|
68 @pyqtSlot() |
|
69 def on_editorFontButton_clicked(self): |
|
70 """ |
|
71 Private method used to select the font to be used by the code editor. |
|
72 """ |
|
73 self.editorFont = self.selectFont( |
|
74 self.editorFontSample, self.editorFont, |
|
75 options=MonospacedFontsOption) |
|
76 |
|
77 |
|
78 def create(dlg): |
|
79 """ |
|
80 Module function to create the configuration page. |
|
81 |
|
82 @param dlg reference to the configuration dialog |
|
83 @return reference to the instantiated page (ConfigurationPageBase) |
|
84 """ |
|
85 page = TemplatesPage() |
|
86 return page |