URI: 
       tadd NotEnoughFunds exception - electrum - Electrum Bitcoin wallet
  HTML git clone https://git.parazyd.org/electrum
   DIR Log
   DIR Files
   DIR Refs
   DIR Submodules
       ---
   DIR commit 01cf04079f990839eb413bfbbde20a3bae24d90e
   DIR parent 5adb10e4d2229a9ac7e3d8ec271e36fcf24ab516
  HTML Author: ThomasV <thomasv@gitorious>
       Date:   Thu, 20 Nov 2014 19:10:43 +0100
       
       add NotEnoughFunds exception
       
       Diffstat:
         M gui/gtk.py                          |      14 ++++++++------
         M gui/qt/main_window.py               |      11 +++++++----
         M lib/util.py                         |       1 +
         M lib/wallet.py                       |       7 ++++---
       
       4 files changed, 20 insertions(+), 13 deletions(-)
       ---
   DIR diff --git a/gui/gtk.py b/gui/gtk.py
       t@@ -680,19 +680,22 @@ class ElectrumWindow:
                self.user_fee = False
        
                def entry_changed( entry, is_fee ):
       -            self.funds_error = False
                    amount = numbify(amount_entry)
                    fee = numbify(fee_entry)
                    if not is_fee: fee = None
                    if amount is None:
                        return
       -            tx = self.wallet.make_unsigned_transaction([('op_return', 'dummy_tx', amount)], fee)
       -            if not is_fee:
       -                if tx:
       +            try:
       +                tx = self.wallet.make_unsigned_transaction([('op_return', 'dummy_tx', amount)], fee)
       +                self.funds_error = False
       +            except NotEnoughFunds:
       +                self.funds_error = True
       +
       +            if not self.funds_error:
       +                if not is_fee:
                            fee = tx.get_fee()
                            fee_entry.set_text( str( Decimal( fee ) / 100000000 ) )
                            self.fee_box.show()
       -            if tx:
                        amount_entry.modify_text(Gtk.StateType.NORMAL, Gdk.color_parse("#000000"))
                        fee_entry.modify_text(Gtk.StateType.NORMAL, Gdk.color_parse("#000000"))
                        send_button.set_sensitive(True)
       t@@ -700,7 +703,6 @@ class ElectrumWindow:
                        send_button.set_sensitive(False)
                        amount_entry.modify_text(Gtk.StateType.NORMAL, Gdk.color_parse("#cc0000"))
                        fee_entry.modify_text(Gtk.StateType.NORMAL, Gdk.color_parse("#cc0000"))
       -                self.funds_error = True
        
                amount_entry.connect('changed', entry_changed, False)
                fee_entry.connect('changed', entry_changed, True)        
   DIR diff --git a/gui/qt/main_window.py b/gui/qt/main_window.py
       t@@ -35,7 +35,7 @@ from electrum.plugins import run_hook
        
        import icons_rc
        
       -from electrum.util import format_satoshis
       +from electrum.util import format_satoshis, NotEnoughFunds
        from electrum import Transaction
        from electrum import mnemonic
        from electrum import util, bitcoin, commands, Interface, Wallet
       t@@ -953,10 +953,13 @@ class ElectrumWindow(QMainWindow):
                        if not outputs:
                            addr = self.payto_e.payto_address if self.payto_e.payto_address else self.dummy_address
                            outputs = [('address', addr, amount)]
       -                tx = self.wallet.make_unsigned_transaction(outputs, fee, coins = self.get_coins())
       -                self.not_enough_funds = (tx is None)
       +                try:
       +                    tx = self.wallet.make_unsigned_transaction(outputs, fee, coins = self.get_coins())
       +                    self.not_enough_funds = False
       +                except NotEnoughFunds:
       +                    self.not_enough_funds = True
                        if not is_fee:
       -                    fee = self.wallet.get_tx_fee(tx) if tx else None
       +                    fee = None if self.not_enough_funds else self.wallet.get_tx_fee(tx)
                            self.fee_e.setAmount(fee)
        
                self.payto_e.textChanged.connect(lambda:text_edited(False))
   DIR diff --git a/lib/util.py b/lib/util.py
       t@@ -4,6 +4,7 @@ import shutil
        from datetime import datetime
        is_verbose = False
        
       +class NotEnoughFunds(Exception): pass
        
        class MyEncoder(json.JSONEncoder):
            def default(self, obj):
   DIR diff --git a/lib/wallet.py b/lib/wallet.py
       t@@ -27,7 +27,7 @@ import math
        import json
        import copy
        
       -from util import print_msg, print_error
       +from util import print_msg, print_error, NotEnoughFunds
        
        from bitcoin import *
        from account import *
       t@@ -712,8 +712,9 @@ class Abstract_Wallet(object):
                    fee = fixed_fee if fixed_fee is not None else self.estimated_fee(tx)
                    if total >= amount + fee: break
                else:
       -            print_error("Not enough funds", total, amount, fee)
       -            return None
       +            raise NotEnoughFunds()
       +            #print_error("Not enough funds", total, amount, fee)
       +            #return None
        
                # change address
                if not change_addr: