Browse Source

kivy request dialog: follow-up c95791d7eeff6f64968e391c78e344e0a02e1669:

- toggle between text and qr code
 - fix minor issues
patch-4
ThomasV 2 years ago
parent
commit
f65368f1d0
  1. 50
      electrum/gui/kivy/uix/dialogs/request_dialog.py

50
electrum/gui/kivy/uix/dialogs/request_dialog.py

@ -5,7 +5,7 @@ from kivy.lang import Builder
from kivy.core.clipboard import Clipboard from kivy.core.clipboard import Clipboard
from kivy.app import App from kivy.app import App
from kivy.clock import Clock from kivy.clock import Clock
from kivy.properties import NumericProperty, StringProperty from kivy.properties import NumericProperty, StringProperty, BooleanProperty
from kivy.uix.tabbedpanel import TabbedPanel from kivy.uix.tabbedpanel import TabbedPanel
from electrum.gui.kivy.i18n import _ from electrum.gui.kivy.i18n import _
@ -48,27 +48,22 @@ Builder.load_string('''
TabbedPanelWithHiddenHeader: TabbedPanelWithHiddenHeader:
id: qrdata_tabs id: qrdata_tabs
do_default_tab: False do_default_tab: False
on_touch_down:
root.show_text = True if root.error_text else not root.show_text
TabbedPanelItem: TabbedPanelItem:
id: qrdata_tab_qr id: qrdata_tab_qr
border: 0,0,0,0 # to hide visual artifact around hidden tab header border: 0,0,0,0 # to hide visual artifact around hidden tab header
QRCodeWidget: QRCodeWidget:
id: qr id: qr
shaded: False
foreground_color: (0, 0, 0, 0.5) if self.shaded else (0, 0, 0, 0)
on_touch_down:
touch = args[1]
if self.collide_point(*touch.pos): self.shaded = not self.shaded
TabbedPanelItem: TabbedPanelItem:
id: qrdata_tab_error id: qrdata_tab_text
border: 0,0,0,0 # to hide visual artifact around hidden tab header border: 0,0,0,0 # to hide visual artifact around hidden tab header
BoxLayout: BoxLayout:
padding: '20dp' padding: '20dp'
TopLabel: TopLabel:
text: root.error_text text: root.error_text if root.error_text else root.data
pos_hint: {'center_x': .5, 'center_y': .5} pos_hint: {'center_x': .5, 'center_y': .5}
halign: "center" halign: "center"
TopLabel:
text: root.data[0:70] + ('...' if len(root.data)>70 else '')
BoxLayout: BoxLayout:
size_hint: 1, None size_hint: 1, None
height: '48dp' height: '48dp'
@ -78,21 +73,21 @@ Builder.load_string('''
size_hint: 1, None size_hint: 1, None
height: '48dp' height: '48dp'
text: _('Address') text: _('Address')
on_release: root.mode = root.MODE_ADDRESS on_release: self.state = 'down'; root.mode = root.MODE_ADDRESS
ToggleButton: ToggleButton:
id: b1 id: b1
group:'g' group:'g'
size_hint: 1, None size_hint: 1, None
height: '48dp' height: '48dp'
text: _('URI') text: _('URI')
on_release: root.mode = root.MODE_URI on_release: self.state = 'down'; root.mode = root.MODE_URI
ToggleButton: ToggleButton:
id: b2 id: b2
group:'g' group:'g'
size_hint: 1, None size_hint: 1, None
height: '48dp' height: '48dp'
text: _('Lightning') text: _('Lightning')
on_release: root.mode = root.MODE_LIGHTNING on_release: self.state = 'down'; root.mode = root.MODE_LIGHTNING
disabled: not root.has_lightning disabled: not root.has_lightning
TopLabel: TopLabel:
text: _('Description') + ': ' + root.description or _('None') text: _('Description') + ': ' + root.description or _('None')
@ -146,6 +141,7 @@ class RequestDialog(Factory.Popup):
mode = NumericProperty(0) mode = NumericProperty(0)
data = StringProperty('') data = StringProperty('')
show_text = BooleanProperty(False)
def __init__(self, title, key): def __init__(self, title, key):
self.status = PR_UNKNOWN self.status = PR_UNKNOWN
@ -180,9 +176,13 @@ class RequestDialog(Factory.Popup):
else: else:
self.ids.qr.opacity = 0 self.ids.qr.opacity = 0
if not qr_data and self.error_text: if not qr_data and self.error_text:
Clock.schedule_once(lambda dt: self.ids.qrdata_tabs.switch_to(self.ids.qrdata_tab_error)) self.show_text = True
else: else:
Clock.schedule_once(lambda dt: self.ids.qrdata_tabs.switch_to(self.ids.qrdata_tab_qr)) self.show_text = False
def on_show_text(self, instance, b):
tab = self.ids.qrdata_tab_text if self.show_text else self.ids.qrdata_tab_qr
Clock.schedule_once(lambda dt: self.ids.qrdata_tabs.switch_to(tab))
def update_status(self): def update_status(self):
req = self.app.wallet.get_request(self.key) req = self.app.wallet.get_request(self.key)
@ -195,31 +195,31 @@ class RequestDialog(Factory.Popup):
self.status_color = pr_color[self.status] self.status_color = pr_color[self.status]
self.has_lightning = req.is_lightning() self.has_lightning = req.is_lightning()
self.warning = '' warning = ''
self.error_text = '' error_text = ''
self.data = '' self.data = ''
if self.mode == self.MODE_ADDRESS: if self.mode == self.MODE_ADDRESS:
if help_texts.address_is_error: if help_texts.address_is_error:
self.error_text = help_texts.address_help error_text = help_texts.address_help
else: else:
self.data = address self.data = address
self.warning = help_texts.address_help warning = help_texts.address_help
elif self.mode == self.MODE_URI: elif self.mode == self.MODE_URI:
if help_texts.URI_is_error: if help_texts.URI_is_error:
self.error_text = help_texts.URI_help error_text = help_texts.URI_help
else: else:
self.data = URI self.data = URI
self.warning = help_texts.URI_help warning = help_texts.URI_help
elif self.mode == self.MODE_LIGHTNING: elif self.mode == self.MODE_LIGHTNING:
if help_texts.ln_is_error: if help_texts.ln_is_error:
self.error_text = help_texts.ln_help error_text = help_texts.ln_help
else: else:
self.data = lnaddr self.data = lnaddr
self.warning = help_texts.ln_help warning = help_texts.ln_help
else: else:
raise Exception(f"unexpected {self.mode=!r}") raise Exception(f"unexpected {self.mode=!r}")
if self.warning: self.warning = (_('Warning') + ': ' + warning) if warning else ''
self.warning = _('Warning') + ': ' + self.warning self.error_text = error_text
def on_dismiss(self): def on_dismiss(self):
self.app.request_popup = None self.app.request_popup = None

Loading…
Cancel
Save