5 |
5 |
6 """ |
6 """ |
7 Module implementing the Interface configuration page (variant for web browser). |
7 Module implementing the Interface configuration page (variant for web browser). |
8 """ |
8 """ |
9 |
9 |
|
10 import glob |
|
11 import os |
|
12 |
|
13 from PyQt6.QtCore import QTranslator |
10 from PyQt6.QtWidgets import QStyleFactory |
14 from PyQt6.QtWidgets import QStyleFactory |
11 |
15 |
12 from EricWidgets.EricPathPicker import EricPathPickerModes |
16 from EricWidgets.EricPathPicker import EricPathPickerModes |
|
17 from EricWidgets.EricApplication import ericApp |
13 |
18 |
14 from .ConfigurationPageBase import ConfigurationPageBase |
19 from .ConfigurationPageBase import ConfigurationPageBase |
15 from .Ui_WebBrowserInterfacePage import Ui_WebBrowserInterfacePage |
20 from .Ui_WebBrowserInterfacePage import Ui_WebBrowserInterfacePage |
16 |
21 |
17 import Preferences |
22 import Preferences |
|
23 import Utilities |
|
24 |
|
25 from eric7config import getConfig |
18 |
26 |
19 |
27 |
20 class WebBrowserInterfacePage(ConfigurationPageBase, |
28 class WebBrowserInterfacePage(ConfigurationPageBase, |
21 Ui_WebBrowserInterfacePage): |
29 Ui_WebBrowserInterfacePage): |
22 """ |
30 """ |
33 |
41 |
34 self.styleSheetPicker.setMode(EricPathPickerModes.OPEN_FILE_MODE) |
42 self.styleSheetPicker.setMode(EricPathPickerModes.OPEN_FILE_MODE) |
35 self.styleSheetPicker.setFilters(self.tr( |
43 self.styleSheetPicker.setFilters(self.tr( |
36 "Qt Style Sheets (*.qss);;Cascading Style Sheets (*.css);;" |
44 "Qt Style Sheets (*.qss);;Cascading Style Sheets (*.css);;" |
37 "All files (*)")) |
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) |
38 |
52 |
39 # set initial values |
53 # set initial values |
40 self.__populateStyleCombo() |
54 self.__populateStyleCombo() |
|
55 self.__populateLanguageCombo() |
|
56 |
41 self.styleSheetPicker.setText(Preferences.getUI("StyleSheet")) |
57 self.styleSheetPicker.setText(Preferences.getUI("StyleSheet")) |
|
58 self.styleIconsPathPicker.setText(Preferences.getUI("StyleIconsPath")) |
42 |
59 |
43 def save(self): |
60 def save(self): |
44 """ |
61 """ |
45 Public slot to save the Interface configuration. |
62 Public slot to save the Interface configuration. |
46 """ |
63 """ |
49 style = self.styleComboBox.itemData(styleIndex) |
66 style = self.styleComboBox.itemData(styleIndex) |
50 Preferences.setUI("Style", style) |
67 Preferences.setUI("Style", style) |
51 Preferences.setUI( |
68 Preferences.setUI( |
52 "StyleSheet", |
69 "StyleSheet", |
53 self.styleSheetPicker.text()) |
70 self.styleSheetPicker.text()) |
|
71 Preferences.setUI( |
|
72 "StyleIconsPath", |
|
73 self.styleIconsPathPicker.text()) |
|
74 |
|
75 # save the language settings |
|
76 uiLanguageIndex = self.languageComboBox.currentIndex() |
|
77 uiLanguage = ( |
|
78 self.languageComboBox.itemData(uiLanguageIndex) |
|
79 if uiLanguageIndex else |
|
80 None |
|
81 ) |
|
82 Preferences.setUILanguage(uiLanguage) |
54 |
83 |
55 def __populateStyleCombo(self): |
84 def __populateStyleCombo(self): |
56 """ |
85 """ |
57 Private method to populate the style combo box. |
86 Private method to populate the style combo box. |
58 """ |
87 """ |
64 currentIndex = self.styleComboBox.findData(curStyle) |
93 currentIndex = self.styleComboBox.findData(curStyle) |
65 if currentIndex == -1: |
94 if currentIndex == -1: |
66 currentIndex = 0 |
95 currentIndex = 0 |
67 self.styleComboBox.setCurrentIndex(currentIndex) |
96 self.styleComboBox.setCurrentIndex(currentIndex) |
68 |
97 |
|
98 def __populateLanguageCombo(self): |
|
99 """ |
|
100 Private method to initialize the language combo box. |
|
101 """ |
|
102 self.languageComboBox.clear() |
|
103 |
|
104 fnlist = ( |
|
105 glob.glob("eric7_*.qm") + |
|
106 glob.glob(os.path.join( |
|
107 getConfig('ericTranslationsDir'), "eric7_*.qm")) + |
|
108 glob.glob(os.path.join(Utilities.getConfigDir(), "eric7_*.qm")) |
|
109 ) |
|
110 locales = {} |
|
111 for fn in fnlist: |
|
112 locale = os.path.basename(fn)[6:-3] |
|
113 if locale not in locales: |
|
114 translator = QTranslator() |
|
115 translator.load(fn) |
|
116 locales[locale] = ( |
|
117 translator.translate( |
|
118 "InterfacePage", "English", |
|
119 "Translate this with your language") + |
|
120 " ({0})".format(locale) |
|
121 ) |
|
122 localeList = sorted(locales.keys()) |
|
123 try: |
|
124 uiLanguage = Preferences.getUILanguage() |
|
125 if uiLanguage == "None" or uiLanguage is None: |
|
126 currentIndex = 0 |
|
127 elif uiLanguage == "System": |
|
128 currentIndex = 1 |
|
129 else: |
|
130 currentIndex = localeList.index(uiLanguage) + 2 |
|
131 except ValueError: |
|
132 currentIndex = 0 |
|
133 self.languageComboBox.clear() |
|
134 |
|
135 self.languageComboBox.addItem("English (default)", "None") |
|
136 self.languageComboBox.addItem(self.tr('System'), "System") |
|
137 for locale in localeList: |
|
138 self.languageComboBox.addItem(locales[locale], locale) |
|
139 self.languageComboBox.setCurrentIndex(currentIndex) |
|
140 |
69 |
141 |
70 def create(dlg): |
142 def create(dlg): |
71 """ |
143 """ |
72 Module function to create the configuration page. |
144 Module function to create the configuration page. |
73 |
145 |