From 8977493a6278256e42d2b32b9e47959c92f7c1ea Mon Sep 17 00:00:00 2001 From: ThomasV Date: Mon, 14 Dec 2015 12:08:11 +0100 Subject: [PATCH] kivy: label dialogs --- gui/kivy/main.kv | 4 +-- gui/kivy/main_window.py | 13 +++++-- gui/kivy/uix/context_menu.py | 5 ++- gui/kivy/uix/dialogs/label_dialog.py | 54 ++++++++++++++++++++++++++++ gui/kivy/uix/screens.py | 12 ++++++- gui/kivy/uix/ui_screens/receive.kv | 12 +++---- gui/kivy/uix/ui_screens/send.kv | 14 ++++---- 7 files changed, 94 insertions(+), 20 deletions(-) create mode 100644 gui/kivy/uix/dialogs/label_dialog.py diff --git a/gui/kivy/main.kv b/gui/kivy/main.kv index 3bcc56f55..d50538082 100644 --- a/gui/kivy/main.kv +++ b/gui/kivy/main.kv @@ -208,12 +208,12 @@ values: [] #app.wallet.addresses() if app.wallet else [] text: _("Select Your address") -: +: background_color: .238, .585, .878, 0 halign: 'left' text_size: (self.width-10, None) size_hint: 0.5, None - default_text: 'Amount' + default_text: '' text: self.default_text padding: '5dp', '5db' height: '40dp' diff --git a/gui/kivy/main_window.py b/gui/kivy/main_window.py index 00f8851d1..e2528e9cb 100644 --- a/gui/kivy/main_window.py +++ b/gui/kivy/main_window.py @@ -33,6 +33,7 @@ Factory.register('InstallWizard', Factory.register('InfoBubble', module='electrum_gui.kivy.uix.dialogs') Factory.register('ELTextInput', module='electrum_gui.kivy.uix.screens') + #from kivy.core.window import Window #Window.softinput_mode = 'below_target' @@ -719,12 +720,18 @@ class ElectrumWindow(App): popup.tx_hash = obj.tx_hash popup.open() - def tx_label_dialog(self, obj): - pass - def address_dialog(self, screen): pass + def description_dialog(self, screen): + from uix.dialogs.label_dialog import LabelDialog + text = screen.message + def callback(text): + screen.message = text + d = LabelDialog(_('Enter description'), text, callback) + d.open() + + def amount_dialog(self, screen, show_max): popup = Builder.load_file('gui/kivy/uix/ui_screens/amount.kv') but_max = popup.ids.but_max diff --git a/gui/kivy/uix/context_menu.py b/gui/kivy/uix/context_menu.py index d12a326db..2d968cc51 100644 --- a/gui/kivy/uix/context_menu.py +++ b/gui/kivy/uix/context_menu.py @@ -39,5 +39,8 @@ class ContextMenu(Bubble): for k, v in action_list: l = MenuItem() l.text = k - l.on_release = lambda f=v: f(obj) + def func(f=v): + f(obj) + if self.parent: self.parent.hide_menu() + l.on_release = func self.ids.buttons.add_widget(l) diff --git a/gui/kivy/uix/dialogs/label_dialog.py b/gui/kivy/uix/dialogs/label_dialog.py new file mode 100644 index 000000000..f04b75095 --- /dev/null +++ b/gui/kivy/uix/dialogs/label_dialog.py @@ -0,0 +1,54 @@ +from kivy.app import App +from kivy.factory import Factory +from kivy.properties import ObjectProperty +from kivy.lang import Builder + +Builder.load_string(''' + + id: popup + title: '' + size_hint: 0.8, 0.3 + BoxLayout: + orientation: 'vertical' + Widget: + size_hint: 1, 0.2 + TextInput: + id:input + padding: '5dp' + size_hint: 1, None + height: '27dp' + pos_hint: {'center_y':.5} + text:'' + multiline: False + background_normal: 'atlas://gui/kivy/theming/light/tab_btn' + background_active: 'atlas://gui/kivy/theming/light/textinput_active' + hint_text_color: self.foreground_color + foreground_color: 1, 1, 1, 1 + font_size: '16dp' + focus: True + Widget: + size_hint: 1, 0.2 + BoxLayout: + orientation: 'horizontal' + size_hint: 1, 0.5 + Button: + text: 'Cancel' + size_hint: 0.5, None + height: '48dp' + on_release: popup.dismiss() + Button: + text: 'OK' + size_hint: 0.5, None + height: '48dp' + on_release: + root.callback(input.text) + popup.dismiss() +''') + +class LabelDialog(Factory.Popup): + + def __init__(self, title, text, callback): + Factory.Popup.__init__(self) + self.ids.input.text = text + self.callback = callback + self.title = title diff --git a/gui/kivy/uix/screens.py b/gui/kivy/uix/screens.py index 50504a7bf..3b609fc05 100644 --- a/gui/kivy/uix/screens.py +++ b/gui/kivy/uix/screens.py @@ -95,7 +95,17 @@ class HistoryScreen(CScreen): def __init__(self, **kwargs): self.ra_dialog = None super(HistoryScreen, self).__init__(**kwargs) - self.menu_actions = [ (_('Label'), self.app.tx_label_dialog), (_('Details'), self.app.tx_details_dialog)] + self.menu_actions = [ (_('Label'), self.label_dialog), (_('Details'), self.app.tx_details_dialog)] + + def label_dialog(self, obj): + from dialogs.label_dialog import LabelDialog + key = obj.tx_hash + text = self.app.wallet.get_label(key)[0] + def callback(text): + self.app.wallet.set_label(key, text) + self.update() + d = LabelDialog(_('Enter Transaction Label'), text, callback) + d.open() def get_history_rate(self, btc_balance, timestamp): date = timestamp_to_datetime(timestamp) diff --git a/gui/kivy/uix/ui_screens/receive.kv b/gui/kivy/uix/ui_screens/receive.kv index 653f2f059..5adef2def 100644 --- a/gui/kivy/uix/ui_screens/receive.kv +++ b/gui/kivy/uix/ui_screens/receive.kv @@ -56,8 +56,9 @@ ReceiveScreen: size_hint: None, None size: '22dp', '22dp' pos_hint: {'center_y': .5} - AmountButton: + BlueButton: id: amount_label + default_text: 'Amount' text: s.amount if s.amount else 'Amount' on_release: app.amount_dialog(s, False) CardSeparator: @@ -74,11 +75,10 @@ ReceiveScreen: size_hint: None, None size: '22dp', '22dp' pos_hint: {'center_y': .5} - TextInputBlue: - id: message_input - hint_text: 'Description' - text: s.message - on_text_validate: s.message = self.text + BlueButton: + id: description + text: s.message if s.message else _('Description') + on_release: app.description_dialog(s) BoxLayout: size_hint: 1, None height: '48dp' diff --git a/gui/kivy/uix/ui_screens/send.kv b/gui/kivy/uix/ui_screens/send.kv index 33f34a36e..d6a380a72 100644 --- a/gui/kivy/uix/ui_screens/send.kv +++ b/gui/kivy/uix/ui_screens/send.kv @@ -32,7 +32,7 @@ SendScreen: size_hint: None, None size: '22dp', '22dp' pos_hint: {'center_y': .5} - AmountButton: + BlueButton: id: payto_e text: s.address if s.address else _('Recipient') on_release: app.address_dialog(s) @@ -47,8 +47,9 @@ SendScreen: size_hint: None, None size: '22dp', '22dp' pos_hint: {'center_y': .5} - AmountButton: + BlueButton: id: amount_e + default_text: _('Amount') text: s.amount if s.amount else _('Amount') on_release: app.amount_dialog(s, True) @@ -66,11 +67,10 @@ SendScreen: size_hint: None, None size: '22dp', '22dp' pos_hint: {'center_y': .5} - TextInputBlue: - id: message_e - hint_text: _('Description') - text: s.message - on_text_validate: s.message = self.text + BlueButton: + id: description + text: s.message if s.message else _('Description') + on_release: app.description_dialog(s) BoxLayout: size_hint: 1, None height: '48dp'