@@ -73,6 +73,11 @@ def __init__(self):
73
73
"""Init the mainUI : init the UI, all the dlg element, and the main timer."""
74
74
PyQt6 .QtWidgets .QMainWindow .__init__ (self )
75
75
base_ui .CommunicationHandler .__init__ (self )
76
+
77
+ self .profile_ui = profile_ui .ProfileUI (main = self ) # load profile without UI
78
+ self .translator = PyQt6 .QtCore .QTranslator (self ) # Languages must be created before UI loaded
79
+ self .load_language () # load manually
80
+
76
81
base_ui .WidgetUI .__init__ (self , None , "MainWindow.ui" )
77
82
78
83
self .restart_app_flag = False
@@ -97,9 +102,8 @@ def __init__(self):
97
102
# Systray
98
103
self .systray = SystrayWrapper (self )
99
104
# Profile
100
- self .profile_ui = profile_ui .ProfileUI (main = self )
101
-
102
- self .make_lang_selector () # Languages must be created as early as possible
105
+ self .profile_ui .initialize_ui () # Profile UI
106
+ self .make_lang_selector ()
103
107
104
108
self .timer = PyQt6 .QtCore .QTimer (self )
105
109
self .timer .timeout .connect (self .update_timer ) # pylint: disable=no-value-for-parameter
@@ -197,13 +201,23 @@ def setup(self):
197
201
nb_device_compat = self .serialchooser .get_ports ()
198
202
self .serialchooser .auto_connect (nb_device_compat )
199
203
200
- # def refresh_widgets(self):
201
- # for w in app.allWidgets(): # Does not actually update the translation
202
- # w.update()
203
- # w.repaint()
204
- # # print(w)
204
+ def load_language (self ):
205
+ """load language file in profile befor creating UI"""
206
+ app .removeTranslator (self .translator )
207
+
208
+ langid = self .profile_ui .get_global_setting ("language" ,DEFAULTLANG )
209
+ # print(f"Loading langid: {langid}")
210
+ if langid == DEFAULTLANG :
211
+ langfile = ''
212
+ else :
213
+ langfile = helper .res_path (f"{ langid } .qm" ,"translations" )
214
+ # print(f"Loading language file: {langfile}")
215
+ if self .translator .load (langfile ):
216
+ app .installTranslator (self .translator )
217
+ # print(f"Language file loaded: {langfile}")
205
218
206
219
def change_language (self ,enabled ):
220
+ """Change language of the UI, this will run too when initializing the UI"""
207
221
if (not enabled ):
208
222
return
209
223
langfile ,user_language = self .language_action_group .checkedAction ().data ()
@@ -218,6 +232,7 @@ def change_language(self,enabled):
218
232
app .removeTranslator (self .translator )
219
233
if self .translator .load (langfile ):
220
234
app .installTranslator (self .translator )
235
+ # print(f"Language file loaded: {langfile}")
221
236
self .profile_ui .set_global_setting ("language" ,user_language ) #store language
222
237
223
238
#self.refresh_widgets()
@@ -914,8 +929,8 @@ def process_events():
914
929
QueryValueEx as getSubkeyValue ,
915
930
OpenKey as getKey ,
916
931
)
917
-
918
- if windows_theme_is_light () == 0 :
932
+ # Check if is not using windows 11 style(windows 11 style is dark mode compatible)
933
+ if windows_theme_is_light () == 0 and app . style (). objectName () != "windows11" :
919
934
app .setStyle ("Fusion" )
920
935
app .setPalette (dark_palette .PALETTE_DARK )
921
936
window .menubar .setStyleSheet ("QMenu::item {color: white; }" ) # Menu item text ignores palette setting and stays black. Force to white.
0 commit comments