kivy: improve amount and password dialogs
This commit is contained in:
parent
3c4801b8de
commit
0d5114b6c2
|
@ -221,7 +221,8 @@
|
||||||
<KButton@Button>:
|
<KButton@Button>:
|
||||||
size_hint: 1, None
|
size_hint: 1, None
|
||||||
height: '48dp'
|
height: '48dp'
|
||||||
on_release: app.update_amount(self.label, self.text)
|
on_release:
|
||||||
|
self.parent.update_text(self.parent, self.text)
|
||||||
|
|
||||||
|
|
||||||
<TabbedPanelStrip>:
|
<TabbedPanelStrip>:
|
||||||
|
|
|
@ -85,15 +85,6 @@ class ElectrumWindow(App):
|
||||||
def decimal_point(self):
|
def decimal_point(self):
|
||||||
return base_units[self.base_unit]
|
return base_units[self.base_unit]
|
||||||
|
|
||||||
def toggle_fiat(self, a):
|
|
||||||
if not a.is_fiat:
|
|
||||||
if a.fiat_text:
|
|
||||||
a.fiat_amount = str(a.fiat_text).split()[0]
|
|
||||||
else:
|
|
||||||
if a.btc_text:
|
|
||||||
a.amount = str(a.btc_text).split()[0]
|
|
||||||
a.is_fiat = not a.is_fiat
|
|
||||||
|
|
||||||
def btc_to_fiat(self, amount_str):
|
def btc_to_fiat(self, amount_str):
|
||||||
if not amount_str:
|
if not amount_str:
|
||||||
return ''
|
return ''
|
||||||
|
@ -101,7 +92,7 @@ class ElectrumWindow(App):
|
||||||
if not rate:
|
if not rate:
|
||||||
return ''
|
return ''
|
||||||
fiat_amount = self.get_amount(amount_str + ' ' + self.base_unit) * rate / pow(10, 8)
|
fiat_amount = self.get_amount(amount_str + ' ' + self.base_unit) * rate / pow(10, 8)
|
||||||
return "{:.2f}".format(fiat_amount).rstrip('0').rstrip('.') + ' ' + self.fiat_unit
|
return "{:.2f}".format(fiat_amount).rstrip('0').rstrip('.')
|
||||||
|
|
||||||
def fiat_to_btc(self, fiat_amount):
|
def fiat_to_btc(self, fiat_amount):
|
||||||
if not fiat_amount:
|
if not fiat_amount:
|
||||||
|
@ -110,7 +101,7 @@ class ElectrumWindow(App):
|
||||||
if not rate:
|
if not rate:
|
||||||
return ''
|
return ''
|
||||||
satoshis = int(pow(10,8) * Decimal(fiat_amount) / Decimal(rate))
|
satoshis = int(pow(10,8) * Decimal(fiat_amount) / Decimal(rate))
|
||||||
return format_satoshis_plain(satoshis, self.decimal_point()) + ' ' + self.base_unit
|
return format_satoshis_plain(satoshis, self.decimal_point())
|
||||||
|
|
||||||
def get_amount(self, amount_str):
|
def get_amount(self, amount_str):
|
||||||
a, u = amount_str.split()
|
a, u = amount_str.split()
|
||||||
|
@ -478,6 +469,19 @@ class ElectrumWindow(App):
|
||||||
amount, fee = self.wallet.get_max_amount(self.electrum_config, inputs, None)
|
amount, fee = self.wallet.get_max_amount(self.electrum_config, inputs, None)
|
||||||
return format_satoshis_plain(amount, self.decimal_point())
|
return format_satoshis_plain(amount, self.decimal_point())
|
||||||
|
|
||||||
|
def update_password(self, label, c):
|
||||||
|
text = label.password
|
||||||
|
if c == '<':
|
||||||
|
text = text[:-1]
|
||||||
|
elif c == 'Clear':
|
||||||
|
text = ''
|
||||||
|
else:
|
||||||
|
text += c
|
||||||
|
label.password = text
|
||||||
|
|
||||||
|
def toggle_fiat(self, a):
|
||||||
|
a.is_fiat = not a.is_fiat
|
||||||
|
|
||||||
def update_amount(self, label, c):
|
def update_amount(self, label, c):
|
||||||
amount = label.fiat_amount if label.is_fiat else label.amount
|
amount = label.fiat_amount if label.is_fiat else label.amount
|
||||||
if c == '<':
|
if c == '<':
|
||||||
|
@ -498,7 +502,6 @@ class ElectrumWindow(App):
|
||||||
else:
|
else:
|
||||||
label.amount = amount
|
label.amount = amount
|
||||||
|
|
||||||
|
|
||||||
def format_amount(self, x, is_diff=False, whitespaces=False):
|
def format_amount(self, x, is_diff=False, whitespaces=False):
|
||||||
return format_satoshis(x, is_diff, 0, self.decimal_point(), whitespaces)
|
return format_satoshis(x, is_diff, 0, self.decimal_point(), whitespaces)
|
||||||
|
|
||||||
|
@ -786,7 +789,7 @@ class ElectrumWindow(App):
|
||||||
if amount:
|
if amount:
|
||||||
a, u = str(amount).split()
|
a, u = str(amount).split()
|
||||||
assert u == self.base_unit
|
assert u == self.base_unit
|
||||||
popup.ids.a.amount = a
|
popup.ids.kb.amount = a
|
||||||
|
|
||||||
def cb():
|
def cb():
|
||||||
o = popup.ids.a.btc_text
|
o = popup.ids.a.btc_text
|
||||||
|
@ -795,11 +798,17 @@ class ElectrumWindow(App):
|
||||||
popup.on_dismiss = cb
|
popup.on_dismiss = cb
|
||||||
popup.open()
|
popup.open()
|
||||||
|
|
||||||
|
def change_password(self):
|
||||||
|
self.password_dialog(self._change_password, ())
|
||||||
|
|
||||||
|
def _change_password(self, password):
|
||||||
|
print "zs", password
|
||||||
|
|
||||||
def password_dialog(self, f, args):
|
def password_dialog(self, f, args):
|
||||||
if self.wallet.use_encryption:
|
if self.wallet.use_encryption:
|
||||||
popup = Builder.load_file('gui/kivy/uix/ui_screens/password.kv')
|
popup = Builder.load_file('gui/kivy/uix/ui_screens/password.kv')
|
||||||
def callback():
|
def callback():
|
||||||
pw = popup.ids.text_input.text
|
pw = popup.ids.kb.password
|
||||||
Clock.schedule_once(lambda x: apply(f, args + (pw,)), 0.5)
|
Clock.schedule_once(lambda x: apply(f, args + (pw,)), 0.5)
|
||||||
popup.on_dismiss = callback
|
popup.on_dismiss = callback
|
||||||
popup.open()
|
popup.open()
|
||||||
|
|
|
@ -274,9 +274,7 @@ class ReceiveScreen(CScreen):
|
||||||
|
|
||||||
def do_copy(self):
|
def do_copy(self):
|
||||||
uri = self.get_URI()
|
uri = self.get_URI()
|
||||||
print "put", uri
|
|
||||||
self.app._clipboard.put(uri, 'text/plain')
|
self.app._clipboard.put(uri, 'text/plain')
|
||||||
print "get", self.app._clipboard.get()
|
|
||||||
|
|
||||||
def do_clear(self):
|
def do_clear(self):
|
||||||
self.screen.amount = ''
|
self.screen.amount = ''
|
||||||
|
|
|
@ -16,79 +16,69 @@ Popup:
|
||||||
height: '48dp'
|
height: '48dp'
|
||||||
Label:
|
Label:
|
||||||
id: a
|
id: a
|
||||||
amount: ''
|
btc_text: (kb.amount + ' ' + app.base_unit) if kb.amount else ''
|
||||||
fiat_amount: ''
|
fiat_text: (kb.fiat_amount + ' ' + app.fiat_unit) if kb.fiat_amount else ''
|
||||||
is_fiat: False
|
text: (self.fiat_text + ' / ' + self.btc_text if kb.is_fiat else self.btc_text + ' / ' + self.fiat_text) if self.btc_text else ''
|
||||||
btc_text: app.fiat_to_btc(self.fiat_amount) if self.is_fiat else (self.amount + ' ' + app.base_unit if self.amount else '')
|
|
||||||
fiat_text: (self.fiat_amount + ' ' + app.fiat_unit if self.fiat_amount else '') if self.is_fiat else app.btc_to_fiat(self.amount)
|
|
||||||
text: (self.fiat_text + ' / ' + self.btc_text if self.is_fiat else self.btc_text + ' / ' + self.fiat_text) if self.btc_text else ''
|
|
||||||
size_hint: 1, 1
|
size_hint: 1, 1
|
||||||
|
|
||||||
Widget:
|
Widget:
|
||||||
size_hint: 1, 1
|
size_hint: 1, 1
|
||||||
|
|
||||||
GridLayout:
|
GridLayout:
|
||||||
|
id: kb
|
||||||
|
amount: ''
|
||||||
|
fiat_amount: ''
|
||||||
|
is_fiat: False
|
||||||
|
on_fiat_amount: if self.is_fiat: self.amount = app.fiat_to_btc(self.fiat_amount)
|
||||||
|
on_amount: if not self.is_fiat: self.fiat_amount = app.btc_to_fiat(self.amount)
|
||||||
|
update_text: app.update_amount
|
||||||
size_hint: 1, None
|
size_hint: 1, None
|
||||||
height: '300dp'
|
height: '300dp'
|
||||||
cols: 3
|
cols: 3
|
||||||
KButton:
|
KButton:
|
||||||
text: '1'
|
text: '1'
|
||||||
label: a
|
|
||||||
KButton:
|
KButton:
|
||||||
text: '2'
|
text: '2'
|
||||||
label: a
|
|
||||||
KButton:
|
KButton:
|
||||||
text: '3'
|
text: '3'
|
||||||
label: a
|
|
||||||
KButton:
|
KButton:
|
||||||
text: '4'
|
text: '4'
|
||||||
label: a
|
|
||||||
KButton:
|
KButton:
|
||||||
text: '5'
|
text: '5'
|
||||||
label: a
|
|
||||||
KButton:
|
KButton:
|
||||||
text: '6'
|
text: '6'
|
||||||
label: a
|
|
||||||
KButton:
|
KButton:
|
||||||
text: '7'
|
text: '7'
|
||||||
label: a
|
|
||||||
KButton:
|
KButton:
|
||||||
text: '8'
|
text: '8'
|
||||||
label: a
|
|
||||||
KButton:
|
KButton:
|
||||||
text: '9'
|
text: '9'
|
||||||
label: a
|
|
||||||
KButton:
|
KButton:
|
||||||
text: '.'
|
text: '.'
|
||||||
label: a
|
|
||||||
KButton:
|
KButton:
|
||||||
text: '0'
|
text: '0'
|
||||||
label: a
|
|
||||||
KButton:
|
KButton:
|
||||||
text: '<'
|
text: '<'
|
||||||
label: a
|
|
||||||
Button:
|
Button:
|
||||||
id: but_max
|
id: but_max
|
||||||
size_hint: 1, None
|
size_hint: 1, None
|
||||||
height: '48dp'
|
height: '48dp'
|
||||||
text: 'Max'
|
text: 'Max'
|
||||||
on_release:
|
on_release:
|
||||||
a.is_fiat = False
|
kb.is_fiat = False
|
||||||
a.amount = app.get_max_amount()
|
kb.amount = app.get_max_amount()
|
||||||
Button:
|
Button:
|
||||||
id: button_fiat
|
id: button_fiat
|
||||||
size_hint: 1, None
|
size_hint: 1, None
|
||||||
height: '48dp'
|
height: '48dp'
|
||||||
text: app.fiat_unit if a.is_fiat else app.base_unit
|
text: app.fiat_unit if kb.is_fiat else app.base_unit
|
||||||
on_release:
|
on_release:
|
||||||
app.toggle_fiat(a)
|
app.toggle_fiat(kb)
|
||||||
Button:
|
Button:
|
||||||
size_hint: 1, None
|
size_hint: 1, None
|
||||||
height: '48dp'
|
height: '48dp'
|
||||||
text: 'Clear'
|
text: 'Clear'
|
||||||
on_release:
|
on_release:
|
||||||
a.amount = ''
|
kb.amount = ''
|
||||||
a.fiat_amount = ''
|
kb.fiat_amount = ''
|
||||||
|
|
||||||
Widget:
|
Widget:
|
||||||
size_hint: 1, None
|
size_hint: 1, None
|
||||||
|
|
|
@ -1,27 +1,49 @@
|
||||||
Popup:
|
Popup:
|
||||||
id: pw
|
id: popup
|
||||||
title: _('Password')
|
title: _('Enter PIN Code')
|
||||||
|
|
||||||
BoxLayout:
|
BoxLayout:
|
||||||
|
|
||||||
orientation: 'vertical'
|
orientation: 'vertical'
|
||||||
|
|
||||||
GridLayout:
|
Label:
|
||||||
cols: 2
|
id: a
|
||||||
Label:
|
text: '*'*len(kb.password)
|
||||||
text: 'Password'
|
|
||||||
size_hint: 1, None
|
|
||||||
height: '48dp'
|
|
||||||
TextInput:
|
|
||||||
id: text_input
|
|
||||||
size_hint: 1, None
|
|
||||||
password: True
|
|
||||||
multiline: False
|
|
||||||
Button:
|
|
||||||
size_hint: 1, None
|
size_hint: 1, None
|
||||||
height: '48dp'
|
height: '48dp'
|
||||||
text: _('Close')
|
|
||||||
on_release: pw.dismiss()
|
GridLayout:
|
||||||
|
id: kb
|
||||||
|
update_text: app.update_password
|
||||||
|
password: ''
|
||||||
|
on_password: if len(self.password) == 6: popup.dismiss()
|
||||||
|
size_hint: 1, None
|
||||||
|
height: '300dp'
|
||||||
|
cols: 3
|
||||||
|
KButton:
|
||||||
|
text: '1'
|
||||||
|
KButton:
|
||||||
|
text: '2'
|
||||||
|
KButton:
|
||||||
|
text: '3'
|
||||||
|
KButton:
|
||||||
|
text: '4'
|
||||||
|
KButton:
|
||||||
|
text: '5'
|
||||||
|
KButton:
|
||||||
|
text: '6'
|
||||||
|
KButton:
|
||||||
|
text: '7'
|
||||||
|
KButton:
|
||||||
|
text: '8'
|
||||||
|
KButton:
|
||||||
|
text: '9'
|
||||||
|
KButton:
|
||||||
|
text: 'Clear'
|
||||||
|
KButton:
|
||||||
|
text: '0'
|
||||||
|
KButton:
|
||||||
|
text: '<'
|
||||||
|
|
||||||
Widget:
|
Widget:
|
||||||
size_hint: 1, 1
|
size_hint: 1, 1
|
||||||
|
|
|
@ -6,6 +6,12 @@ Popup:
|
||||||
|
|
||||||
orientation: 'vertical'
|
orientation: 'vertical'
|
||||||
|
|
||||||
|
Button:
|
||||||
|
text: _('Set PIN Code')
|
||||||
|
size_hint: 1, None
|
||||||
|
height: '48dp'
|
||||||
|
on_release: app.change_password()
|
||||||
|
|
||||||
GridLayout:
|
GridLayout:
|
||||||
cols: 2
|
cols: 2
|
||||||
size_hint: 1, None
|
size_hint: 1, None
|
||||||
|
|
Loading…
Reference in New Issue