src/eric7/Preferences/ConfigurationPages/EditorExportersPage.py

branch
eric7
changeset 9209
b99e7fd55fd3
parent 8881
54e42bc2437a
child 9221
bf71ee032bb4
equal deleted inserted replaced
9208:3fc8dfeb6ebe 9209:b99e7fd55fd3
1 # -*- coding: utf-8 -*-
2
3 # Copyright (c) 2007 - 2022 Detlev Offenbach <detlev@die-offenbachs.de>
4 #
5
6 """
7 Module implementing the Editor Exporters configuration page.
8 """
9
10 from PyQt6.QtCore import pyqtSlot
11 from PyQt6.QtWidgets import QFontDialog
12
13 from .ConfigurationPageBase import ConfigurationPageBase
14 from .Ui_EditorExportersPage import Ui_EditorExportersPage
15
16 import Preferences
17
18
19 class EditorExportersPage(ConfigurationPageBase, Ui_EditorExportersPage):
20 """
21 Class implementing the Editor Typing configuration page.
22 """
23 def __init__(self):
24 """
25 Constructor
26 """
27 super().__init__()
28 self.setupUi(self)
29 self.setObjectName("EditorExportersPage")
30
31 # set initial values
32 self.pageIds = {}
33 self.pageIds[' '] = self.stackedWidget.indexOf(self.emptyPage)
34 self.pageIds['HTML'] = self.stackedWidget.indexOf(self.htmlPage)
35 self.pageIds['ODT'] = self.stackedWidget.indexOf(self.odtPage)
36 self.pageIds['PDF'] = self.stackedWidget.indexOf(self.pdfPage)
37 self.pageIds['RTF'] = self.stackedWidget.indexOf(self.rtfPage)
38 self.pageIds['TeX'] = self.stackedWidget.indexOf(self.texPage)
39 exporters = sorted(self.pageIds.keys())
40 for exporter in exporters:
41 self.exportersCombo.addItem(exporter, self.pageIds[exporter])
42
43 self.pdfFontCombo.addItem(self.tr("Courier"), "Courier")
44 self.pdfFontCombo.addItem(self.tr("Helvetica"), "Helvetica")
45 self.pdfFontCombo.addItem(self.tr("Times"), "Times")
46
47 self.pdfPageSizeCombo.addItem(self.tr("A4"), "A4")
48 self.pdfPageSizeCombo.addItem(self.tr("Letter"), "Letter")
49
50 # HTML
51 self.htmlWysiwygCheckBox.setChecked(
52 Preferences.getEditorExporter("HTML/WYSIWYG"))
53 self.htmlFoldingCheckBox.setChecked(
54 Preferences.getEditorExporter("HTML/Folding"))
55 self.htmlStylesCheckBox.setChecked(
56 Preferences.getEditorExporter("HTML/OnlyStylesUsed"))
57 self.htmlTitleCheckBox.setChecked(
58 Preferences.getEditorExporter("HTML/FullPathAsTitle"))
59 self.htmlTabsCheckBox.setChecked(
60 Preferences.getEditorExporter("HTML/UseTabs"))
61
62 # ODT
63 self.odtWysiwygCheckBox.setChecked(
64 Preferences.getEditorExporter("ODT/WYSIWYG"))
65 self.odtStylesCheckBox.setChecked(
66 Preferences.getEditorExporter("ODT/OnlyStylesUsed"))
67 self.odtTabsCheckBox.setChecked(
68 Preferences.getEditorExporter("ODT/UseTabs"))
69
70 # PDF
71 self.pdfMagnificationSlider.setValue(
72 Preferences.getEditorExporter("PDF/Magnification"))
73 ind = self.pdfFontCombo.findData(
74 Preferences.getEditorExporter("PDF/Font"))
75 self.pdfFontCombo.setCurrentIndex(ind)
76 ind = self.pdfPageSizeCombo.findData(
77 Preferences.getEditorExporter("PDF/PageSize"))
78 self.pdfPageSizeCombo.setCurrentIndex(ind)
79 self.pdfMarginTopSpin.setValue(
80 Preferences.getEditorExporter("PDF/MarginTop"))
81 self.pdfMarginBottomSpin.setValue(
82 Preferences.getEditorExporter("PDF/MarginBottom"))
83 self.pdfMarginLeftSpin.setValue(
84 Preferences.getEditorExporter("PDF/MarginLeft"))
85 self.pdfMarginRightSpin.setValue(
86 Preferences.getEditorExporter("PDF/MarginRight"))
87
88 # RTF
89 self.rtfWysiwygCheckBox.setChecked(
90 Preferences.getEditorExporter("RTF/WYSIWYG"))
91 self.rtfTabsCheckBox.setChecked(
92 Preferences.getEditorExporter("RTF/UseTabs"))
93 self.rtfFont = Preferences.getEditorExporter("RTF/Font")
94 self.rtfFontSample.setFont(self.rtfFont)
95
96 # TeX
97 self.texStylesCheckBox.setChecked(
98 Preferences.getEditorExporter("TeX/OnlyStylesUsed"))
99 self.texTitleCheckBox.setChecked(
100 Preferences.getEditorExporter("TeX/FullPathAsTitle"))
101
102 self.on_exportersCombo_activated(0)
103
104 def save(self):
105 """
106 Public slot to save the Editor Typing configuration.
107 """
108 # HTML
109 Preferences.setEditorExporter(
110 "HTML/WYSIWYG",
111 self.htmlWysiwygCheckBox.isChecked())
112 Preferences.setEditorExporter(
113 "HTML/Folding",
114 self.htmlFoldingCheckBox.isChecked())
115 Preferences.setEditorExporter(
116 "HTML/OnlyStylesUsed",
117 self.htmlStylesCheckBox.isChecked())
118 Preferences.setEditorExporter(
119 "HTML/FullPathAsTitle",
120 self.htmlTitleCheckBox.isChecked())
121 Preferences.setEditorExporter(
122 "HTML/UseTabs",
123 self.htmlTabsCheckBox.isChecked())
124
125 # ODT
126 Preferences.setEditorExporter(
127 "ODT/WYSIWYG",
128 self.odtWysiwygCheckBox.isChecked())
129 Preferences.setEditorExporter(
130 "ODT/OnlyStylesUsed",
131 self.odtStylesCheckBox.isChecked())
132 Preferences.setEditorExporter(
133 "ODT/UseTabs",
134 self.odtTabsCheckBox.isChecked())
135
136 # PDF
137 Preferences.setEditorExporter(
138 "PDF/Magnification",
139 self.pdfMagnificationSlider.value())
140 Preferences.setEditorExporter(
141 "PDF/Font",
142 self.pdfFontCombo.itemData(self.pdfFontCombo.currentIndex()))
143 Preferences.setEditorExporter(
144 "PDF/PageSize",
145 self.pdfPageSizeCombo.itemData(
146 self.pdfPageSizeCombo.currentIndex()))
147 Preferences.setEditorExporter(
148 "PDF/MarginTop",
149 self.pdfMarginTopSpin.value())
150 Preferences.setEditorExporter(
151 "PDF/MarginBottom",
152 self.pdfMarginBottomSpin.value())
153 Preferences.setEditorExporter(
154 "PDF/MarginLeft",
155 self.pdfMarginLeftSpin.value())
156 Preferences.setEditorExporter(
157 "PDF/MarginRight",
158 self.pdfMarginRightSpin.value())
159
160 # RTF
161 Preferences.setEditorExporter(
162 "RTF/WYSIWYG",
163 self.rtfWysiwygCheckBox.isChecked())
164 Preferences.setEditorExporter(
165 "RTF/UseTabs",
166 self.rtfTabsCheckBox.isChecked())
167 Preferences.setEditorExporter("RTF/Font", self.rtfFont)
168
169 # TeX
170 Preferences.setEditorExporter(
171 "TeX/OnlyStylesUsed",
172 self.texStylesCheckBox.isChecked())
173 Preferences.setEditorExporter(
174 "TeX/FullPathAsTitle",
175 self.texTitleCheckBox.isChecked())
176
177 @pyqtSlot(int)
178 def on_exportersCombo_activated(self, index):
179 """
180 Private slot to select the page related to the selected exporter.
181
182 @param index index of the selected entry
183 @type int
184 """
185 exporter = self.exportersCombo.itemText(index)
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

eric ide

mercurial