electrum

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

commit 0d5114b6c2ed648b7739b325b18458542a054684
parent 3c4801b8de0e8da8ef15d6c57f358360767571ef
Author: ThomasV <thomasv@electrum.org>
Date:   Mon,  7 Dec 2015 10:40:10 +0100

kivy: improve amount and password dialogs

Diffstat:
Mgui/kivy/main.kv | 3++-
Mgui/kivy/main_window.py | 37+++++++++++++++++++++++--------------
Mgui/kivy/uix/screens.py | 2--
Mgui/kivy/uix/ui_screens/amount.kv | 42++++++++++++++++--------------------------
Mgui/kivy/uix/ui_screens/password.kv | 54++++++++++++++++++++++++++++++++++++++----------------
Mgui/kivy/uix/ui_screens/settings.kv | 6++++++
6 files changed, 85 insertions(+), 59 deletions(-)

diff --git a/gui/kivy/main.kv b/gui/kivy/main.kv @@ -221,7 +221,8 @@ <KButton@Button>: size_hint: 1, None height: '48dp' - on_release: app.update_amount(self.label, self.text) + on_release: + self.parent.update_text(self.parent, self.text) <TabbedPanelStrip>: diff --git a/gui/kivy/main_window.py b/gui/kivy/main_window.py @@ -85,15 +85,6 @@ class ElectrumWindow(App): def decimal_point(self): 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): if not amount_str: return '' @@ -101,7 +92,7 @@ class ElectrumWindow(App): if not rate: return '' 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): if not fiat_amount: @@ -110,7 +101,7 @@ class ElectrumWindow(App): if not rate: return '' 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): a, u = amount_str.split() @@ -478,6 +469,19 @@ class ElectrumWindow(App): amount, fee = self.wallet.get_max_amount(self.electrum_config, inputs, None) 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): amount = label.fiat_amount if label.is_fiat else label.amount if c == '<': @@ -498,7 +502,6 @@ class ElectrumWindow(App): else: label.amount = amount - def format_amount(self, x, is_diff=False, whitespaces=False): return format_satoshis(x, is_diff, 0, self.decimal_point(), whitespaces) @@ -786,7 +789,7 @@ class ElectrumWindow(App): if amount: a, u = str(amount).split() assert u == self.base_unit - popup.ids.a.amount = a + popup.ids.kb.amount = a def cb(): o = popup.ids.a.btc_text @@ -795,11 +798,17 @@ class ElectrumWindow(App): popup.on_dismiss = cb 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): if self.wallet.use_encryption: popup = Builder.load_file('gui/kivy/uix/ui_screens/password.kv') def callback(): - pw = popup.ids.text_input.text + pw = popup.ids.kb.password Clock.schedule_once(lambda x: apply(f, args + (pw,)), 0.5) popup.on_dismiss = callback popup.open() diff --git a/gui/kivy/uix/screens.py b/gui/kivy/uix/screens.py @@ -274,9 +274,7 @@ class ReceiveScreen(CScreen): 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): self.screen.amount = '' diff --git a/gui/kivy/uix/ui_screens/amount.kv b/gui/kivy/uix/ui_screens/amount.kv @@ -16,79 +16,69 @@ Popup: height: '48dp' Label: id: a - amount: '' - fiat_amount: '' - is_fiat: False - 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 '' + btc_text: (kb.amount + ' ' + app.base_unit) if kb.amount else '' + fiat_text: (kb.fiat_amount + ' ' + app.fiat_unit) if kb.fiat_amount else '' + text: (self.fiat_text + ' / ' + self.btc_text if kb.is_fiat else self.btc_text + ' / ' + self.fiat_text) if self.btc_text else '' size_hint: 1, 1 - Widget: size_hint: 1, 1 - 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 height: '300dp' cols: 3 KButton: text: '1' - label: a KButton: text: '2' - label: a KButton: text: '3' - label: a KButton: text: '4' - label: a KButton: text: '5' - label: a KButton: text: '6' - label: a KButton: text: '7' - label: a KButton: text: '8' - label: a KButton: text: '9' - label: a KButton: text: '.' - label: a KButton: text: '0' - label: a KButton: text: '<' - label: a Button: id: but_max size_hint: 1, None height: '48dp' text: 'Max' on_release: - a.is_fiat = False - a.amount = app.get_max_amount() + kb.is_fiat = False + kb.amount = app.get_max_amount() Button: id: button_fiat size_hint: 1, None 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: - app.toggle_fiat(a) + app.toggle_fiat(kb) Button: size_hint: 1, None height: '48dp' text: 'Clear' on_release: - a.amount = '' - a.fiat_amount = '' + kb.amount = '' + kb.fiat_amount = '' Widget: size_hint: 1, None diff --git a/gui/kivy/uix/ui_screens/password.kv b/gui/kivy/uix/ui_screens/password.kv @@ -1,27 +1,49 @@ Popup: - id: pw - title: _('Password') + id: popup + title: _('Enter PIN Code') BoxLayout: orientation: 'vertical' - GridLayout: - cols: 2 - Label: - text: 'Password' - size_hint: 1, None - height: '48dp' - TextInput: - id: text_input - size_hint: 1, None - password: True - multiline: False - Button: + Label: + id: a + text: '*'*len(kb.password) size_hint: 1, None 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: size_hint: 1, 1 diff --git a/gui/kivy/uix/ui_screens/settings.kv b/gui/kivy/uix/ui_screens/settings.kv @@ -6,6 +6,12 @@ Popup: orientation: 'vertical' + Button: + text: _('Set PIN Code') + size_hint: 1, None + height: '48dp' + on_release: app.change_password() + GridLayout: cols: 2 size_hint: 1, None