electrum

Electrum Bitcoin wallet
git clone https://git.parazyd.org/electrum
Log | Files | Refs | Submodules

commit f5fcae7f11e5d102b70bb76d413e428db451f1a9
parent b54ba556bca11f17c6236ead7a6c3cb754555fa1
Author: ThomasV <thomasv@electrum.org>
Date:   Mon,  8 Feb 2016 19:01:34 +0100

kivy: receive_screen improvements

Diffstat:
Mgui/kivy/main_window.py | 11++---------
Agui/kivy/uix/dialogs/question.py | 51+++++++++++++++++++++++++++++++++++++++++++++++++++
Mgui/kivy/uix/screens.py | 71+++++++++++++++++++++++++++++++++++++++++------------------------------
Mgui/kivy/uix/ui_screens/receive.kv | 12++++++------
Mgui/kivy/uix/ui_screens/send.kv | 4++--
5 files changed, 102 insertions(+), 47 deletions(-)

diff --git a/gui/kivy/main_window.py b/gui/kivy/main_window.py @@ -159,8 +159,6 @@ class ElectrumWindow(App): ''' uri = StringProperty('', allownone=True) - ''' - ''' wallet = ObjectProperty(None) '''Holds the electrum wallet @@ -176,7 +174,6 @@ class ElectrumWindow(App): self.nfcscanner = None self.tabs = None - self.receive_address = None self.current_invoice = None super(ElectrumWindow, self).__init__(**kwargs) @@ -203,9 +200,6 @@ class ElectrumWindow(App): self._trigger_notify_transactions = \ Clock.create_trigger(self.notify_transactions, 5) - def get_receive_address(self): - return self.receive_address if self.receive_address else self.wallet.get_unused_address(None) - def do_pay(self, obj): pr = self.invoices.get(obj.key) self.on_pr(pr) @@ -264,8 +258,7 @@ class ElectrumWindow(App): panel.switch_to(tab) def show_request(self, addr): - self.receive_address = addr - self.update_tab('receive') + self.receive_screen.screen.address = addr self.switch_to('receive') def scan_qr(self, on_complete): @@ -644,7 +637,7 @@ class ElectrumWindow(App): popup.open() def address_dialog(self, screen): - pass + self.switch_to('invoices') def description_dialog(self, screen): from uix.dialogs.label_dialog import LabelDialog diff --git a/gui/kivy/uix/dialogs/question.py b/gui/kivy/uix/dialogs/question.py @@ -0,0 +1,51 @@ +from kivy.app import App +from kivy.factory import Factory +from kivy.properties import ObjectProperty +from kivy.lang import Builder +from kivy.uix.checkbox import CheckBox +from kivy.uix.label import Label +from kivy.uix.widget import Widget + +from electrum_gui.kivy.i18n import _ + +Builder.load_string(''' +<Question@Popup> + id: popup + title: '' + message: '' + size_hint: 0.8, 0.5 + pos_hint: {'top':0.9} + BoxLayout: + orientation: 'vertical' + Label: + id: label + text: root.message + Widget: + size_hint: 1, 0.1 + BoxLayout: + orientation: 'horizontal' + size_hint: 1, 0.2 + Button: + text: _('No') + size_hint: 0.5, None + height: '48dp' + on_release: + popup.dismiss() + Button: + text: _('Yes') + size_hint: 0.5, None + height: '48dp' + on_release: + root.callback() + popup.dismiss() +''') + + + +class Question(Factory.Popup): + + def __init__(self, msg, callback): + Factory.Popup.__init__(self) + self.title = _('Question') + self.message = msg + self.callback = callback diff --git a/gui/kivy/uix/screens.py b/gui/kivy/uix/screens.py @@ -194,9 +194,6 @@ class SendScreen(CScreen): self.screen.address = '' self.payment_request = None - def amount_dialog(self): - Clock.schedule_once(lambda dt: self.app.amount_dialog(self, True), .25) - def set_request(self, pr): self.payment_request = pr self.screen.address = pr.get_requestor() @@ -263,16 +260,28 @@ class SendScreen(CScreen): class ReceiveScreen(CScreen): kvname = 'receive' - + def update(self): - addr = self.app.get_receive_address() + if not self.screen.address: + self.get_new_address() + + def get_new_address(self): + addr = self.app.wallet.get_unused_address(None) + if addr is None: + return False self.screen.address = addr + self.screen.amount = '' + self.screen.message = '' + return True + + def on_address(self, addr): req = self.app.wallet.receive_requests.get(addr) if req: self.screen.message = unicode(req.get('memo', '')) amount = req.get('amount') if amount: self.screen.amount = self.app.format_amount_and_units(amount) + Clock.schedule_once(lambda dt: self.update_qr()) def amount_callback(self, popup): amount_label = self.screen.ids.get('amount') @@ -321,31 +330,19 @@ class ReceiveScreen(CScreen): message = str(self.screen.message) #.ids.message_input.text) if not message and not amount: return False - if amount: - amount = self.app.get_amount(amount) - else: - amount = 0 + amount = self.app.get_amount(amount) if amount else 0 req = self.app.wallet.make_payment_request(addr, amount, message, None) self.app.wallet.add_payment_request(req, self.app.electrum_config) self.app.update_tab('requests') return True - def on_amount(self): + def on_amount_or_message(self): self.do_save() - self.update_qr() - - def on_message(self): - self.do_save() - self.update_qr() + Clock.schedule_once(lambda dt: self.update_qr()) def do_new(self): - if self.do_save(): - self.app.show_info(_('Request saved')) - - self.app.receive_address = None - self.screen.amount = '' - self.screen.message = '' - self.update() + if not self.get_new_address(): + self.app.show_info(_('Please use the existing requests first.')) class ContactsScreen(CScreen): @@ -423,15 +420,20 @@ class InvoicesScreen(CScreen): self.app.do_pay(obj) def do_delete(self, obj): - self.app.invoices.remove(obj.key) - self.app.update_tab('invoices') + from dialogs.question import Question + def cb(): + self.app.invoices.remove(obj.key) + self.app.update_tab('invoices') + d = Question(_('Delete invoice?'), cb) + d.open() + class RequestsScreen(CScreen): kvname = 'requests' def update(self): - self.menu_actions = [('Show', self.do_show), ('Delete', self.do_delete)] + self.menu_actions = [('View/Edit', self.do_show), ('Delete', self.do_delete)] requests_list = self.screen.ids.requests_container requests_list.clear_widgets() _list = self.app.wallet.get_sorted_requests(self.app.electrum_config) @@ -445,10 +447,15 @@ class RequestsScreen(CScreen): ci = Factory.RequestItem() ci.address = req['address'] ci.memo = self.app.wallet.get_label(address) - status = req.get('status') - ci.status = pr_text[status] + if amount: + status = req.get('status') + ci.status = pr_text[status] + else: + received = self.app.wallet.get_addr_received(address) + ci.status = self.app.format_amount_and_units(amount) + ci.icon = pr_icon[status] - ci.amount = self.app.format_amount_and_units(amount) if amount else '' + ci.amount = self.app.format_amount_and_units(amount) if amount else _('No Amount') ci.date = format_time(timestamp) ci.screen = self requests_list.add_widget(ci) @@ -461,8 +468,12 @@ class RequestsScreen(CScreen): self.app.show_request(obj.address) def do_delete(self, obj): - self.app.wallet.remove_payment_request(obj.address, self.app.electrum_config) - self.update() + from dialogs.question import Question + def cb(): + self.app.wallet.remove_payment_request(obj.address, self.app.electrum_config) + self.update() + d = Question(_('Delete request?'), cb) + d.open() class CSpinner(Factory.Spinner): diff --git a/gui/kivy/uix/ui_screens/receive.kv b/gui/kivy/uix/ui_screens/receive.kv @@ -15,11 +15,11 @@ ReceiveScreen: message: '' on_address: - self.parent.update_qr() + self.parent.on_address(self.address) on_amount: - self.parent.on_amount() + self.parent.on_amount_or_message() on_message: - self.parent.on_message() + self.parent.on_amount_or_message() BoxLayout padding: '12dp', '12dp', '12dp', '12dp' @@ -71,7 +71,7 @@ ReceiveScreen: id: amount_label default_text: _('Amount') text: s.amount if s.amount else _('Amount') - on_release: app.amount_dialog(s, False) + on_release: Clock.schedule_once(lambda dt: app.amount_dialog(s, False)) CardSeparator: opacity: message_selection.opacity color: blue_bottom.foreground_color @@ -89,7 +89,7 @@ ReceiveScreen: BlueButton: id: description text: s.message if s.message else _('Description') - on_release: app.description_dialog(s) + on_release: Clock.schedule_once(lambda dt: app.description_dialog(s)) BoxLayout: size_hint: 1, None height: '48dp' @@ -107,4 +107,4 @@ ReceiveScreen: text: _('New') size_hint: 1, None height: '48dp' - on_release: s.parent.do_new() + on_release: Clock.schedule_once(lambda dt: s.parent.do_new()) diff --git a/gui/kivy/uix/ui_screens/send.kv b/gui/kivy/uix/ui_screens/send.kv @@ -52,7 +52,7 @@ SendScreen: id: amount_e default_text: _('Amount') text: s.amount if s.amount else _('Amount') - on_release: s.amount_dialog() + on_release: Clock.schedule_once(lambda dt: app.amount_dialog(s, True)) CardSeparator: opacity: message_selection.opacity color: blue_bottom.foreground_color @@ -69,7 +69,7 @@ SendScreen: BlueButton: id: description text: s.message if s.message else _('Description') - on_release: app.description_dialog(s) + on_release: Clock.schedule_once(lambda dt: app.description_dialog(s)) BoxLayout: size_hint: 1, None height: '48dp'