kivy: i18n needs garbage collection

This commit is contained in:
ThomasV 2016-02-04 20:02:45 +01:00
parent 49fb099bdc
commit 45a0c3b53b
2 changed files with 19 additions and 3 deletions

View File

@ -18,8 +18,24 @@ class _(str):
return _.lang(s).format(args, kwargs)
@staticmethod
def bind(label):
_.observers.add(label)
def bind(label, arg):
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
def switch_lang(lang):

View File

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