electrum

Electrum Bitcoin wallet
git clone https://git.parazyd.org/electrum
Log | Files | Refs | Submodules

commit f7ffdfc2b1ef53d67dd844a6622cc871d4e70b39
parent a190d1dbe67bc9868f79da620a375ad40d5dcb04
Author: ThomasV <thomasv@electrum.org>
Date:   Sun, 13 Dec 2015 16:21:50 +0100

kivy: fix qrcodewidget (only update from gui thread)

Diffstat:
Mgui/kivy/uix/qrcodewidget.py | 33+++++----------------------------
Mgui/kivy/uix/screens.py | 2+-
Mgui/kivy/uix/ui_screens/history.kv | 2+-
3 files changed, 7 insertions(+), 30 deletions(-)

diff --git a/gui/kivy/uix/qrcodewidget.py b/gui/kivy/uix/qrcodewidget.py @@ -42,14 +42,9 @@ Builder.load_string(''' class QRCodeWidget(FloatLayout): data = StringProperty(None, allow_none=True) - background_color = ListProperty((1, 1, 1, 1)) - foreground_color = ListProperty((0, 0, 0, 0)) - - #loading_image = StringProperty('gui/kivy/theming/loading.gif') - def __init__(self, **kwargs): super(QRCodeWidget, self).__init__(**kwargs) self.data = None @@ -57,21 +52,11 @@ class QRCodeWidget(FloatLayout): self._qrtexture = None def on_data(self, instance, value): - print "on data", value if not (self.canvas or value): return - img = self.ids.get('qrimage', None) - - if not img: - # if texture hasn't yet been created delay the texture updation - Clock.schedule_once(lambda dt: self.on_data(instance, value)) - return - - #Thread(target=partial(self.update_qr, )).start() self.update_qr() def set_data(self, data): - print "set data", data if self.data == data: return MinSize = 210 if len(data) < 128 else 500 @@ -98,7 +83,7 @@ class QRCodeWidget(FloatLayout): # currently unused, do we need this? self._texture_size = size - def _create_texture(self, k, dt): + def _create_texture(self, k): self._qrtexture = texture = Texture.create(size=(k,k), colorfmt='rgb') # don't interpolate texture texture.min_filter = 'nearest' @@ -107,32 +92,24 @@ class QRCodeWidget(FloatLayout): def update_texture(self): if not self.qr: return - matrix = self.qr.get_matrix() k = len(matrix) - # create the texture in main UI thread otherwise - # this will lead to memory corruption - Clock.schedule_once(partial(self._create_texture, k), -1) + # create the texture + self._create_texture(k) buff = [] bext = buff.extend cr, cg, cb, ca = self.background_color[:] cr, cg, cb = cr*255, cg*255, cb*255 - for r in range(k): for c in range(k): bext([0, 0, 0] if matrix[r][c] else [cr, cg, cb]) - # then blit the buffer buff = ''.join(map(chr, buff)) - # update texture in UI thread. - Clock.schedule_once(lambda dt: self._upd_texture(buff), .1) + # update texture + self._upd_texture(buff) def _upd_texture(self, buff): texture = self._qrtexture - if not texture: - # if texture hasn't yet been created delay the texture updation - Clock.schedule_once(lambda dt: self._upd_texture(buff), .1) - return texture.blit_buffer(buff, colorfmt='rgb', bufferfmt='ubyte') img =self.ids.qrimage img.anim_delay = -1 diff --git a/gui/kivy/uix/screens.py b/gui/kivy/uix/screens.py @@ -308,7 +308,7 @@ class ReceiveScreen(CScreen): @profiler def update_qr(self): uri = self.get_URI() - qr = self.screen.ids.get('qr') + qr = self.screen.ids.qr qr.set_data(uri) def do_copy(self): diff --git a/gui/kivy/uix/ui_screens/history.kv b/gui/kivy/uix/ui_screens/history.kv @@ -42,7 +42,7 @@ color: .699, .699, .699, 1 font_size: '13sp' shorten: True - text: root.message if root.message else ' ' + text: root.message Widget CardLabel: halign: 'right'