8
8
from tzlocal import get_localzone_name
9
9
from itertools import cycle
10
10
from core .utils .widgets .animation_manager import AnimationManager
11
+ import locale
11
12
12
13
class ClockWidget (BaseWidget ):
13
14
validation_schema = VALIDATION_SCHEMA
@@ -35,9 +36,6 @@ def __init__(
35
36
self ._label_content = label
36
37
self ._padding = container_padding
37
38
self ._label_alt_content = label_alt
38
- if self ._locale :
39
- import locale
40
- locale .setlocale (locale .LC_TIME , self ._locale )
41
39
42
40
# Construct container
43
41
self ._widget_container_layout : QHBoxLayout = QHBoxLayout ()
@@ -114,7 +112,9 @@ def _update_label(self):
114
112
label_parts = re .split ('(<span.*?>.*?</span>)' , active_label_content )
115
113
label_parts = [part for part in label_parts if part ]
116
114
widget_index = 0
117
-
115
+ if self ._locale :
116
+ org_locale = locale .getlocale (locale .LC_TIME )
117
+
118
118
for part in label_parts :
119
119
part = part .strip ()
120
120
if part and widget_index < len (active_widgets ) and isinstance (active_widgets [widget_index ], QLabel ):
@@ -123,6 +123,8 @@ def _update_label(self):
123
123
active_widgets [widget_index ].setText (icon )
124
124
else :
125
125
try :
126
+ if self ._locale :
127
+ locale .setlocale (locale .LC_TIME , self ._locale )
126
128
datetime_format_search = re .search ('\\ {(.*)}' , part )
127
129
datetime_format_str = datetime_format_search .group ()
128
130
datetime_format = datetime_format_search .group (1 )
@@ -132,7 +134,9 @@ def _update_label(self):
132
134
format_label_content = part
133
135
active_widgets [widget_index ].setText (format_label_content )
134
136
widget_index += 1
135
-
137
+ if self ._locale :
138
+ locale .setlocale (locale .LC_TIME , org_locale )
139
+
136
140
def _next_timezone (self ):
137
141
self ._active_tz = next (self ._timezones )
138
142
if self ._tooltip :
0 commit comments