electrum

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

commit b08f1a2a7b7eb11fbd6297f54fb3e5fcd5d55dc7
parent 58538ba825c199b4f3286cc3d7f3b3d2a33473e3
Author: ThomasV <thomasv@gitorious>
Date:   Mon,  5 Aug 2013 17:15:01 +0200

plugins: do not overload __init__, use init() instead

Diffstat:
Mgui/gui_classic.py | 12++++++------
Mgui/plugins.py | 41++++++++++++++++++++++++++++-------------
Mlib/version.py | 2+-
Mplugins/aliases.py | 8++++++--
Mplugins/labels.py | 47++++++++++++++++++++++++-----------------------
Mplugins/pointofsale.py | 25+++++++++++++------------
Mplugins/qrscanner.py | 10+++++++---
Mplugins/virtualkeyboard.py | 9+++++++--
8 files changed, 92 insertions(+), 62 deletions(-)

diff --git a/gui/gui_classic.py b/gui/gui_classic.py @@ -345,7 +345,8 @@ class ElectrumWindow(QMainWindow): self.notify_transactions() # plugins that need to change the GUI do it here - self.run_hook('init_gui') + self.run_hook('init') + def select_wallet_file(self): wallet_folder = self.wallet.config.path @@ -494,9 +495,9 @@ class ElectrumWindow(QMainWindow): plugins = [ __import__('electrum_plugins.'+name, fromlist=['electrum_plugins']) for name in plugin_names] self.plugins = [] - for p in plugins: + for name, p in zip(plugin_names, plugins): try: - self.plugins.append( p.Plugin(self) ) + self.plugins.append( p.Plugin(self, name) ) except: print_msg("Error:cannot initialize plugin",p) traceback.print_exc(file=sys.stdout) @@ -2161,15 +2162,14 @@ class ElectrumWindow(QMainWindow): return lambda: cb.setChecked(p.toggle()) for i, p in enumerate(self.plugins): try: - name, description = p.get_info() - cb = QCheckBox(name) + cb = QCheckBox(p.fullname()) cb.setDisabled(not p.is_available()) cb.setChecked(p.is_enabled()) cb.clicked.connect(mk_toggle(cb,p)) grid_plugins.addWidget(cb, i, 0) if p.requires_settings(): grid_plugins.addWidget(EnterButton(_('Settings'), p.settings_dialog), i, 1) - grid_plugins.addWidget(HelpButton(description), i, 2) + grid_plugins.addWidget(HelpButton(p.description()), i, 2) except: print_msg("Error: cannot display plugin", p) traceback.print_exc(file=sys.stdout) diff --git a/gui/plugins.py b/gui/plugins.py @@ -2,27 +2,42 @@ class BasePlugin: - def get_info(self): - return self.fullname, self.description - - def __init__(self, gui, name, fullname, description): - self.name = name - self.fullname = fullname - self.description = description + def __init__(self, gui, name): self.gui = gui + self.name = name self.config = gui.config + def fullname(self): + return self.name + + def description(self): + return 'undefined' + def requires_settings(self): return False def toggle(self): - enabled = not self.is_enabled() - self.set_enabled(enabled) - self.init_gui() - return enabled + if self.is_enabled(): + if self.disable(): + self.close() + else: + if self.enable(): + self.init() + + return self.is_enabled() + - def init_gui(self): - pass + def enable(self): + self.set_enabled(True) + return True + + def disable(self): + self.set_enabled(False) + return True + + def init(self): pass + + def close(self): pass def is_enabled(self): return self.is_available() and self.config.get('use_'+self.name) is True diff --git a/lib/version.py b/lib/version.py @@ -1,4 +1,4 @@ -ELECTRUM_VERSION = "1.8.1" # version of the client package +ELECTRUM_VERSION = "1.9" # version of the client package PROTOCOL_VERSION = '0.6' # protocol version requested SEED_VERSION = 4 # bump this every time the seed generation is modified TRANSLATION_ID = 4101 # version of the wiki page diff --git a/plugins/aliases.py b/plugins/aliases.py @@ -20,13 +20,17 @@ ALIAS_REGEXP = '^(|([\w\-\.]+)@)((\w[\w\-]+\.)+[\w\-]+)$' from electrum_gui import BasePlugin class Plugin(BasePlugin): - def __init__(self, gui): - BasePlugin.__init__(self, gui, 'aliases', 'Aliases', _('Retrieve aliases using http.')) + def fullname(self): return 'Aliases' + + def description(self): return _('Retrieve aliases using http.') + + def init(self): self.aliases = self.config.get('aliases', {}) # aliases for addresses self.authorities = self.config.get('authorities', {}) # trusted addresses self.receipts = self.config.get('receipts',{}) # signed URIs + def timer_actions(self): if self.gui.payto_e.hasFocus(): return diff --git a/plugins/labels.py b/plugins/labels.py @@ -21,6 +21,13 @@ from electrum_gui.i18n import _ from electrum_gui.gui_classic import HelpButton class Plugin(BasePlugin): + + def fullname(self): + return _('Label Sync') + + def description(self): + return '%s\n\n%s%s%s' % (_("This plugin can sync your labels across multiple Electrum installs by using a remote database to save your data. Labels, transactions and addresses are all sent and stored encrypted on the remote server. This code might increase the load of your wallet with a few microseconds as it will sync labels on each startup."), _("To get started visit"), " http://labelectrum.herokuapp.com/", _(" to sign up for an account.")) + def version(self): return "0.2.1" @@ -35,34 +42,32 @@ class Plugin(BasePlugin): return decoded_message - def __init__(self, gui): - self.target_host = 'labelectrum.herokuapp.com' - BasePlugin.__init__(self, gui, 'labels', _('Label Sync'), '%s\n\n%s%s%s' % (_("This plugin can sync your labels across multiple Electrum installs by using a remote database to save your data. Labels, transactions and addresses are all sent and stored encrypted on the remote server. This code might increase the load of your wallet with a few microseconds as it will sync labels on each startup."), _("To get started visit"), " http://labelectrum.herokuapp.com/", _(" to sign up for an account."))) + def init(self): + self.target_host = 'labelectrum.herokuapp.com' self.wallet = gui.wallet self.gui = gui self.config = gui.config self.labels = self.wallet.labels self.transactions = self.wallet.transactions - self.encode_password = hashlib.sha1(self.config.get("master_public_key")).digest().encode('hex')[:32] - - self.wallet_id = hashlib.sha256(str(self.config.get("master_public_key"))).digest().encode('hex') + mpk = self.wallet.master_public_keys["m/0'/"][1] + self.encode_password = hashlib.sha1(mpk).digest().encode('hex')[:32] + self.wallet_id = hashlib.sha256(mpk).digest().encode('hex') addresses = [] - for k, account in self.wallet.accounts.items(): - for address in account[0]: + for account in self.wallet.accounts.values(): + for address in account.get_addresses(0): addresses.append(address) self.addresses = addresses - def auth_token(self): - return self.config.get("plugin_label_api_key") - - def init_gui(self): - if self.is_enabled() and self.auth_token(): + if self.auth_token(): # If there is an auth token we can try to actually start syncing self.full_pull() + def auth_token(self): + return self.config.get("plugin_label_api_key") + def is_available(self): return True @@ -138,18 +143,14 @@ class Plugin(BasePlugin): else: return False - def toggle(self): - enabled = not self.is_enabled() - self.set_enabled(enabled) - self.init_gui() - - if not self.auth_token() and enabled: # First run, throw plugin settings in your face + def enable(self): + if not self.auth_token(): # First run, throw plugin settings in your face if self.settings_dialog(): - self.set_enabled(True) - return True + self.set_enabled(True) + return True else: - self.set_enabled(False) - return False + self.set_enabled(False) + return False return enabled def full_push(self): diff --git a/plugins/pointofsale.py b/plugins/pointofsale.py @@ -93,23 +93,24 @@ class QR_Window(QWidget): class Plugin(BasePlugin): - def __init__(self, gui): - BasePlugin.__init__(self, gui, 'pointofsale', 'Point of Sale', - _('Show QR code window and amounts requested for each address. Add menu item to request amount.') ) + def fullname(self): + return 'Point of Sale' + + def description(self): + return _('Show QR code window and amounts requested for each address. Add menu item to request amount.') + + def init(self): self.qr_window = None self.requested_amounts = self.config.get('requested_amounts',{}) self.merchant_name = self.config.get('merchant_name', 'Invoice') + self.gui.expert_mode = True + self.gui.receive_list.setHeaderLabels([ _('Address'), _('Label'), _('Balance'), _('Request')]) + self.toggle_QR_window(True) - def init_gui(self): - enabled = self.is_enabled() - if enabled: - self.gui.expert_mode = True - self.gui.receive_list.setHeaderLabels([ _('Address'), _('Label'), _('Balance'), _('Request')]) - else: - self.gui.receive_list.setHeaderLabels([ _('Address'), _('Label'), _('Balance'), _('Tx')]) - - self.toggle_QR_window(enabled) + def close(self): + self.gui.receive_list.setHeaderLabels([ _('Address'), _('Label'), _('Balance'), _('Tx')]) + self.toggle_QR_window(False) def close_main_window(self): diff --git a/plugins/qrscanner.py b/plugins/qrscanner.py @@ -18,10 +18,14 @@ except ImportError: from electrum_gui import BasePlugin class Plugin(BasePlugin): - def __init__(self, gui): - BasePlugin.__init__(self, gui, 'qrscans', 'QR scans', "QR Scans.\nInstall the zbar package (http://zbar.sourceforge.net/download.html) to enable this plugin") + def fullname(self): return 'QR scans' + + def description(self): return "QR Scans.\nInstall the zbar package (http://zbar.sourceforge.net/download.html) to enable this plugin" + + def __init__(self, gui, name): + BasePlugin.__init__(self, gui, name) self._is_available = self._init() - + def _init(self): if not zbar: return False diff --git a/plugins/virtualkeyboard.py b/plugins/virtualkeyboard.py @@ -5,8 +5,13 @@ from electrum_gui.i18n import _ class Plugin(BasePlugin): - def __init__(self, gui): - BasePlugin.__init__(self, gui, 'virtualkeyboard', 'Virtual Keyboard', '%s\n%s' % (_("Add an optional, mouse keyboard to the password dialog."), _("Warning: do not use this if it makes you pick a weaker password."))) + def fullname(self): + return 'Virtual Keyboard' + + def description(self): + return '%s\n%s' % (_("Add an optional, mouse keyboard to the password dialog."), _("Warning: do not use this if it makes you pick a weaker password.")) + + def init(self): self.vkb = None self.vkb_index = 0