eric7/Preferences/ConfigurationPages/InterfacePage.py

branch
eric7
changeset 8312
800c432b34c8
parent 8259
2bbec88047dd
child 8314
e3642a6a1e71
equal deleted inserted replaced
8311:4e8b98454baa 8312:800c432b34c8
1 # -*- coding: utf-8 -*-
2
3 # Copyright (c) 2006 - 2021 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 PyQt5.QtCore import pyqtSlot, QTranslator
14 from PyQt5.QtWidgets import QStyleFactory
15
16 from E5Gui.E5PathPicker import E5PathPickerModes
17
18 from .ConfigurationPageBase import ConfigurationPageBase
19 from .Ui_InterfacePage import Ui_InterfacePage
20
21 import Preferences
22 import Utilities
23
24 from eric6config import getConfig
25
26
27 class InterfacePage(ConfigurationPageBase, Ui_InterfacePage):
28 """
29 Class implementing the Interface configuration page.
30 """
31 def __init__(self):
32 """
33 Constructor
34 """
35 super().__init__()
36 self.setupUi(self)
37 self.setObjectName("InterfacePage")
38
39 self.styleSheetPicker.setMode(E5PathPickerModes.OpenFileMode)
40 self.styleSheetPicker.setFilters(self.tr(
41 "Qt Style Sheets (*.qss);;Cascading Style Sheets (*.css);;"
42 "All files (*)"))
43 self.styleSheetPicker.setDefaultDirectory(getConfig("ericStylesDir"))
44
45 # set initial values
46 self.__populateStyleCombo()
47 self.__populateLanguageCombo()
48 self.__populateShellPositionCombo()
49
50 self.uiBrowsersListFoldersFirstCheckBox.setChecked(
51 Preferences.getUI("BrowsersListFoldersFirst"))
52 self.uiBrowsersHideNonPublicCheckBox.setChecked(
53 Preferences.getUI("BrowsersHideNonPublic"))
54 self.uiBrowsersSortByOccurrenceCheckBox.setChecked(
55 Preferences.getUI("BrowsersListContentsByOccurrence"))
56 self.browserShowCodingCheckBox.setChecked(
57 Preferences.getUI("BrowserShowCoding"))
58 self.fileFiltersEdit.setText(
59 Preferences.getUI("BrowsersFileFilters"))
60
61 self.uiCaptionShowsFilenameGroupBox.setChecked(
62 Preferences.getUI("CaptionShowsFilename"))
63 self.filenameLengthSpinBox.setValue(
64 Preferences.getUI("CaptionFilenameLength"))
65 self.styleSheetPicker.setText(Preferences.getUI("StyleSheet"))
66
67 layoutType = Preferences.getUI("LayoutType")
68 if layoutType == "Sidebars":
69 index = 0
70 elif layoutType == "Toolboxes":
71 index = 1
72 else:
73 index = 0 # default for bad values
74 self.layoutComboBox.setCurrentIndex(index)
75
76 # integrated tools activation
77 # left side
78 self.templateViewerCheckBox.setChecked(
79 Preferences.getUI("ShowTemplateViewer"))
80 self.fileBrowserCheckBox.setChecked(
81 Preferences.getUI("ShowFileBrowser"))
82 self.symbolsCheckBox.setChecked(
83 Preferences.getUI("ShowSymbolsViewer"))
84 # right side
85 self.codeDocumentationViewerCheckBox.setChecked(
86 Preferences.getUI("ShowCodeDocumentationViewer"))
87 self.microPythonCheckBox.setChecked(
88 Preferences.getUI("ShowMicroPython"))
89 self.pypiCheckBox.setChecked(
90 Preferences.getUI("ShowPyPIPackageManager"))
91 self.condaCheckBox.setChecked(
92 Preferences.getUI("ShowCondaPackageManager"))
93 self.cooperationCheckBox.setChecked(
94 Preferences.getUI("ShowCooperation"))
95 self.ircCheckBox.setChecked(
96 Preferences.getUI("ShowIrc"))
97 # bottom side
98 self.numbersCheckBox.setChecked(
99 Preferences.getUI("ShowNumbersViewer"))
100
101 self.delaySpinBox.setValue(Preferences.getUI("SidebarDelay"))
102
103 def save(self):
104 """
105 Public slot to save the Interface configuration.
106 """
107 # save the style settings
108 styleIndex = self.styleComboBox.currentIndex()
109 style = self.styleComboBox.itemData(styleIndex)
110 Preferences.setUI("Style", style)
111
112 # save the other UI related settings
113 Preferences.setUI(
114 "BrowsersListFoldersFirst",
115 self.uiBrowsersListFoldersFirstCheckBox.isChecked())
116 Preferences.setUI(
117 "BrowsersHideNonPublic",
118 self.uiBrowsersHideNonPublicCheckBox.isChecked())
119 Preferences.setUI(
120 "BrowsersListContentsByOccurrence",
121 self.uiBrowsersSortByOccurrenceCheckBox.isChecked())
122 Preferences.setUI(
123 "BrowserShowCoding",
124 self.browserShowCodingCheckBox.isChecked())
125 Preferences.setUI(
126 "BrowsersFileFilters",
127 self.fileFiltersEdit.text())
128
129 Preferences.setUI(
130 "CaptionShowsFilename",
131 self.uiCaptionShowsFilenameGroupBox.isChecked())
132 Preferences.setUI(
133 "CaptionFilenameLength",
134 self.filenameLengthSpinBox.value())
135 Preferences.setUI(
136 "StyleSheet",
137 self.styleSheetPicker.text())
138
139 # save the language settings
140 uiLanguageIndex = self.languageComboBox.currentIndex()
141 uiLanguage = (
142 self.languageComboBox.itemData(uiLanguageIndex)
143 if uiLanguageIndex else
144 None
145 )
146 Preferences.setUILanguage(uiLanguage)
147
148 # save the interface layout settings
149 if self.layoutComboBox.currentIndex() == 0:
150 layoutType = "Sidebars"
151 elif self.layoutComboBox.currentIndex() == 1:
152 layoutType = "Toolboxes"
153 else:
154 layoutType = "Sidebars" # just in case
155 Preferences.setUI("LayoutType", layoutType)
156
157 # save the shell position setting
158 shellPositionIndex = self.shellPositionComboBox.currentIndex()
159 shellPosition = self.shellPositionComboBox.itemData(shellPositionIndex)
160 Preferences.setUI("ShellPosition", shellPosition)
161
162 # save the integrated tools activation
163 # left side
164 Preferences.setUI(
165 "ShowTemplateViewer",
166 self.templateViewerCheckBox.isChecked())
167 Preferences.setUI(
168 "ShowFileBrowser",
169 self.fileBrowserCheckBox.isChecked())
170 Preferences.setUI(
171 "ShowSymbolsViewer",
172 self.symbolsCheckBox.isChecked())
173 # right side
174 Preferences.setUI(
175 "ShowCodeDocumentationViewer",
176 self.codeDocumentationViewerCheckBox.isChecked())
177 Preferences.setUI(
178 "ShowMicroPython",
179 self.microPythonCheckBox.isChecked())
180 Preferences.setUI(
181 "ShowPyPIPackageManager",
182 self.pypiCheckBox.isChecked())
183 Preferences.setUI(
184 "ShowCondaPackageManager",
185 self.condaCheckBox.isChecked())
186 Preferences.setUI(
187 "ShowCooperation",
188 self.cooperationCheckBox.isChecked())
189 Preferences.setUI(
190 "ShowIrc",
191 self.ircCheckBox.isChecked())
192 # bottom side
193 Preferences.setUI(
194 "ShowNumbersViewer",
195 self.numbersCheckBox.isChecked())
196
197 Preferences.setUI("SidebarDelay", self.delaySpinBox.value())
198
199 def __populateStyleCombo(self):
200 """
201 Private method to populate the style combo box.
202 """
203 curStyle = Preferences.getUI("Style")
204 styles = sorted(list(QStyleFactory.keys()))
205 self.styleComboBox.addItem(self.tr('System'), "System")
206 for style in styles:
207 self.styleComboBox.addItem(style, style)
208 currentIndex = self.styleComboBox.findData(curStyle)
209 if currentIndex == -1:
210 currentIndex = 0
211 self.styleComboBox.setCurrentIndex(currentIndex)
212
213 def __populateLanguageCombo(self):
214 """
215 Private method to initialize the language combo box.
216 """
217 self.languageComboBox.clear()
218
219 fnlist = (
220 glob.glob("eric6_*.qm") +
221 glob.glob(os.path.join(
222 getConfig('ericTranslationsDir'), "eric6_*.qm")) +
223 glob.glob(os.path.join(Utilities.getConfigDir(), "eric6_*.qm"))
224 )
225 locales = {}
226 for fn in fnlist:
227 locale = os.path.basename(fn)[6:-3]
228 if locale not in locales:
229 translator = QTranslator()
230 translator.load(fn)
231 locales[locale] = (
232 translator.translate(
233 "InterfacePage", "English",
234 "Translate this with your language") +
235 " ({0})".format(locale)
236 )
237 localeList = sorted(list(locales.keys()))
238 try:
239 uiLanguage = Preferences.getUILanguage()
240 if uiLanguage == "None" or uiLanguage is None:
241 currentIndex = 0
242 elif uiLanguage == "System":
243 currentIndex = 1
244 else:
245 currentIndex = localeList.index(uiLanguage) + 2
246 except ValueError:
247 currentIndex = 0
248 self.languageComboBox.clear()
249
250 self.languageComboBox.addItem("English (default)", "None")
251 self.languageComboBox.addItem(self.tr('System'), "System")
252 for locale in localeList:
253 self.languageComboBox.addItem(locales[locale], locale)
254 self.languageComboBox.setCurrentIndex(currentIndex)
255
256 def __populateShellPositionCombo(self):
257 """
258 Private method to initialize the shell position combo box.
259 """
260 self.shellPositionComboBox.addItem(self.tr("Left Side"), "left")
261 self.shellPositionComboBox.addItem(self.tr("Right Side"), "right")
262 self.shellPositionComboBox.addItem(self.tr("Bottom Side"), "bottom")
263
264 shellPosition = Preferences.getUI("ShellPosition")
265 if shellPosition not in ("left", "right", "bottom"):
266 shellPosition = "bottom"
267 index = self.shellPositionComboBox.findData(shellPosition)
268 self.shellPositionComboBox.setCurrentIndex(index)
269
270 @pyqtSlot()
271 def on_resetLayoutButton_clicked(self):
272 """
273 Private method to reset layout to factory defaults.
274 """
275 Preferences.resetLayout()
276
277
278 def create(dlg):
279 """
280 Module function to create the configuration page.
281
282 @param dlg reference to the configuration dialog
283 @return reference to the instantiated page (ConfigurationPageBase)
284 """
285 page = InterfacePage()
286 return page

eric ide

mercurial