commit 8b79e9fed1dfe4f8c272098f828acd19dcf2b15a
parent b0ddd7dc2779eeb2b328bea05d63a7343ab404ae
Author: ThomasV <thomasv@electrum.org>
Date: Sat, 7 Mar 2020 22:18:53 +0100
kivy: remove dynamic screen loading.
The performance gain it brings is negligible,
and it causes object duplication, which makes
things difficult to debug.
Diffstat:
4 files changed, 60 insertions(+), 68 deletions(-)
diff --git a/electrum/gui/kivy/uix/screens.py b/electrum/gui/kivy/uix/screens.py
@@ -58,7 +58,6 @@ class PaymentRecycleView(RecycleView):
class CScreen(Factory.Screen):
__events__ = ('on_activate', 'on_deactivate', 'on_enter', 'on_leave')
action_view = ObjectProperty(None)
- loaded = False
kvname = None
app = App.get_running_app() # type: ElectrumWindow
@@ -80,17 +79,8 @@ class CScreen(Factory.Screen):
def update(self):
pass
- @profiler
- def load_screen(self):
- self.screen = Builder.load_file('electrum/gui/kivy/uix/ui_screens/' + self.kvname + '.kv')
- self.add_widget(self.screen)
- self.loaded = True
- self.update()
- setattr(self.app, self.kvname + '_screen', self)
-
def on_activate(self):
- if self.kvname and not self.loaded:
- self.load_screen()
+ setattr(self.app, self.kvname + '_screen', self)
#Clock.schedule_once(lambda dt: self._change_action_view())
def on_leave(self):
@@ -114,6 +104,12 @@ TX_ICONS = [
"confirmed",
]
+
+Builder.load_file('electrum/gui/kivy/uix/ui_screens/history.kv')
+Builder.load_file('electrum/gui/kivy/uix/ui_screens/send.kv')
+Builder.load_file('electrum/gui/kivy/uix/ui_screens/receive.kv')
+
+
class HistoryScreen(CScreen):
tab = ObjectProperty(None)
@@ -182,7 +178,7 @@ class HistoryScreen(CScreen):
return
self.history = wallet.get_full_history(self.app.fx)
history = reversed(self.history.values())
- history_card = self.screen.ids.history_container
+ history_card = self.ids.history_container
history_card.data = [self.get_card(item) for item in history]
@@ -204,11 +200,11 @@ class SendScreen(CScreen):
return
self.parsed_URI = uri
amount = uri.get('amount')
- self.screen.address = uri.get('address', '')
- self.screen.message = uri.get('message', '')
- self.screen.amount = self.app.format_amount_and_units(amount) if amount else ''
+ self.address = uri.get('address', '')
+ self.message = uri.get('message', '')
+ self.amount = self.app.format_amount_and_units(amount) if amount else ''
self.payment_request = None
- self.screen.is_lightning = False
+ self.is_lightning = False
def set_ln_invoice(self, invoice):
try:
@@ -217,15 +213,13 @@ class SendScreen(CScreen):
except Exception as e:
self.app.show_info(invoice + _(" is not a valid Lightning invoice: ") + repr(e)) # repr because str(Exception()) == ''
return
- self.screen.address = invoice
- self.screen.message = dict(lnaddr.tags).get('d', None)
- self.screen.amount = self.app.format_amount_and_units(lnaddr.amount * bitcoin.COIN) if lnaddr.amount else ''
+ self.address = invoice
+ self.message = dict(lnaddr.tags).get('d', None)
+ self.amount = self.app.format_amount_and_units(lnaddr.amount * bitcoin.COIN) if lnaddr.amount else ''
self.payment_request = None
- self.screen.is_lightning = True
+ self.is_lightning = True
def update(self):
- if not self.loaded:
- return
if self.app.wallet and self.payment_request_queued:
self.set_URI(self.payment_request_queued)
self.payment_request_queued = None
@@ -233,7 +227,7 @@ class SendScreen(CScreen):
_list.reverse()
lnworker_logs = self.app.wallet.lnworker.logs if self.app.wallet.lnworker else {}
_list = [x for x in _list if x and x.get('status') != PR_PAID or x.get('rhash') in lnworker_logs]
- payments_container = self.screen.ids.payments_container
+ payments_container = self.ids.payments_container
payments_container.data = [self.get_card(item) for item in _list]
def show_item(self, obj):
@@ -263,20 +257,20 @@ class SendScreen(CScreen):
}
def do_clear(self):
- self.screen.amount = ''
- self.screen.message = ''
- self.screen.address = ''
+ self.amount = ''
+ self.message = ''
+ self.address = ''
self.payment_request = None
- self.screen.is_lightning = False
- self.screen.is_bip70 = False
+ self.is_lightning = False
+ self.is_bip70 = False
self.parsed_URI = None
def set_request(self, pr: 'PaymentRequest'):
- self.screen.address = pr.get_requestor()
+ self.address = pr.get_requestor()
amount = pr.get_amount()
- self.screen.amount = self.app.format_amount_and_units(amount) if amount else ''
- self.screen.message = pr.get_memo()
- self.screen.locked = True
+ self.amount = self.app.format_amount_and_units(amount) if amount else ''
+ self.message = pr.get_memo()
+ self.locked = True
self.payment_request = pr
def do_paste(self):
@@ -301,20 +295,20 @@ class SendScreen(CScreen):
self.set_URI(data)
def read_invoice(self):
- address = str(self.screen.address)
+ address = str(self.address)
if not address:
self.app.show_error(_('Recipient not specified.') + ' ' + _('Please scan a Bitcoin address or a payment request'))
return
- if not self.screen.amount:
+ if not self.amount:
self.app.show_error(_('Please enter an amount'))
return
try:
- amount = self.app.get_amount(self.screen.amount)
+ amount = self.app.get_amount(self.amount)
except:
- self.app.show_error(_('Invalid amount') + ':\n' + self.screen.amount)
+ self.app.show_error(_('Invalid amount') + ':\n' + self.amount)
return
- message = self.screen.message
- if self.screen.is_lightning:
+ message = self.message
+ if self.is_lightning:
return self.app.wallet.lnworker.parse_bech32_invoice(address)
else: # on-chain
if self.payment_request:
@@ -423,32 +417,32 @@ class ReceiveScreen(CScreen):
return self.app.electrum_config.get('request_expiry', PR_DEFAULT_EXPIRATION_WHEN_CREATING)
def clear(self):
- self.screen.address = ''
- self.screen.amount = ''
- self.screen.message = ''
- self.screen.lnaddr = ''
+ self.address = ''
+ self.amount = ''
+ self.message = ''
+ self.lnaddr = ''
def set_address(self, addr):
- self.screen.address = addr
+ self.address = addr
def on_address(self, addr):
req = self.app.wallet.get_request(addr)
- self.screen.status = ''
+ self.status = ''
if req:
- self.screen.message = req.get('memo', '')
+ self.message = req.get('memo', '')
amount = req.get('amount')
- self.screen.amount = self.app.format_amount_and_units(amount) if amount else ''
+ self.amount = self.app.format_amount_and_units(amount) if amount else ''
status = req.get('status', PR_UNKNOWN)
- self.screen.status = _('Payment received') if status == PR_PAID else ''
+ self.status = _('Payment received') if status == PR_PAID else ''
def get_URI(self):
from electrum.util import create_bip21_uri
- amount = self.screen.amount
+ amount = self.amount
if amount:
- a, u = self.screen.amount.split()
+ a, u = self.amount.split()
assert u == self.app.base_unit
amount = Decimal(a) * pow(10, self.app.decimal_point())
- return create_bip21_uri(self.screen.address, amount, self.screen.message)
+ return create_bip21_uri(self.address, amount, self.message)
def do_copy(self):
uri = self.get_URI()
@@ -456,17 +450,17 @@ class ReceiveScreen(CScreen):
self.app.show_info(_('Request copied to clipboard'))
def new_request(self, lightning):
- amount = self.screen.amount
+ amount = self.amount
amount = self.app.get_amount(amount) if amount else 0
- message = self.screen.message
+ message = self.message
if lightning:
key = self.app.wallet.lnworker.add_request(amount, message, self.expiry())
else:
- addr = self.screen.address or self.app.wallet.get_unused_address()
+ addr = self.address or self.app.wallet.get_unused_address()
if not addr:
self.app.show_info(_('No address available. Please remove some of your pending requests.'))
return
- self.screen.address = addr
+ self.address = addr
req = self.app.wallet.make_payment_request(addr, amount, message, self.expiry())
self.app.wallet.add_payment_request(req)
key = addr
@@ -497,11 +491,9 @@ class ReceiveScreen(CScreen):
return ci
def update(self):
- if not self.loaded:
- return
_list = self.app.wallet.get_sorted_requests()
_list.reverse()
- requests_container = self.screen.ids.requests_container
+ requests_container = self.ids.requests_container
requests_container.data = [self.get_card(item) for item in _list if item.get('status') != PR_PAID]
def show_item(self, obj):
diff --git a/electrum/gui/kivy/uix/ui_screens/history.kv b/electrum/gui/kivy/uix/ui_screens/history.kv
@@ -76,7 +76,7 @@
orientation: 'vertical'
-HistoryScreen:
+<HistoryScreen>:
name: 'history'
content: history_container
BoxLayout:
diff --git a/electrum/gui/kivy/uix/ui_screens/receive.kv b/electrum/gui/kivy/uix/ui_screens/receive.kv
@@ -60,7 +60,7 @@
orientation: 'vertical'
-ReceiveScreen:
+<ReceiveScreen>:
id: s
name: 'receive'
address: ''
@@ -135,22 +135,22 @@ ReceiveScreen:
icon: 'atlas://electrum/gui/kivy/theming/light/list'
size_hint: 0.5, None
height: '48dp'
- on_release: Clock.schedule_once(lambda dt: s.parent.clear_requests_dialog())
+ on_release: Clock.schedule_once(lambda dt: s.clear_requests_dialog())
IconButton:
icon: 'atlas://electrum/gui/kivy/theming/light/clock1'
size_hint: 0.5, None
height: '48dp'
- on_release: Clock.schedule_once(lambda dt: s.parent.expiration_dialog(s))
+ on_release: Clock.schedule_once(lambda dt: s.expiration_dialog(s))
Button:
text: _('Clear')
size_hint: 1, None
height: '48dp'
- on_release: Clock.schedule_once(lambda dt: s.parent.clear())
+ on_release: Clock.schedule_once(lambda dt: s.clear())
Button:
text: _('Request')
size_hint: 1, None
height: '48dp'
- on_release: Clock.schedule_once(lambda dt: s.parent.new_request(root.is_lightning))
+ on_release: Clock.schedule_once(lambda dt: s.new_request(root.is_lightning))
Widget:
size_hint: 1, 0.1
RequestRecycleView:
diff --git a/electrum/gui/kivy/uix/ui_screens/send.kv b/electrum/gui/kivy/uix/ui_screens/send.kv
@@ -62,7 +62,7 @@
height: self.minimum_height
orientation: 'vertical'
-SendScreen:
+<SendScreen>:
id: s
name: 'send'
address: ''
@@ -150,12 +150,12 @@ SendScreen:
height: '48dp'
IconButton:
size_hint: 0.5, 1
- on_release: s.parent.do_save()
+ on_release: s.do_save()
icon: 'atlas://electrum/gui/kivy/theming/light/save'
IconButton:
size_hint: 0.5, 1
icon: 'atlas://electrum/gui/kivy/theming/light/copy'
- on_release: s.parent.do_paste()
+ on_release: s.do_paste()
IconButton:
id: qr
size_hint: 1, 1
@@ -164,11 +164,11 @@ SendScreen:
Button:
text: _('Clear')
size_hint: 1, 1
- on_release: s.parent.do_clear()
+ on_release: s.do_clear()
Button:
text: _('Pay')
size_hint: 1, 1
- on_release: s.parent.do_pay()
+ on_release: s.do_pay()
Widget:
size_hint: 1, 0.1
PaymentRecycleView: