eric7/Preferences/ConfigurationPages/WebBrowserInterfacePage.py

branch
eric7
changeset 8876
2001accf55b3
parent 8875
67c3ea933787
child 8877
548d45c3f571
equal deleted inserted replaced
8875:67c3ea933787 8876:2001accf55b3
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_WebBrowserInterfacePage import Ui_WebBrowserInterfacePage
21
22 import Preferences
23 import Utilities
24
25 from eric7config import getConfig
26
27
28 class WebBrowserInterfacePage(ConfigurationPageBase,
29 Ui_WebBrowserInterfacePage):
30 """
31 Class implementing the Interface configuration page (variant for web
32 browser).
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 # set initial values
54 self.__populateStyleCombo()
55 self.__populateLanguageCombo()
56
57 self.styleSheetPicker.setText(Preferences.getUI("StyleSheet"))
58 self.styleIconsPathPicker.setText(Preferences.getUI("StyleIconsPath"))
59
60 def save(self):
61 """
62 Public slot to save the Interface configuration.
63 """
64 # save the style settings
65 styleIndex = self.styleComboBox.currentIndex()
66 style = self.styleComboBox.itemData(styleIndex)
67 Preferences.setUI("Style", style)
68 Preferences.setUI(
69 "StyleSheet",
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)
83
84 def __populateStyleCombo(self):
85 """
86 Private method to populate the style combo box.
87 """
88 curStyle = Preferences.getUI("Style")
89 styles = sorted(QStyleFactory.keys())
90 self.styleComboBox.addItem(self.tr('System'), "System")
91 for style in styles:
92 self.styleComboBox.addItem(style, style)
93 currentIndex = self.styleComboBox.findData(curStyle)
94 if currentIndex == -1:
95 currentIndex = 0
96 self.styleComboBox.setCurrentIndex(currentIndex)
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
141
142 def create(dlg):
143 """
144 Module function to create the configuration page.
145
146 @param dlg reference to the configuration dialog
147 @return reference to the instantiated page (ConfigurationPageBase)
148 """
149 page = WebBrowserInterfacePage()
150 return page

eric ide

mercurial