Browse Source

kivy: rework send and receive screens

283
ThomasV 9 years ago
parent
commit
df02269bcf
  1. 36
      gui/kivy/main_window.py
  2. 96
      gui/kivy/uix/screens.py
  3. 35
      gui/kivy/uix/ui_screens/receive.kv
  4. 54
      gui/kivy/uix/ui_screens/send.kv

36
gui/kivy/main_window.py

@ -48,6 +48,7 @@ from kivy.uix.screenmanager import Screen
from kivy.uix.tabbedpanel import TabbedPanel
from kivy.uix.label import Label
from kivy.uix.checkbox import CheckBox
from kivy.core.clipboard import Clipboard
Factory.register('TabbedCarousel', module='electrum_gui.kivy.uix.screens')
@ -163,7 +164,7 @@ class ElectrumWindow(App):
def __init__(self, **kwargs):
# initialize variables
self._clipboard = None
self._clipboard = Clipboard
self.info_bubble = None
self.qrscanner = None
self.nfcscanner = None
@ -203,18 +204,6 @@ class ElectrumWindow(App):
return
self.send_screen.set_URI(url)
def send_from_clipboard(self, on_complete):
if not self._clipboard:
from kivy.core.clipboard import Clipboard
self._clipboard = Clipboard
contents = self._clipboard.get()
try:
uri = electrum.util.parse_URI(contents)
except:
self.show_info("Invalid URI", url)
return
on_complete(uri)
def scan_qr(self, on_complete):
from jnius import autoclass
@ -564,14 +553,6 @@ class ElectrumWindow(App):
format(txs=tx_amount, amount=self.format_amount(v),
unit=self.base_unit))
def copy(self, text):
''' Copy provided text to clipboard
'''
if not self._clipboard:
from kivy.core.clipboard import Clipboard
self._clipboard = Clipboard
self._clipboard.put(text, 'text/plain')
def notify(self, message):
try:
global notification, os
@ -776,7 +757,7 @@ class ElectrumWindow(App):
popup.tx_hash = tx_hash
popup.open()
def amount_dialog(self, label, callback, show_max):
def amount_dialog(self, screen, show_max):
popup = Builder.load_file('gui/kivy/uix/ui_screens/amount.kv')
but_max = popup.ids.but_max
if not show_max:
@ -786,15 +767,16 @@ class ElectrumWindow(App):
but_max.disabled = False
but_max.opacity = 1
if label.text != label.default_text:
a, u = label.text.split()
amount = screen.amount
if amount:
a, u = str(amount).split()
assert u == self.base_unit
popup.ids.a.amount = a
def cb():
o = popup.ids.a.btc_text
label.text = o if o else label.default_text
if callback:
callback()
screen.amount = o
popup.on_dismiss = cb
popup.open()

96
gui/kivy/uix/screens.py

