move methods related to amount dialog

This commit is contained in:
ThomasV 2015-12-18 13:04:19 +01:00
parent f7a3b53c3f
commit e46b00bb39
4 changed files with 36 additions and 35 deletions

View File

@ -243,12 +243,6 @@
background_active: 'atlas://gui/kivy/theming/light/textinput_active' background_active: 'atlas://gui/kivy/theming/light/textinput_active'
<KButton@Button>:
size_hint: 1, None
height: '48dp'
on_release:
self.parent.update_text(self.parent, self.text)
<TabbedPanelStrip>: <TabbedPanelStrip>:
on_parent: on_parent:

View File

@ -491,28 +491,6 @@ class ElectrumWindow(App):
text += c text += c
label.password = text label.password = text
def toggle_fiat(self, a):
a.is_fiat = not a.is_fiat
def update_amount(self, label, c):
amount = label.fiat_amount if label.is_fiat else label.amount
if c == '<':
amount = amount[:-1]
elif c == '.' and amount == '':
amount = '0.'
elif c == '0' and amount == '0':
amount = '0'
else:
try:
Decimal(amount+c)
amount += c
except:
pass
if label.is_fiat:
label.fiat_amount = amount
else:
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)

View File

@ -2,9 +2,15 @@ from kivy.app import App
from kivy.factory import Factory from kivy.factory import Factory
from kivy.properties import ObjectProperty from kivy.properties import ObjectProperty
from kivy.lang import Builder from kivy.lang import Builder
from decimal import Decimal
Builder.load_string(''' Builder.load_string('''
<KButton@Button>:
size_hint: 1, None
height: '48dp'
on_release:
self.parent.update_amount(self.text)
<AmountDialog@Popup> <AmountDialog@Popup>
id: popup id: popup
title: _('Amount') title: _('Amount')
@ -32,8 +38,8 @@ Builder.load_string('''
is_fiat: False is_fiat: False
on_fiat_amount: if self.is_fiat: self.amount = app.fiat_to_btc(self.fiat_amount) 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) 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
update_amount: popup.update_amount
height: '300dp' height: '300dp'
cols: 3 cols: 3
KButton: KButton:
@ -76,7 +82,7 @@ Builder.load_string('''
height: '48dp' height: '48dp'
text: (app.fiat_unit if kb.is_fiat else app.base_unit) if app.fiat_unit else '' text: (app.fiat_unit if kb.is_fiat else app.base_unit) if app.fiat_unit else ''
on_release: on_release:
app.toggle_fiat(kb) popup.toggle_fiat(kb)
Button: Button:
size_hint: 1, None size_hint: 1, None
height: '48dp' height: '48dp'
@ -90,7 +96,7 @@ Builder.load_string('''
size_hint: 1, None size_hint: 1, None
height: '48dp' height: '48dp'
Widget: Widget:
size_hint: 2, None size_hint: 1, None
height: '48dp' height: '48dp'
Button: Button:
size_hint: 1, None size_hint: 1, None
@ -112,3 +118,25 @@ class AmountDialog(Factory.Popup):
if amount: if amount:
self.ids.kb.amount = amount self.ids.kb.amount = amount
def toggle_fiat(self, a):
a.is_fiat = not a.is_fiat
def update_amount(self, c):
kb = self.ids.kb
amount = kb.fiat_amount if kb.is_fiat else kb.amount
if c == '<':
amount = amount[:-1]
elif c == '.' and amount in ['0', '']:
amount = '0.'
elif amount == '0':
amount = c
else:
try:
Decimal(amount+c)
amount += c
except:
pass
if kb.is_fiat:
kb.fiat_amount = amount
else:
kb.amount = amount

View File

@ -42,7 +42,8 @@ ReceiveScreen:
size_hint: 1, None size_hint: 1, None
height: '48dp' height: '48dp'
opacity: 0.5 if qr.shaded else 1 opacity: 0.5 if qr.shaded else 1
text: s.address text: _('Bitcoin Address') + ': ' + s.address
text_size: self.width, None
SendReceiveBlueBottom: SendReceiveBlueBottom:
id: blue_bottom id: blue_bottom
@ -98,5 +99,5 @@ ReceiveScreen:
size_hint: 1, None size_hint: 1, None
height: '48dp' height: '48dp'
on_release: s.parent.do_new() on_release: s.parent.do_new()
Widget: #Widget:
size_hint: 1, 0.3 # size_hint: 1, 0.3