|
1 # -*- coding: utf-8 -*- |
|
2 |
|
3 # Copyright (c) 2006 - 2009 Detlev Offenbach <detlev@die-offenbachs.de> |
|
4 # |
|
5 |
|
6 """ |
|
7 Module implementing the Interface configuration page. |
|
8 """ |
|
9 |
|
10 import glob |
|
11 import os |
|
12 |
|
13 from PyQt4.QtCore import pyqtSlot, QVariant, QTranslator, qVersion |
|
14 from PyQt4.QtGui import QStyleFactory, QFileDialog |
|
15 |
|
16 from E4Gui.E4Completers import E4FileCompleter |
|
17 |
|
18 from ConfigurationPageBase import ConfigurationPageBase |
|
19 from Ui_InterfacePage import Ui_InterfacePage |
|
20 |
|
21 import Preferences |
|
22 import Utilities |
|
23 |
|
24 from eric4config import getConfig |
|
25 |
|
26 class InterfacePage(ConfigurationPageBase, Ui_InterfacePage): |
|
27 """ |
|
28 Class implementing the Interface configuration page. |
|
29 """ |
|
30 def __init__(self): |
|
31 """ |
|
32 Constructor |
|
33 """ |
|
34 ConfigurationPageBase.__init__(self) |
|
35 self.setupUi(self) |
|
36 self.setObjectName("InterfacePage") |
|
37 |
|
38 self.styleSheetCompleter = E4FileCompleter(self.styleSheetEdit) |
|
39 |
|
40 self.uiColours = {} |
|
41 |
|
42 # set initial values |
|
43 self.__populateStyleCombo() |
|
44 self.__populateLanguageCombo() |
|
45 |
|
46 self.uiBrowsersListFoldersFirstCheckBox.setChecked( |
|
47 Preferences.getUI("BrowsersListFoldersFirst")) |
|
48 self.uiBrowsersHideNonPublicCheckBox.setChecked( |
|
49 Preferences.getUI("BrowsersHideNonPublic")) |
|
50 self.uiBrowsersSortByOccurrenceCheckBox.setChecked( |
|
51 Preferences.getUI("BrowsersListContentsByOccurrence")) |
|
52 |
|
53 self.lvAutoRaiseCheckBox.setChecked( |
|
54 Preferences.getUI("LogViewerAutoRaise")) |
|
55 |
|
56 self.uiCaptionShowsFilenameGroupBox.setChecked( |
|
57 Preferences.getUI("CaptionShowsFilename")) |
|
58 self.filenameLengthSpinBox.setValue(\ |
|
59 Preferences.getUI("CaptionFilenameLength")) |
|
60 self.styleSheetEdit.setText(Preferences.getUI("StyleSheet")) |
|
61 |
|
62 if Preferences.getUI("TopLeftByLeft"): |
|
63 self.tlLeftButton.setChecked(True) |
|
64 else: |
|
65 self.tlTopButton.setChecked(True) |
|
66 if Preferences.getUI("BottomLeftByLeft"): |
|
67 self.blLeftButton.setChecked(True) |
|
68 else: |
|
69 self.blBottomButton.setChecked(True) |
|
70 if Preferences.getUI("TopRightByRight"): |
|
71 self.trRightButton.setChecked(True) |
|
72 else: |
|
73 self.trTopButton.setChecked(True) |
|
74 if Preferences.getUI("BottomRightByRight"): |
|
75 self.brRightButton.setChecked(True) |
|
76 else: |
|
77 self.brTopButton.setChecked(True) |
|
78 |
|
79 layout = Preferences.getUILayout() |
|
80 if layout[0] == "DockWindows": |
|
81 index = 0 |
|
82 elif layout[0] == "FloatingWindows": |
|
83 index = 1 |
|
84 elif layout[0] == "Toolboxes": |
|
85 index = 2 |
|
86 elif layout[0] == "Sidebars": |
|
87 index = 3 |
|
88 else: |
|
89 index = 3 # default for bad values |
|
90 self.layoutComboBox.setCurrentIndex(index) |
|
91 if layout[1] == 0: |
|
92 self.separateShellButton.setChecked(True) |
|
93 else: |
|
94 self.debugEmbeddedShellButton.setChecked(True) |
|
95 if layout[2] == 0: |
|
96 self.separateFileBrowserButton.setChecked(True) |
|
97 elif layout[2] == 1: |
|
98 self.debugEmbeddedFileBrowserButton.setChecked(True) |
|
99 else: |
|
100 self.projectEmbeddedFileBrowserButton.setChecked(True) |
|
101 |
|
102 if qVersion() < '4.5.0': |
|
103 self.tabsGroupBox.setEnabled(False) |
|
104 self.tabsCloseButtonCheckBox.setChecked(True) |
|
105 else: |
|
106 self.tabsGroupBox.setEnabled(True) |
|
107 self.tabsCloseButtonCheckBox.setChecked( |
|
108 Preferences.getUI("SingleCloseButton")) |
|
109 |
|
110 self.uiColours["LogStdErrColour"] = \ |
|
111 self.initColour("LogStdErrColour", self.stderrTextColourButton, |
|
112 Preferences.getUI) |
|
113 |
|
114 def save(self): |
|
115 """ |
|
116 Public slot to save the Interface configuration. |
|
117 """ |
|
118 # save the style settings |
|
119 styleIndex = self.styleComboBox.currentIndex() |
|
120 style = self.styleComboBox.itemData(styleIndex).toString() |
|
121 Preferences.setUI("Style", style) |
|
122 |
|
123 # save the other UI related settings |
|
124 Preferences.setUI("BrowsersListFoldersFirst", |
|
125 int(self.uiBrowsersListFoldersFirstCheckBox.isChecked())) |
|
126 Preferences.setUI("BrowsersHideNonPublic", |
|
127 int(self.uiBrowsersHideNonPublicCheckBox.isChecked())) |
|
128 Preferences.setUI("BrowsersListContentsByOccurrence", |
|
129 int(self.uiBrowsersSortByOccurrenceCheckBox.isChecked())) |
|
130 Preferences.setUI("LogViewerAutoRaise", |
|
131 int(self.lvAutoRaiseCheckBox.isChecked())) |
|
132 Preferences.setUI("CaptionShowsFilename", |
|
133 int(self.uiCaptionShowsFilenameGroupBox.isChecked())) |
|
134 Preferences.setUI("CaptionFilenameLength", |
|
135 self.filenameLengthSpinBox.value()) |
|
136 Preferences.setUI("StyleSheet", |
|
137 self.styleSheetEdit.text()) |
|
138 |
|
139 # save the dockarea corner settings |
|
140 Preferences.setUI("TopLeftByLeft", |
|
141 int(self.tlLeftButton.isChecked())) |
|
142 Preferences.setUI("BottomLeftByLeft", |
|
143 int(self.blLeftButton.isChecked())) |
|
144 Preferences.setUI("TopRightByRight", |
|
145 int(self.trRightButton.isChecked())) |
|
146 Preferences.setUI("BottomRightByRight", |
|
147 int(self.brRightButton.isChecked())) |
|
148 |
|
149 # save the language settings |
|
150 uiLanguageIndex = self.languageComboBox.currentIndex() |
|
151 if uiLanguageIndex: |
|
152 uiLanguage = \ |
|
153 self.languageComboBox.itemData(uiLanguageIndex).toString() |
|
154 else: |
|
155 uiLanguage = None |
|
156 Preferences.setUILanguage(uiLanguage) |
|
157 |
|
158 # save the interface layout settings |
|
159 if self.separateShellButton.isChecked(): |
|
160 layout2 = 0 |
|
161 else: |
|
162 layout2 = 1 |
|
163 if self.separateFileBrowserButton.isChecked(): |
|
164 layout3 = 0 |
|
165 elif self.debugEmbeddedFileBrowserButton.isChecked(): |
|
166 layout3 = 1 |
|
167 else: |
|
168 layout3 = 2 |
|
169 if self.layoutComboBox.currentIndex() == 0: |
|
170 layout1 = "DockWindows" |
|
171 elif self.layoutComboBox.currentIndex() == 1: |
|
172 layout1 = "FloatingWindows" |
|
173 elif self.layoutComboBox.currentIndex() == 2: |
|
174 layout1 = "Toolboxes" |
|
175 elif self.layoutComboBox.currentIndex() == 3: |
|
176 layout1 = "Sidebars" |
|
177 else: |
|
178 layout1 = "Sidebars" # just in case |
|
179 layout = (layout1, layout2, layout3) |
|
180 Preferences.setUILayout(layout) |
|
181 |
|
182 Preferences.setUI("SingleCloseButton", |
|
183 int(self.tabsCloseButtonCheckBox.isChecked())) |
|
184 |
|
185 for key in self.uiColours.keys(): |
|
186 Preferences.setUI(key, self.uiColours[key]) |
|
187 |
|
188 def __populateStyleCombo(self): |
|
189 """ |
|
190 Private method to populate the style combo box. |
|
191 """ |
|
192 curStyle = Preferences.getUI("Style") |
|
193 styles = QStyleFactory.keys() |
|
194 styles.sort() |
|
195 self.styleComboBox.addItem(self.trUtf8('System'), QVariant("System")) |
|
196 for style in styles: |
|
197 self.styleComboBox.addItem(style, QVariant(style)) |
|
198 currentIndex = self.styleComboBox.findData(QVariant(curStyle)) |
|
199 if currentIndex == -1: |
|
200 currentIndex = 0 |
|
201 self.styleComboBox.setCurrentIndex(currentIndex) |
|
202 |
|
203 def __populateLanguageCombo(self): |
|
204 """ |
|
205 Private method to initialize the language combobox of the Interface |
|
206 configuration page. |
|
207 """ |
|
208 self.languageComboBox.clear() |
|
209 |
|
210 fnlist = glob.glob("eric4_*.qm") + \ |
|
211 glob.glob(os.path.join(getConfig('ericTranslationsDir'), "eric4_*.qm")) + \ |
|
212 glob.glob(os.path.join(Utilities.getConfigDir(), "eric4_*.qm")) |
|
213 locales = {} |
|
214 for fn in fnlist: |
|
215 locale = os.path.basename(fn)[6:-3] |
|
216 if not locales.has_key(locale): |
|
217 translator = QTranslator() |
|
218 translator.load(fn) |
|
219 locales[locale] = \ |
|
220 translator.translate("InterfacePage", "English", |
|
221 "Translate this with your language") + \ |
|
222 " ({0})".format(locale) |
|
223 localeList = locales.keys() |
|
224 localeList.sort() |
|
225 |
|
226 try: |
|
227 uiLanguage = Preferences.getUILanguage() |
|
228 if uiLanguage == "None" or uiLanguage is None: |
|
229 currentIndex = 0 |
|
230 elif uiLanguage == "System": |
|
231 currentIndex = 1 |
|
232 else: |
|
233 currentIndex = localeList.index(uiLanguage) + 2 |
|
234 except ValueError: |
|
235 currentIndex = 0 |
|
236 self.languageComboBox.clear() |
|
237 |
|
238 self.languageComboBox.addItem("English (default)", QVariant("None")) |
|
239 self.languageComboBox.addItem(self.trUtf8('System'), QVariant("System")) |
|
240 for locale in localeList: |
|
241 self.languageComboBox.addItem(locales[locale], QVariant(locale)) |
|
242 self.languageComboBox.setCurrentIndex(currentIndex) |
|
243 |
|
244 @pyqtSlot() |
|
245 def on_styleSheetButton_clicked(self): |
|
246 """ |
|
247 Private method to select the style sheet file via a dialog. |
|
248 """ |
|
249 file = QFileDialog.getOpenFileName(\ |
|
250 self, |
|
251 self.trUtf8("Select style sheet file"), |
|
252 self.styleSheetEdit.text(), |
|
253 self.trUtf8("Qt Style Sheets (*.qss);;Cascading Style Sheets (*.css);;" |
|
254 "All files (*)")) |
|
255 |
|
256 if file: |
|
257 self.styleSheetEdit.setText(Utilities.toNativeSeparators(file)) |
|
258 |
|
259 @pyqtSlot() |
|
260 def on_resetLayoutButton_clicked(self): |
|
261 """ |
|
262 Private method to reset layout to factory defaults |
|
263 """ |
|
264 Preferences.resetLayout() |
|
265 |
|
266 @pyqtSlot() |
|
267 def on_stderrTextColourButton_clicked(self): |
|
268 """ |
|
269 Private slot to set the foreground colour of the caret. |
|
270 """ |
|
271 self.uiColours["LogStdErrColour"] = \ |
|
272 self.selectColour(self.stderrTextColourButton, |
|
273 self.uiColours["LogStdErrColour"]) |
|
274 |
|
275 def create(dlg): |
|
276 """ |
|
277 Module function to create the configuration page. |
|
278 |
|
279 @param dlg reference to the configuration dialog |
|
280 """ |
|
281 page = InterfacePage() |
|
282 return page |