Browse Source

kivy: fix threading issue when scanning bip70 qr code on newer kivy

kivy 2.1 seemingly became more sensitive to threading issues.
This used to work on kivy 2.0 and older, but 2.1 is complaining.

```
I | paymentrequest | Error while contacting payment URL: https://bitpay.com/i/... -- error type: <class 'aiohttp.client_exceptions.ClientResponseError'> -- Got HTTP status code 404.
E | util | Exception in get_payment_request: TypeError('Cannot create graphics instruction outside the main Kivy thread')
Traceback (most recent call last):
  File "/home/user/wspace/electrum/electrum/util.py", line 1175, in wrapper
    return await func(*args, **kwargs)
  File "/home/user/wspace/electrum/electrum/util.py", line 1033, in get_payment_request
    on_pr(request)
  File "/home/user/wspace/electrum/electrum/gui/kivy/main_window.py", line 460, in on_pr
    self.show_error("invoice error:" + pr.error)
  File "/home/user/wspace/electrum/electrum/gui/kivy/main_window.py", line 1066, in show_error
    self.show_info_bubble(text=error, icon=icon, width=width,
  File "/home/user/wspace/electrum/electrum/gui/kivy/main_window.py", line 1092, in show_info_bubble
    info_bubble = self.info_bubble = Factory.InfoBubble()
  File "/usr/local/lib/python3.8/dist-packages/kivy/uix/bubble.py", line 199, in __init__
    self._arrow_layout = BoxLayout()
  File "/usr/local/lib/python3.8/dist-packages/kivy/uix/boxlayout.py", line 145, in __init__
    super(BoxLayout, self).__init__(**kwargs)
  File "/usr/local/lib/python3.8/dist-packages/kivy/uix/layout.py", line 76, in __init__
    super(Layout, self).__init__(**kwargs)
  File "/usr/local/lib/python3.8/dist-packages/kivy/uix/widget.py", line 361, in __init__
    self.canvas = Canvas(opacity=self.opacity)
  File "kivy/graphics/instructions.pyx", line 608, in kivy.graphics.instructions.Canvas.__init__
  File "kivy/graphics/instructions.pyx", line 154, in kivy.graphics.instructions.InstructionGroup.__init__
  File "kivy/graphics/instructions.pyx", line 60, in kivy.graphics.instructions.Instruction.__init__
TypeError: Cannot create graphics instruction outside the main Kivy thread
```
patch-4
SomberNight 3 years ago
parent
commit
5e0df77df6
No known key found for this signature in database GPG Key ID: B33B5F232C6271E9
  1. 3
      electrum/gui/kivy/main_window.py

3
electrum/gui/kivy/main_window.py

@ -443,6 +443,9 @@ class ElectrumWindow(App, Logger):
self._init_finished = True
def on_pr(self, pr: 'PaymentRequest'):
Clock.schedule_once(lambda dt, pr=pr: self._on_pr(pr))
def _on_pr(self, pr: 'PaymentRequest'):
if not self.wallet:
self.show_error(_('No wallet loaded.'))
return

Loading…
Cancel
Save