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