2015-12-14 05:27:39 -08:00
|
|
|
from kivy.app import App
|
|
|
|
from kivy.factory import Factory
|
|
|
|
from kivy.properties import ObjectProperty
|
|
|
|
from kivy.lang import Builder
|
2015-12-18 04:04:19 -08:00
|
|
|
from decimal import Decimal
|
2015-10-14 02:44:01 -07:00
|
|
|
|
2015-12-14 05:27:39 -08:00
|
|
|
Builder.load_string('''
|
2015-12-18 04:04:19 -08:00
|
|
|
|
2015-12-14 05:27:39 -08:00
|
|
|
<AmountDialog@Popup>
|
2015-10-14 02:44:01 -07:00
|
|
|
id: popup
|
|
|
|
title: _('Amount')
|
2015-10-16 05:59:26 -07:00
|
|
|
AnchorLayout:
|
|
|
|
anchor_x: 'center'
|
2015-10-16 02:18:24 -07:00
|
|
|
BoxLayout:
|
2015-10-16 05:59:26 -07:00
|
|
|
orientation: 'vertical'
|
|
|
|
size_hint: 0.8, 1
|
|
|
|
BoxLayout:
|
2016-01-30 04:24:54 -08:00
|
|
|
size_hint: 1, None
|
|
|
|
height: '80dp'
|
2015-10-16 05:59:26 -07:00
|
|
|
Label:
|
|
|
|
id: a
|
2015-12-07 01:40:10 -08:00
|
|
|
btc_text: (kb.amount + ' ' + app.base_unit) if kb.amount else ''
|
|
|
|
fiat_text: (kb.fiat_amount + ' ' + app.fiat_unit) if kb.fiat_amount else ''
|
2016-01-30 04:24:54 -08:00
|
|
|
text1: ((self.fiat_text if kb.is_fiat else self.btc_text) if app.fiat_unit else self.btc_text) if self.btc_text else ''
|
|
|
|
text2: ((self.btc_text if kb.is_fiat else self.fiat_text) if app.fiat_unit else '') if self.btc_text else ''
|
|
|
|
text: self.text1 + "\\n" + "[color=#8888ff]" + self.text2 + "[/color]"
|
2016-01-30 07:05:36 -08:00
|
|
|
halign: 'right'
|
2016-01-30 04:24:54 -08:00
|
|
|
size_hint: 1, None
|
2015-12-07 07:43:18 -08:00
|
|
|
font_size: '22dp'
|
2016-01-30 04:24:54 -08:00
|
|
|
height: '80dp'
|
2015-10-16 05:59:26 -07:00
|
|
|
Widget:
|
2016-01-30 04:24:54 -08:00
|
|
|
size_hint: 1, 0.2
|
2015-10-16 05:59:26 -07:00
|
|
|
GridLayout:
|
2015-12-07 01:40:10 -08:00
|
|
|
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)
|
2015-10-16 05:59:26 -07:00
|
|
|
size_hint: 1, None
|
2015-12-18 04:04:19 -08:00
|
|
|
update_amount: popup.update_amount
|
2015-10-16 05:59:26 -07:00
|
|
|
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: '.'
|
|
|
|
KButton:
|
|
|
|
text: '0'
|
|
|
|
KButton:
|
|
|
|
text: '<'
|
2015-10-30 06:34:15 -07:00
|
|
|
Button:
|
2015-10-30 07:11:54 -07:00
|
|
|
id: but_max
|
2015-12-14 05:27:39 -08:00
|
|
|
opacity: 1 if root.show_max else 0
|
|
|
|
disabled: not root.show_max
|
2015-10-30 06:34:15 -07:00
|
|
|
size_hint: 1, None
|
|
|
|
height: '48dp'
|
|
|
|
text: 'Max'
|
2015-12-05 09:14:17 -08:00
|
|
|
on_release:
|
2015-12-07 01:40:10 -08:00
|
|
|
kb.is_fiat = False
|
|
|
|
kb.amount = app.get_max_amount()
|
2015-12-02 10:25:07 -08:00
|
|
|
Button:
|
|
|
|
id: button_fiat
|
|
|
|
size_hint: 1, None
|
|
|
|
height: '48dp'
|
2016-01-30 04:24:54 -08:00
|
|
|
text: (app.base_unit if kb.is_fiat else app.fiat_unit) if app.fiat_unit else ''
|
2015-12-03 13:43:43 -08:00
|
|
|
on_release:
|
2016-01-30 04:24:54 -08:00
|
|
|
if app.fiat_unit: popup.toggle_fiat(kb)
|
2015-12-02 10:25:07 -08:00
|
|
|
Button:
|
|
|
|
size_hint: 1, None
|
|
|
|
height: '48dp'
|
|
|
|
text: 'Clear'
|
2015-12-03 13:43:43 -08:00
|
|
|
on_release:
|
2015-12-07 01:40:10 -08:00
|
|
|
kb.amount = ''
|
|
|
|
kb.fiat_amount = ''
|
2015-12-02 09:02:11 -08:00
|
|
|
Widget:
|
2016-01-30 04:24:54 -08:00
|
|
|
size_hint: 1, 0.2
|
2015-10-16 05:59:26 -07:00
|
|
|
BoxLayout:
|
|
|
|
size_hint: 1, None
|
|
|
|
height: '48dp'
|
|
|
|
Widget:
|
2015-12-18 04:04:19 -08:00
|
|
|
size_hint: 1, None
|
2015-10-16 05:59:26 -07:00
|
|
|
height: '48dp'
|
|
|
|
Button:
|
2015-12-02 09:02:11 -08:00
|
|
|
size_hint: 1, None
|
2015-10-16 05:59:26 -07:00
|
|
|
height: '48dp'
|
|
|
|
text: _('OK')
|
2015-12-14 05:27:39 -08:00
|
|
|
on_release:
|
|
|
|
root.callback(a.btc_text)
|
|
|
|
popup.dismiss()
|
|
|
|
''')
|
|
|
|
|
|
|
|
from kivy.properties import BooleanProperty
|
|
|
|
|
|
|
|
class AmountDialog(Factory.Popup):
|
|
|
|
show_max = BooleanProperty(False)
|
|
|
|
def __init__(self, show_max, amount, cb):
|
|
|
|
Factory.Popup.__init__(self)
|
|
|
|
self.show_max = show_max
|
|
|
|
self.callback = cb
|
|
|
|
if amount:
|
|
|
|
self.ids.kb.amount = amount
|
|
|
|
|
2015-12-18 04:04:19 -08:00
|
|
|
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
|