src/eric7/Preferences/ConfigurationPages/InterfacePage.py

branch
eric7
changeset 9209
b99e7fd55fd3
parent 9038
90bcfdd63d47
child 9221
bf71ee032bb4
equal deleted inserted replaced
9208:3fc8dfeb6ebe 9209:b99e7fd55fd3
1 # -*- coding: utf-8 -*-
2
3 # Copyright (c) 2006 - 2022 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 PyQt6.QtCore import pyqtSlot, QTranslator
14 from PyQt6.QtWidgets import QStyleFactory, QDialog, QColorDialog
15
16 from EricWidgets.EricPathPicker import EricPathPickerModes
17 from EricWidgets.EricIconBar import EricIconBar
18 from EricWidgets.EricApplication import ericApp
19
20 from .ConfigurationPageBase import ConfigurationPageBase
21 from .Ui_InterfacePage import Ui_InterfacePage
22
23 import Preferences
24 import Utilities
25 import UI.PixmapCache
26
27 from eric7config import getConfig
28
29
30 class InterfacePage(ConfigurationPageBase, Ui_InterfacePage):
31 """
32 Class implementing the Interface configuration page.
33 """
34 def __init__(self):
35 """
36 Constructor
37 """
38 super().__init__()
39 self.setupUi(self)
40 self.setObjectName("InterfacePage")
41
42 self.styleSheetPicker.setMode(EricPathPickerModes.OPEN_FILE_MODE)
43 self.styleSheetPicker.setFilters(self.tr(
44 "Qt Style Sheets (*.qss);;Cascading Style Sheets (*.css);;"
45 "All files (*)"))
46 self.styleSheetPicker.setDefaultDirectory(getConfig("ericStylesDir"))
47
48 styleIconsPath = ericApp().getStyleIconsPath()
49 self.styleIconsPathPicker.setMode(
50 EricPathPickerModes.DIRECTORY_SHOW_FILES_MODE)
51 self.styleIconsPathPicker.setDefaultDirectory(styleIconsPath)
52
53 for iconBarSize in EricIconBar.BarSizes:
54 self.iconSizeComboBox.addItem(
55 EricIconBar.BarSizes[iconBarSize][2], iconBarSize)
56
57 # set initial values
58 self.__populateStyleCombo()
59 self.__populateLanguageCombo()
60
61 self.uiBrowsersListFoldersFirstCheckBox.setChecked(
62 Preferences.getUI("BrowsersListFoldersFirst"))
63 self.uiBrowsersHideNonPublicCheckBox.setChecked(
64 Preferences.getUI("BrowsersHideNonPublic"))
65 self.uiBrowsersSortByOccurrenceCheckBox.setChecked(
66 Preferences.getUI("BrowsersListContentsByOccurrence"))
67 self.browserShowCodingCheckBox.setChecked(
68 Preferences.getUI("BrowserShowCoding"))
69 self.fileFiltersEdit.setText(
70 Preferences.getUI("BrowsersFileFilters"))
71
72 self.uiCaptionShowsFilenameGroupBox.setChecked(
73 Preferences.getUI("CaptionShowsFilename"))
74 self.filenameLengthSpinBox.setValue(
75 Preferences.getUI("CaptionFilenameLength"))
76 self.styleSheetPicker.setText(Preferences.getUI("StyleSheet"))
77 self.styleIconsPathPicker.setText(Preferences.getUI("StyleIconsPath"))
78
79 layoutType = Preferences.getUI("LayoutType")
80 if layoutType == "Sidebars":
81 index = 0
82 elif layoutType == "Toolboxes":
83 index = 1
84 else:
85 index = 0 # default for bad values
86 self.layoutComboBox.setCurrentIndex(index)
87
88 # integrated tools activation
89 # left side
90 self.findReplaceCheckBox.setChecked(
91 Preferences.getUI("ShowFindFileWidget"))
92 self.findLocationCheckBox.setChecked(
93 Preferences.getUI("ShowFindLocationWidget"))
94 self.templateViewerCheckBox.setChecked(
95 Preferences.getUI("ShowTemplateViewer"))
96 self.fileBrowserCheckBox.setChecked(
97 Preferences.getUI("ShowFileBrowser"))
98 self.symbolsCheckBox.setChecked(
99 Preferences.getUI("ShowSymbolsViewer"))
100 # right side
101 self.codeDocumentationViewerCheckBox.setChecked(
102 Preferences.getUI("ShowCodeDocumentationViewer"))
103 self.helpViewerCheckBox.setChecked(
104 Preferences.getUI("ShowInternalHelpViewer"))
105 self.condaCheckBox.setChecked(
106 Preferences.getUI("ShowCondaPackageManager"))
107 self.pypiCheckBox.setChecked(
108 Preferences.getUI("ShowPyPIPackageManager"))
109 self.cooperationCheckBox.setChecked(
110 Preferences.getUI("ShowCooperation"))
111 self.ircCheckBox.setChecked(
112 Preferences.getUI("ShowIrc"))
113 self.microPythonCheckBox.setChecked(
114 Preferences.getUI("ShowMicroPython"))
115 # bottom side
116 self.numbersCheckBox.setChecked(
117 Preferences.getUI("ShowNumbersViewer"))
118
119 self.iconSizeComboBox.setCurrentIndex(
120 self.iconSizeComboBox.findData(Preferences.getUI("IconBarSize")))
121 self.__iconBarColor = Preferences.getUI("IconBarColor")
122 self.__setIconBarSamples()
123
124 self.combinedLeftRightSidebarCheckBox.setChecked(
125 Preferences.getUI("CombinedLeftRightSidebar"))
126
127 # connect the icon size combo box after initialization is complete
128 self.iconSizeComboBox.currentIndexChanged.connect(
129 self.__setIconBarSamples)
130
131 def save(self):
132 """
133 Public slot to save the Interface configuration.
134 """
135 # save the style settings
136 styleIndex = self.styleComboBox.currentIndex()
137 style = self.styleComboBox.itemData(styleIndex)
138 Preferences.setUI("Style", style)
139
140 # save the other UI related settings
141 Preferences.setUI(
142 "BrowsersListFoldersFirst",
143 self.uiBrowsersListFoldersFirstCheckBox.isChecked())
144 Preferences.setUI(
145 "BrowsersHideNonPublic",
146 self.uiBrowsersHideNonPublicCheckBox.isChecked())
147 Preferences.setUI(
148 "BrowsersListContentsByOccurrence",
149 self.uiBrowsersSortByOccurrenceCheckBox.isChecked())
150 Preferences.setUI(
151 "BrowserShowCoding",
152 self.browserShowCodingCheckBox.isChecked())
153 Preferences.setUI(
154 "BrowsersFileFilters",
155 self.fileFiltersEdit.text())
156
157 Preferences.setUI(
158 "CaptionShowsFilename",
159 self.uiCaptionShowsFilenameGroupBox.isChecked())
160 Preferences.setUI(
161 "CaptionFilenameLength",
162 self.filenameLengthSpinBox.value())
163 Preferences.setUI(
164 "StyleSheet",
165 self.styleSheetPicker.text())
166 Preferences.setUI(
167 "StyleIconsPath",
168 self.styleIconsPathPicker.text())
169
170 # save the language settings
171 uiLanguageIndex = self.languageComboBox.currentIndex()
172 uiLanguage = (
173 self.languageComboBox.itemData(uiLanguageIndex)
174 if uiLanguageIndex else
175 None
176 )
177 Preferences.setUILanguage(uiLanguage)
178
179 # save the interface layout settings
180 if self.layoutComboBox.currentIndex() == 0:
181 layoutType = "Sidebars"
182 elif self.layoutComboBox.currentIndex() == 1:
183 layoutType = "Toolboxes"
184 else:
185 layoutType = "Sidebars" # just in case
186 Preferences.setUI("LayoutType", layoutType)
187
188 # save the integrated tools activation
189 # left side
190 Preferences.setUI(
191 "ShowFindFileWidget",
192 self.findReplaceCheckBox.isChecked())
193 Preferences.setUI(
194 "ShowFindLocationWidget",
195 self.findLocationCheckBox.isChecked())
196 Preferences.setUI(
197 "ShowTemplateViewer",
198 self.templateViewerCheckBox.isChecked())
199 Preferences.setUI(
200 "ShowFileBrowser",
201 self.fileBrowserCheckBox.isChecked())
202 Preferences.setUI(
203 "ShowSymbolsViewer",
204 self.symbolsCheckBox.isChecked())
205 # right side
206 Preferences.setUI(
207 "ShowCodeDocumentationViewer",
208 self.codeDocumentationViewerCheckBox.isChecked())
209 Preferences.setUI(
210 "ShowInternalHelpViewer",
211 self.helpViewerCheckBox.isChecked())
212 Preferences.setUI(
213 "ShowCondaPackageManager",
214 self.condaCheckBox.isChecked())
215 Preferences.setUI(
216 "ShowPyPIPackageManager",
217 self.pypiCheckBox.isChecked())
218 Preferences.setUI(
219 "ShowCooperation",
220 self.cooperationCheckBox.isChecked())
221 Preferences.setUI(
222 "ShowIrc",
223 self.ircCheckBox.isChecked())
224 Preferences.setUI(
225 "ShowMicroPython",
226 self.microPythonCheckBox.isChecked())
227 # bottom side
228 Preferences.setUI(
229 "ShowNumbersViewer",
230 self.numbersCheckBox.isChecked())
231
232 Preferences.setUI(
233 "IconBarSize",
234 self.iconSizeComboBox.currentData())
235 Preferences.setUI(
236 "IconBarColor",
237 self.__iconBarColor)
238 Preferences.setUI(
239 "CombinedLeftRightSidebar",
240 self.combinedLeftRightSidebarCheckBox.isChecked())
241
242 def __populateStyleCombo(self):
243 """
244 Private method to populate the style combo box.
245 """
246 curStyle = Preferences.getUI("Style")
247 styles = sorted(QStyleFactory.keys())
248 self.styleComboBox.addItem(self.tr('System'), "System")
249 for style in styles:
250 self.styleComboBox.addItem(style, style)
251 currentIndex = self.styleComboBox.findData(curStyle)
252 if currentIndex == -1:
253 currentIndex = 0
254 self.styleComboBox.setCurrentIndex(currentIndex)
255
256 def __populateLanguageCombo(self):
257 """
258 Private method to initialize the language combo box.
259 """
260 self.languageComboBox.clear()
261
262 fnlist = (
263 glob.glob("eric7_*.qm") +
264 glob.glob(os.path.join(
265 getConfig('ericTranslationsDir'), "eric7_*.qm")) +
266 glob.glob(os.path.join(Utilities.getConfigDir(), "eric7_*.qm"))
267 )
268 locales = {}
269 for fn in fnlist:
270 locale = os.path.basename(fn)[6:-3]
271 if locale not in locales:
272 translator = QTranslator()
273 translator.load(fn)
274 locales[locale] = (
275 translator.translate(
276 "InterfacePage", "English",
277 "Translate this with your language") +
278 " ({0})".format(locale)
279 )
280 localeList = sorted(locales.keys())
281 try:
282 uiLanguage = Preferences.getUILanguage()
283 if uiLanguage == "None" or uiLanguage is None:
284 currentIndex = 0
285 elif uiLanguage == "System":
286 currentIndex = 1
287 else:
288 currentIndex = localeList.index(uiLanguage) + 2
289 except ValueError:
290 currentIndex = 0
291 self.languageComboBox.clear()
292
293 self.languageComboBox.addItem("English (default)", "None")
294 self.languageComboBox.addItem(self.tr('System'), "System")
295 for locale in localeList:
296 self.languageComboBox.addItem(locales[locale], locale)
297 self.languageComboBox.setCurrentIndex(currentIndex)
298
299 @pyqtSlot()
300 def on_resetLayoutButton_clicked(self):
301 """
302 Private method to reset layout to factory defaults.
303 """
304 Preferences.resetLayout()
305
306 @pyqtSlot()
307 def __setIconBarSamples(self):
308 """
309 Private slot to set the colors of the icon bar color samples.
310 """
311 iconBarSize = self.iconSizeComboBox.currentData()
312 iconSize, borderSize = EricIconBar.BarSizes[iconBarSize][:2]
313 size = iconSize + 2 * borderSize
314
315 self.sampleLabel.setFixedSize(size, size)
316 self.sampleLabel.setStyleSheet(
317 EricIconBar.LabelStyleSheetTemplate
318 .format(self.__iconBarColor.name()))
319 self.sampleLabel.setPixmap(
320 UI.PixmapCache.getIcon("sbDebugViewer96")
321 .pixmap(iconSize, iconSize)
322 )
323
324 self.highlightedSampleLabel.setFixedSize(size, size)
325 self.highlightedSampleLabel.setStyleSheet(
326 EricIconBar.LabelStyleSheetTemplate
327 .format(self.__iconBarColor.darker().name()))
328 self.highlightedSampleLabel.setPixmap(
329 UI.PixmapCache.getIcon("sbDebugViewer96")
330 .pixmap(iconSize, iconSize)
331 )
332
333 @pyqtSlot()
334 def on_iconBarButton_clicked(self):
335 """
336 Private slot to select the icon bar color.
337 """
338 colDlg = QColorDialog(self)
339 # Set current colour last to avoid conflicts with alpha channel
340 colDlg.setCurrentColor(self.__iconBarColor)
341 if colDlg.exec() == QDialog.DialogCode.Accepted:
342 self.__iconBarColor = colDlg.selectedColor()
343 self.__setIconBarSamples()
344
345 @pyqtSlot(bool)
346 def on_combinedLeftRightSidebarCheckBox_toggled(self, checked):
347 """
348 Private slot handling a change of the combined sidebars checkbox.
349
350 @param checked state of the checkbox
351 @type bool
352 """
353 self.leftRightGroupBox.setTitle(
354 self.tr("Combined Left Side")
355 if checked else
356 self.tr("Right Side")
357 )
358
359
360 def create(dlg):
361 """
362 Module function to create the configuration page.
363
364 @param dlg reference to the configuration dialog
365 @return reference to the instantiated page (ConfigurationPageBase)
366 """
367 page = InterfacePage()
368 return page

eric ide

mercurial