From 45a0c3b53b58dd54b1118e7379521bc6acc72052 Mon Sep 17 00:00:00 2001 From: ThomasV Date: Thu, 4 Feb 2016 20:02:45 +0100 Subject: [PATCH] kivy: i18n needs garbage collection --- gui/kivy/i18n.py | 20 ++++++++++++++++++-- gui/kivy/main.kv | 2 +- 2 files changed, 19 insertions(+), 3 deletions(-) diff --git a/gui/kivy/i18n.py b/gui/kivy/i18n.py index 2acc3964..32a442ed 100644 --- a/gui/kivy/i18n.py +++ b/gui/kivy/i18n.py @@ -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): diff --git a/gui/kivy/main.kv b/gui/kivy/main.kv index 66032199..a41e64d9 100644 --- a/gui/kivy/main.kv +++ b/gui/kivy/main.kv @@ -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]) on_focus: app._focused_widget = root