src/eric7/Preferences/ConfigurationPages/InterfaceLightPage.py

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

eric ide

mercurial