@ -10,12 +10,14 @@ from kivy.cache import Cache
from kivy.clock import Clock
from kivy.compat import string_types
from kivy.properties import (ObjectProperty, DictProperty, NumericProperty,
ListProperty)
ListProperty, StringProperty)
from kivy.lang import Builder
from kivy.factory import Factory
from electrum.i18n import _
from electrum.util import profiler
from electrum.util import profiler, parse_URI
from electrum import bitcoin
from electrum.util import timestamp_to_datetime
from electrum.plugins import run_hook
@ -181,42 +183,38 @@ class SendScreen(CScreen):
kvname = 'send'
def set_URI(self, uri):
print "z", uri
self.ids.payto_e.text = uri.get('address', '')
self.ids.message_e.text = uri.get('message', '')
print "set uri", uri
self.screen.address = uri.get('address', '')
self.screen.message = uri.get('message', '')
amount = uri.get('amount')
if amount:
amount_str = str( Decimal(amount) / pow(10, self.app.decimal_point()))
self.ids.amount_e.text = amount_str + ' ' + self.app.base_unit
self.screen.amount = amount_str + ' ' + self.app.base_unit
def do_clear(self):
self.ids.payto_e.text = ''
self.ids.message_e.text = ''
self.ids.amount_e.text = 'Amount'
#self.set_frozen(content, False)
#self.update_status()
self.screen.amount = ''
self.screen.message = ''
self.screen.address = ''
def do_send(self):
scrn = self.ids
label = unicode(scrn.message_e.text)
r = unicode(scrn.payto_e.text).strip()
# label or alias, with address in brackets
m = re.match('(.*?)\s*\<([1-9A-HJ-NP-Za-km-z]{26,})\>', r)
to_address = m.group(2) if m else r
if not bitcoin.is_address(to_address):
self.app.show_error(_('Invalid Bitcoin Address') + ':\n' + to_address)
def do_paste(self):
contents = unicode(self.app._clipboard.get())
try:
uri = parse_URI(contents)
except:
self.app.show_info("Invalid URI", contents)
return
self.set_URI(uri)
amount = self.app.get_amount(scrn.amount_e.text)
#fee = scrn.fee_e.amt
#if not fee:
# app.show_error(_('Invalid Fee'))
# return
def do_send(self):
address = str(self.screen.address)
amount = self.app.get_amount(self.screen.amount)
message = unicode(self.screen.message)
if not bitcoin.is_address(self.address):
self.app.show_error(_('Invalid Bitcoin Address') + ':\n' + address)
return
fee = None
message = 'sending {} {} to {}'.format(self.app.base_unit, scrn.amount_e.text, r)
outputs = [('address', to_address, amount)]
self.app.password_dialog(self.send_tx, (outputs, fee, label))
outputs = [('address', address, amount)]
self.app.password_dialog(self.send_tx, (outputs, fee, message))
def send_tx(self, *args):
self.app.show_info("Sending...")
@ -244,43 +242,41 @@ class SendScreen(CScreen):
class ReceiveScreen(CScreen):
kvname = 'receive'
kvname = 'receive'
def update(self):
addr = self.app.wallet.get_unused_address(None)
address_label = self.screen.ids.get('address')
address_label.text = addr
self.update_qr()
self.screen.address = self.app.wallet.get_unused_address(None)
def amount_callback(self, popup):
amount_label = self.screen.ids.get('amount')
amount_label.text = popup.ids.amount_label.text
self.update_qr()
@profiler
def update_qr(self):
def get_URI(self):
from electrum.util import create_URI
address = self.screen.ids.get('address').text
amount = self.screen.ids.get('amount').text
default_text = self.screen.ids.get('amount').default_text
if amount == default_text:
amount = None
else:
a, u = amount.split()
amount = self.screen.amount
if amount:
a, u = self.screen.amount.split()
assert u == self.app.base_unit
amount = Decimal(a) * pow(10, self.app.decimal_point())
msg = self.screen.ids.get('message').text
uri = create_URI(address, amount, msg)
return create_URI(self.screen.address, amount, self.screen.message)
@profiler
def update_qr(self):
uri = self.get_URI()
qr = self.screen.ids.get('qr')
qr.set_data(uri)
def do_share(self):
pass
def do_copy(self):
uri = self.get_URI()
print "put", uri
self.app._clipboard.put(uri, 'text/plain')
print "get", self.app._clipboard.get()
def do_clear(self):
a = self.screen.ids.get('amount')
a.text = a.default_text
self.screen.ids.get('message').text = ''
self.screen.amount = ''
self.screen.message = ''

35
gui/kivy/uix/ui_screens/receive.kv

