tupdate guis for new contacts - electrum - Electrum Bitcoin wallet HTML git clone https://git.parazyd.org/electrum DIR Log DIR Files DIR Refs DIR Submodules --- DIR commit 782522fb7103ca4cac3d83a271f344f247ed73af DIR parent e8189490e9a2ac6805c5800526bd1ea582e97daa HTML Author: ThomasV <thomasv@gitorious> Date: Thu, 23 Apr 2015 12:46:52 +0200 update guis for new contacts Diffstat: M gui/android.py | 18 +++++++++--------- M gui/gtk.py | 18 +++++++----------- M gui/stdio.py | 18 ++++-------------- M gui/text.py | 12 +++++++----- 4 files changed, 27 insertions(+), 39 deletions(-) --- DIR diff --git a/gui/android.py b/gui/android.py t@@ -76,11 +76,7 @@ def edit_label(addr): def select_from_contacts(): title = 'Contacts:' droid.dialogCreateAlert(title) - l = [] - for i in range(len(wallet.addressbook)): - addr = wallet.addressbook[i] - label = wallet.labels.get(addr,addr) - l.append( label ) + l = contacts.keys() droid.dialogSetItems(l) droid.dialogSetPositiveButtonText('New contact') droid.dialogShow() t@@ -92,8 +88,8 @@ def select_from_contacts(): result = response.get('item') if result is not None: - addr = wallet.addressbook[result] - return addr + t, v = contacts.get(result) + return v t@@ -483,7 +479,8 @@ def make_new_contact(): address = None if address: if modal_question('Add to contacts?', address): - wallet.add_contact(address) + # fixme: ask for key + contacts[address] = ('address', address) else: modal_dialog('Invalid address', data) t@@ -893,17 +890,20 @@ droid = android.Android() menu_commands = ["send", "receive", "settings", "contacts", "main"] wallet = None network = None +contacts = None class ElectrumGui: def __init__(self, config, _network): - global wallet, network + global wallet, network, contacts network = _network network.register_callback('updated', update_callback) network.register_callback('connected', update_callback) network.register_callback('disconnected', update_callback) network.register_callback('disconnecting', update_callback) + contacts = util.StoreDict(config, 'contacts') + storage = WalletStorage(config) if not storage.file_exists: action = self.restore_or_create() DIR diff --git a/gui/gtk.py b/gui/gtk.py t@@ -466,6 +466,9 @@ class ElectrumWindow: self.window.set_default_size(720, 350) self.wallet_updated = False + from electrum.util import StoreDict + self.contacts = StoreDict(self.config, 'contacts') + vbox = Gtk.VBox() self.notebook = Gtk.Notebook() t@@ -1154,17 +1157,10 @@ class ElectrumWindow: self.recv_list.append((address, label, tx, format_satoshis(c,False,self.num_zeros), Type )) def update_sending_tab(self): - # detect addresses that are not mine in history, add them here... self.addressbook_list.clear() - #for alias, v in self.wallet.aliases.items(): - # s, target = v - # label = self.wallet.labels.get(alias) - # self.addressbook_list.append((alias, label, '-')) - - for address in self.wallet.addressbook: - label = self.wallet.labels.get(address) - n = self.wallet.get_num_tx(address) - self.addressbook_list.append((address, label, "%d"%n)) + for k, v in self.contacts.items(): + t, v = v + self.addressbook_list.append((k, v, t)) def update_history_tab(self): cursor = self.history_treeview.get_cursor()[0] t@@ -1268,7 +1264,7 @@ class ElectrumWindow: if result == 1: if is_valid(address): - self.wallet.add_contact(address,label) + self.contacts[label] = address self.update_sending_tab() else: errorDialog = Gtk.MessageDialog( DIR diff --git a/gui/stdio.py b/gui/stdio.py t@@ -2,7 +2,7 @@ from decimal import Decimal _ = lambda x:x #from i18n import _ from electrum.wallet import WalletStorage, Wallet -from electrum.util import format_satoshis, set_verbosity +from electrum.util import format_satoshis, set_verbosity, StoreDict from electrum.bitcoin import is_valid from electrum.network import filter_protocol import sys, getpass, datetime t@@ -32,6 +32,7 @@ class ElectrumGui: self.wallet = Wallet(storage) self.wallet.start_threads(network) + self.contacts = StoreDict(self.config, 'contacts') self.wallet.network.register_callback('updated', self.updated) self.wallet.network.register_callback('connected', self.connected) t@@ -133,8 +134,8 @@ class ElectrumGui: def print_contacts(self): - messages = map(lambda addr: "%30s %30s "%(addr, self.wallet.labels.get(addr,"")), self.wallet.addressbook) - self.print_list(messages, "%19s %25s "%("Address", "Label")) + messages = map(lambda x: "%20s %45s "%(x[0], x[1][1]), self.contacts.items()) + self.print_list(messages, "%19s %25s "%("Key", "Value")) def print_addresses(self): messages = map(lambda addr: "%30s %30s "%(addr, self.wallet.labels.get(addr,"")), self.wallet.addresses()) t@@ -239,14 +240,3 @@ class ElectrumGui: def run_contacts_tab(self, c): pass -# if c == 10 and self.wallet.addressbook: -# out = self.run_popup('Adress', ["Copy", "Pay to", "Edit label", "Delete"]).get('button') -# address = self.wallet.addressbook[self.pos%len(self.wallet.addressbook)] -# if out == "Pay to": -# self.tab = 1 -# self.str_recipient = address -# self.pos = 2 -# elif out == "Edit label": -# s = self.get_string(6 + self.pos, 18) -# if s: -# self.wallet.labels[address] = s DIR diff --git a/gui/text.py b/gui/text.py t@@ -3,6 +3,7 @@ from decimal import Decimal _ = lambda x:x #from i18n import _ from electrum.util import format_satoshis, set_verbosity +from electrum.util import StoreDict from electrum.bitcoin import is_valid from electrum import Wallet, WalletStorage t@@ -23,6 +24,7 @@ class ElectrumGui: self.wallet = Wallet(storage) self.wallet.start_threads(self.network) + self.contacts = StoreDict(self.config, 'contacts') locale.setlocale(locale.LC_ALL, '') self.encoding = locale.getpreferredencoding() t@@ -145,8 +147,8 @@ class ElectrumGui: def print_contacts(self): - messages = map(lambda addr: "%30s %30s "%(addr, self.wallet.labels.get(addr,"")), self.wallet.addressbook) - self.print_list(messages, "%19s %25s "%("Address", "Label")) + messages = map(lambda x: "%20s %45s "%(x[0], x[1][1]), self.contacts.items()) + self.print_list(messages, "%19s %15s "%("Key", "Value")) def print_receive(self): fmt = "%-35s %-30s" t@@ -248,12 +250,12 @@ class ElectrumGui: out = self.run_popup('Address', ["Edit label", "Freeze", "Prioritize"]) def run_contacts_tab(self, c): - if c == 10 and self.wallet.addressbook: + if c == 10 and self.contacts: out = self.run_popup('Adress', ["Copy", "Pay to", "Edit label", "Delete"]).get('button') - address = self.wallet.addressbook[self.pos%len(self.wallet.addressbook)] + key = self.contacts.keys()[self.pos%len(self.contacts.keys())] if out == "Pay to": self.tab = 1 - self.str_recipient = address + self.str_recipient = key self.pos = 2 elif out == "Edit label": s = self.get_string(6 + self.pos, 18)