src/eric7/Preferences/ConfigurationPages/InterfaceLightPage.py

branch
eric7
changeset 9209
b99e7fd55fd3
parent 8876
2001accf55b3
child 9221
bf71ee032bb4
equal deleted inserted replaced
9208:3fc8dfeb6ebe 9209:b99e7fd55fd3
1 # -*- coding: utf-8 -*-
2
3 # Copyright (c) 2006 - 2019 Detlev Offenbach <detlev@die-offenbachs.de>
4 #
5
6 """
7 Module implementing the Interface configuration page (variant for web browser).
8 """
9
10 import glob
11 import os
12
13 from PyQt6.QtCore import QTranslator
14 from PyQt6.QtWidgets import QStyleFactory
15
16 from EricWidgets.EricPathPicker import EricPathPickerModes
17 from EricWidgets.EricApplication import ericApp
18
19 from .ConfigurationPageBase import ConfigurationPageBase
20 from .Ui_InterfaceLightPage import Ui_InterfaceLightPage
21
22 import Preferences
23 import Utilities
24
25 from eric7config import getConfig
26
27
28 class InterfaceLightPage(ConfigurationPageBase, Ui_InterfaceLightPage):
29 """
30 Class implementing the Interface configuration page (variant for generic
31 use).
32 """
33 def __init__(self):
34 """
35 Constructor
36 """
37 super().__init__()
38 self.setupUi(self)
39 self.setObjectName("InterfacePage")
40
41 self.styleSheetPicker.setMode(EricPathPickerModes.OPEN_FILE_MODE)
42 self.styleSheetPicker.setFilters(self.tr(
43 "Qt Style Sheets (*.qss);;Cascading Style Sheets (*.css);;"
44 "All files (*)"))
45 self.styleSheetPicker.setDefaultDirectory(getConfig("ericStylesDir"))
46
47 styleIconsPath = ericApp().getStyleIconsPath()
48 self.styleIconsPathPicker.setMode(
49 EricPathPickerModes.DIRECTORY_SHOW_FILES_MODE)
50 self.styleIconsPathPicker.setDefaultDirectory(styleIconsPath)
51
52 # set initial values
53 self.__populateStyleCombo()
54 self.__populateLanguageCombo()
55
56 self.styleSheetPicker.setText(Preferences.getUI("StyleSheet"))
57 self.styleIconsPathPicker.setText(Preferences.getUI("StyleIconsPath"))
58
59 def save(self):
60 """
61 Public slot to save the Interface configuration.
62 """
63 # save the style settings
64 styleIndex = self.styleComboBox.currentIndex()
65 style = self.styleComboBox.itemData(styleIndex)
66 Preferences.setUI("Style", style)
67 Preferences.setUI(
68 "StyleSheet",
69 self.styleSheetPicker.text())
70 Preferences.setUI(
71 "StyleIconsPath",
72 self.styleIconsPathPicker.text())
73
74 # save the language settings
75 uiLanguageIndex = self.languageComboBox.currentIndex()
76 uiLanguage = (
77 self.languageComboBox.itemData(uiLanguageIndex)
78 if uiLanguageIndex else
79 None
80 )
81 Preferences.setUILanguage(uiLanguage)
82
83 def __populateStyleCombo(self):
84 """
85 Private method to populate the style combo box.
86 """
87 curStyle = Preferences.getUI("Style")
88 styles = sorted(QStyleFactory.keys())
89 self.styleComboBox.addItem(self.tr('System'), "System")
90 for style in styles:
91 self.styleComboBox.addItem(style, style)
92 currentIndex = self.styleComboBox.findData(curStyle)
93 if currentIndex == -1:
94 currentIndex = 0
95 self.styleComboBox.setCurrentIndex(currentIndex)
96
97 def __populateLanguageCombo(self):
98 """
99 Private method to initialize the language combo box.
100 """
101 self.languageComboBox.clear()
102
103 fnlist = (
104 glob.glob("eric7_*.qm") +
105 glob.glob(os.path.join(
106 getConfig('ericTranslationsDir'), "eric7_*.qm")) +
107 glob.glob(os.path.join(Utilities.getConfigDir(), "eric7_*.qm"))
108 )
109 locales = {}
110 for fn in fnlist:
111 locale = os.path.basename(fn)[6:-3]
112 if locale not in locales:
113 translator = QTranslator()
114 translator.load(fn)
115 locales[locale] = (
116 translator.translate(
117 "InterfacePage", "English",
118 "Translate this with your language") +
119 " ({0})".format(locale)
120 )
121 localeList = sorted(locales.keys())
122 try:
123 uiLanguage = Preferences.getUILanguage()
124 if uiLanguage == "None" or uiLanguage is None:
125 currentIndex = 0
126 elif uiLanguage == "System":
127 currentIndex = 1
128 else:
129 currentIndex = localeList.index(uiLanguage) + 2
130 except ValueError:
131 currentIndex = 0
132 self.languageComboBox.clear()
133
134 self.languageComboBox.addItem("English (default)", "None")
135 self.languageComboBox.addItem(self.tr('System'), "System")
136 for locale in localeList:
137 self.languageComboBox.addItem(locales[locale], locale)
138 self.languageComboBox.setCurrentIndex(currentIndex)
139
140
141 def create(dlg):
142 """
143 Module function to create the configuration page.
144
145 @param dlg reference to the configuration dialog
146 @return reference to the instantiated page (ConfigurationPageBase)
147 """
148 page = InterfaceLightPage()
149 return page

eric ide

mercurial