|
1 # -*- coding: utf-8 -*- |
|
2 |
|
3 # Copyright (c) 2007 - 2019 Detlev Offenbach <detlev@die-offenbachs.de> |
|
4 # |
|
5 |
|
6 """ |
|
7 Module implementing the Editor Exporters 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 .ConfigurationPageBase import ConfigurationPageBase |
|
16 from .Ui_EditorExportersPage import Ui_EditorExportersPage |
|
17 |
|
18 import Preferences |
|
19 |
|
20 |
|
21 class EditorExportersPage(ConfigurationPageBase, Ui_EditorExportersPage): |
|
22 """ |
|
23 Class implementing the Editor Typing configuration page. |
|
24 """ |
|
25 def __init__(self): |
|
26 """ |
|
27 Constructor |
|
28 """ |
|
29 super(EditorExportersPage, self).__init__() |
|
30 self.setupUi(self) |
|
31 self.setObjectName("EditorExportersPage") |
|
32 |
|
33 # set initial values |
|
34 self.pageIds = {} |
|
35 self.pageIds[' '] = self.stackedWidget.indexOf(self.emptyPage) |
|
36 self.pageIds['HTML'] = self.stackedWidget.indexOf(self.htmlPage) |
|
37 self.pageIds['ODT'] = self.stackedWidget.indexOf(self.odtPage) |
|
38 self.pageIds['PDF'] = self.stackedWidget.indexOf(self.pdfPage) |
|
39 self.pageIds['RTF'] = self.stackedWidget.indexOf(self.rtfPage) |
|
40 self.pageIds['TeX'] = self.stackedWidget.indexOf(self.texPage) |
|
41 exporters = sorted(list(self.pageIds.keys())) |
|
42 for exporter in exporters: |
|
43 self.exportersCombo.addItem(exporter, self.pageIds[exporter]) |
|
44 |
|
45 self.pdfFontCombo.addItem(self.tr("Courier"), "Courier") |
|
46 self.pdfFontCombo.addItem(self.tr("Helvetica"), "Helvetica") |
|
47 self.pdfFontCombo.addItem(self.tr("Times"), "Times") |
|
48 |
|
49 self.pdfPageSizeCombo.addItem(self.tr("A4"), "A4") |
|
50 self.pdfPageSizeCombo.addItem(self.tr("Letter"), "Letter") |
|
51 |
|
52 # HTML |
|
53 self.htmlWysiwygCheckBox.setChecked( |
|
54 Preferences.getEditorExporter("HTML/WYSIWYG")) |
|
55 self.htmlFoldingCheckBox.setChecked( |
|
56 Preferences.getEditorExporter("HTML/Folding")) |
|
57 self.htmlStylesCheckBox.setChecked( |
|
58 Preferences.getEditorExporter("HTML/OnlyStylesUsed")) |
|
59 self.htmlTitleCheckBox.setChecked( |
|
60 Preferences.getEditorExporter("HTML/FullPathAsTitle")) |
|
61 self.htmlTabsCheckBox.setChecked( |
|
62 Preferences.getEditorExporter("HTML/UseTabs")) |
|
63 |
|
64 # ODT |
|
65 self.odtWysiwygCheckBox.setChecked( |
|
66 Preferences.getEditorExporter("ODT/WYSIWYG")) |
|
67 self.odtStylesCheckBox.setChecked( |
|
68 Preferences.getEditorExporter("ODT/OnlyStylesUsed")) |
|
69 self.odtTabsCheckBox.setChecked( |
|
70 Preferences.getEditorExporter("ODT/UseTabs")) |
|
71 |
|
72 # PDF |
|
73 self.pdfMagnificationSlider.setValue( |
|
74 Preferences.getEditorExporter("PDF/Magnification")) |
|
75 ind = self.pdfFontCombo.findData( |
|
76 Preferences.getEditorExporter("PDF/Font")) |
|
77 self.pdfFontCombo.setCurrentIndex(ind) |
|
78 ind = self.pdfPageSizeCombo.findData( |
|
79 Preferences.getEditorExporter("PDF/PageSize")) |
|
80 self.pdfPageSizeCombo.setCurrentIndex(ind) |
|
81 self.pdfMarginTopSpin.setValue( |
|
82 Preferences.getEditorExporter("PDF/MarginTop")) |
|
83 self.pdfMarginBottomSpin.setValue( |
|
84 Preferences.getEditorExporter("PDF/MarginBottom")) |
|
85 self.pdfMarginLeftSpin.setValue( |
|
86 Preferences.getEditorExporter("PDF/MarginLeft")) |
|
87 self.pdfMarginRightSpin.setValue( |
|
88 Preferences.getEditorExporter("PDF/MarginRight")) |
|
89 |
|
90 # RTF |
|
91 self.rtfWysiwygCheckBox.setChecked( |
|
92 Preferences.getEditorExporter("RTF/WYSIWYG")) |
|
93 self.rtfTabsCheckBox.setChecked( |
|
94 Preferences.getEditorExporter("RTF/UseTabs")) |
|
95 self.rtfFont = Preferences.getEditorExporter("RTF/Font") |
|
96 self.rtfFontSample.setFont(self.rtfFont) |
|
97 |
|
98 # TeX |
|
99 self.texStylesCheckBox.setChecked( |
|
100 Preferences.getEditorExporter("TeX/OnlyStylesUsed")) |
|
101 self.texTitleCheckBox.setChecked( |
|
102 Preferences.getEditorExporter("TeX/FullPathAsTitle")) |
|
103 |
|
104 self.on_exportersCombo_activated(' ') |
|
105 |
|
106 def save(self): |
|
107 """ |
|
108 Public slot to save the Editor Typing configuration. |
|
109 """ |
|
110 # HTML |
|
111 Preferences.setEditorExporter( |
|
112 "HTML/WYSIWYG", |
|
113 self.htmlWysiwygCheckBox.isChecked()) |
|
114 Preferences.setEditorExporter( |
|
115 "HTML/Folding", |
|
116 self.htmlFoldingCheckBox.isChecked()) |
|
117 Preferences.setEditorExporter( |
|
118 "HTML/OnlyStylesUsed", |
|
119 self.htmlStylesCheckBox.isChecked()) |
|
120 Preferences.setEditorExporter( |
|
121 "HTML/FullPathAsTitle", |
|
122 self.htmlTitleCheckBox.isChecked()) |
|
123 Preferences.setEditorExporter( |
|
124 "HTML/UseTabs", |
|
125 self.htmlTabsCheckBox.isChecked()) |
|
126 |
|
127 # ODT |
|
128 Preferences.setEditorExporter( |
|
129 "ODT/WYSIWYG", |
|
130 self.odtWysiwygCheckBox.isChecked()) |
|
131 Preferences.setEditorExporter( |
|
132 "ODT/OnlyStylesUsed", |
|
133 self.odtStylesCheckBox.isChecked()) |
|
134 Preferences.setEditorExporter( |
|
135 "ODT/UseTabs", |
|
136 self.odtTabsCheckBox.isChecked()) |
|
137 |
|
138 # PDF |
|
139 Preferences.setEditorExporter( |
|
140 "PDF/Magnification", |
|
141 self.pdfMagnificationSlider.value()) |
|
142 Preferences.setEditorExporter( |
|
143 "PDF/Font", |
|
144 self.pdfFontCombo.itemData(self.pdfFontCombo.currentIndex())) |
|
145 Preferences.setEditorExporter( |
|
146 "PDF/PageSize", |
|
147 self.pdfPageSizeCombo.itemData( |
|
148 self.pdfPageSizeCombo.currentIndex())) |
|
149 Preferences.setEditorExporter( |
|
150 "PDF/MarginTop", |
|
151 self.pdfMarginTopSpin.value()) |
|
152 Preferences.setEditorExporter( |
|
153 "PDF/MarginBottom", |
|
154 self.pdfMarginBottomSpin.value()) |
|
155 Preferences.setEditorExporter( |
|
156 "PDF/MarginLeft", |
|
157 self.pdfMarginLeftSpin.value()) |
|
158 Preferences.setEditorExporter( |
|
159 "PDF/MarginRight", |
|
160 self.pdfMarginRightSpin.value()) |
|
161 |
|
162 # RTF |
|
163 Preferences.setEditorExporter( |
|
164 "RTF/WYSIWYG", |
|
165 self.rtfWysiwygCheckBox.isChecked()) |
|
166 Preferences.setEditorExporter( |
|
167 "RTF/UseTabs", |
|
168 self.rtfTabsCheckBox.isChecked()) |
|
169 Preferences.setEditorExporter("RTF/Font", self.rtfFont) |
|
170 |
|
171 # TeX |
|
172 Preferences.setEditorExporter( |
|
173 "TeX/OnlyStylesUsed", |
|
174 self.texStylesCheckBox.isChecked()) |
|
175 Preferences.setEditorExporter( |
|
176 "TeX/FullPathAsTitle", |
|
177 self.texTitleCheckBox.isChecked()) |
|
178 |
|
179 @pyqtSlot(str) |
|
180 def on_exportersCombo_activated(self, exporter): |
|
181 """ |
|
182 Private slot to select the page related to the selected exporter. |
|
183 |
|
184 @param exporter name of the selected exporter (string) |
|
185 """ |
|
186 try: |
|
187 index = self.pageIds[exporter] |
|
188 except KeyError: |
|
189 index = self.pageIds[' '] |
|
190 self.stackedWidget.setCurrentIndex(index) |
|
191 |
|
192 @pyqtSlot() |
|
193 def on_rtfFontButton_clicked(self): |
|
194 """ |
|
195 Private method used to select the font for the RTF export. |
|
196 """ |
|
197 font, ok = QFontDialog.getFont(self.rtfFont) |
|
198 if ok: |
|
199 self.rtfFontSample.setFont(font) |
|
200 self.rtfFont = font |
|
201 |
|
202 |
|
203 def create(dlg): |
|
204 """ |
|
205 Module function to create the configuration page. |
|
206 |
|
207 @param dlg reference to the configuration dialog |
|
208 @return reference to the instantiated page (ConfigurationPageBase) |
|
209 """ |
|
210 page = EditorExportersPage() |
|
211 return page |