Browse Source

kivy: i18n needs garbage collection

283
ThomasV 9 years ago
parent
commit
45a0c3b53b
  1. 20
      gui/kivy/i18n.py
  2. 2
      gui/kivy/main.kv

20
gui/kivy/i18n.py

@ -18,8 +18,24 @@ class _(str):
return _.lang(s).format(args, kwargs) return _.lang(s).format(args, kwargs)
@staticmethod @staticmethod
def bind(label): def bind(label, arg):
_.observers.add(label) if not isinstance(label.text, _):
return
if label.bound:
return
try:
_.observers.add(label)
except:
pass
label.bound = True
# garbage collection
new = set()
for label in _.observers:
try:
new.add(label)
except:
pass
_.observers = new
@staticmethod @staticmethod
def switch_lang(lang): def switch_lang(lang):

2
gui/kivy/main.kv

@ -13,7 +13,7 @@
font_name: 'Roboto' font_name: 'Roboto'
font_size: '16sp' font_size: '16sp'
bound: False bound: False
on_text: if isinstance(self.text, _) and not self.bound: self.bound = True; _.bind(self) on_text: _.bind(self, args[1])
<TextInput> <TextInput>
on_focus: app._focused_widget = root on_focus: app._focused_widget = root

Loading…
Cancel
Save