@ -7,9 +7,20 @@
ReceiveScreen:
id: receive_screen
id: s
name: 'receive'
address: ''
amount: ''
message: ''
on_address:
self.parent.update_qr()
on_amount:
self.parent.update_qr()
on_message:
self.parent.update_qr()
BoxLayout
padding: '12dp', '12dp', '12dp', '12dp'
spacing: '12dp'
@ -27,10 +38,11 @@ ReceiveScreen:
self.shaded = not self.shaded
self.foreground_color = (0, 0, 0, 0.5) if self.shaded else (0, 0, 0, 0)
Label:
id: address
id: address_label
size_hint: 1, None
height: '48dp'
opacity: 0.5 if qr.shaded else 1
text: s.address
SendReceiveBlueBottom:
id: blue_bottom
@ -45,8 +57,9 @@ ReceiveScreen:
size: '22dp', '22dp'
pos_hint: {'center_y': .5}
AmountButton:
id: amount
on_release: app.amount_dialog(amount, receive_screen.parent.update_qr, False)
id: amount_label
text: s.amount if s.amount else 'Amount'
on_release: app.amount_dialog(s, False)
CardSeparator:
opacity: message_selection.opacity
color: blue_bottom.foreground_color
@ -62,23 +75,23 @@ ReceiveScreen:
size: '22dp', '22dp'
pos_hint: {'center_y': .5}
TextInputBlue:
id: message
id: message_input
hint_text: 'Description'
on_text_validate: receive_screen.parent.update_qr()
text: s.message
on_text_validate: s.message = self.text
BoxLayout:
size_hint: 1, None
height: '48dp'
Button:
text: _('Clear')
text: _('Copy')
size_hint: 1, None
height: '48dp'
on_release: receive_screen.parent.do_clear()
on_release: s.parent.do_copy()
Button:
text: _('Share')
text: _('Clear')
size_hint: 1, None
height: '48dp'
on_release: receive_screen.parent.do_share()
on_release: s.parent.do_clear()
Widget:
size_hint: 1, 0.3

54
gui/kivy/uix/ui_screens/send.kv

@ -7,36 +7,14 @@
#:set font_light 'data/fonts/Roboto-Condensed.ttf'
<SendToggle@ToggleButton>
source: ''
markup: False
bold: True
border: 4, 4, 4, 4
group: 'transfer_type'
background_normal: self.background_down
color:
(.140, .140, .140, 1) if self.state == 'down' else (.796, .796, .796, 1)
canvas.after:
Color:
rgba: 1, 1, 1, 1
Image:
source: root.source
color: root.color
size: '30dp', '30dp'
center_x: root.center_x - ((root.texture_size[0]/2)+(self.width/1.5))
center_y: root.center_y
SendScreen:
id: send_screen
id: s
name: 'send'
#action_view: Factory.SendActionView()
#on_deactivate:
# self.ids.amount_e.focus = False
# self.ids.payto_e.focus = False
# self.ids.message_e.focus = False
address: ''
amount: ''
message: ''
BoxLayout
padding: '12dp', '12dp', '12dp', '12dp'
spacing: '12dp'
@ -56,6 +34,7 @@ SendScreen:
pos_hint: {'center_y': .5}
TextInputBlue:
id: payto_e
text: s.address
hint_text: "Recipient"
CardSeparator:
opacity: message_selection.opacity
@ -70,8 +49,8 @@ SendScreen:
pos_hint: {'center_y': .5}
AmountButton:
id: amount_e
on_release: app.amount_dialog(self, None, True)
text: s.amount if s.amount else 'Amount'
on_release: app.amount_dialog(s, True)
CardSeparator:
opacity: message_selection.opacity
@ -89,6 +68,7 @@ SendScreen:
pos_hint: {'center_y': .5}
TextInputBlue:
id: message_e
text: s.message
hint_text: 'Description'
BoxLayout:
size_hint: 1, None
@ -97,26 +77,28 @@ SendScreen:
id: qr
text: _('QR Code')
on_release:
app.scan_qr(on_complete=root.set_URI)
app.scan_qr(on_complete=s.parent.set_URI)
Button:
id: paste_button
text: _('Clipboard')
text: _('Paste')
on_release:
app.send_from_clipboard(on_complete=root.set_URI)
s.parent.do_paste()
Button:
text: _('Clear')
size_hint: 1, None
height: '48dp'
on_release: send_screen.do_clear()
Widget:
size_hint: 1, 1
on_release: s.parent.do_clear()
BoxLayout:
size_hint: 1, None
height: '48dp'
Widget:
size_hint: 1, 1
Button:
text: _('Send')
size_hint: 1, None
height: '48dp'
on_release: send_screen.do_send()
on_release: s.parent.do_send()
Widget:
size_hint: 1, 1

Loading…
Cancel
Save