URI: 
       tImprove text gui. Disable print_error when text gui is used. - electrum - Electrum Bitcoin wallet
  HTML git clone https://git.parazyd.org/electrum
   DIR Log
   DIR Files
   DIR Refs
   DIR Submodules
       ---
   DIR commit 5e28ccd09d924428de617b71fb218991cfd0d17c
   DIR parent cdb52c30d286c4829008e8765b995464624354fa
  HTML Author: thomasv <thomasv@gitorious>
       Date:   Mon, 29 Oct 2012 16:22:53 +0100
       
       Improve text gui. Disable print_error when text gui is used.
       
       Diffstat:
         M electrum                            |      12 +++++-------
         M lib/__init__.py                     |       2 +-
         M lib/gui_text.py                     |      97 +++++++++++++++++--------------
         M lib/util.py                         |       7 +++++++
         M lib/verifier.py                     |       4 ++--
       
       5 files changed, 68 insertions(+), 54 deletions(-)
       ---
   DIR diff --git a/electrum b/electrum
       t@@ -21,11 +21,6 @@ import sys
        import optparse
        
        try:
       -    from lib.util import print_error
       -except ImportError:
       -    from electrum.util import print_error
       -
       -try:
            import ecdsa  
        except ImportError:
            sys.exit("Error: python-ecdsa does not seem to be installed. Try 'sudo pip install ecdsa'")
       t@@ -36,9 +31,9 @@ except ImportError:
            sys.exit("Error: AES does not seem to be installed. Try 'sudo pip install slowaes'")
        
        try:
       -    from lib import Wallet, Interface, WalletSynchronizer, WalletVerifier, format_satoshis, mnemonic, SimpleConfig, pick_random_server
       +    from lib import *
        except ImportError:
       -    from electrum import Wallet, Interface, WalletSynchronizer, WalletVerifier, format_satoshis, mnemonic, SimpleConfig, pick_random_server
       +    from electrum import *
        
        from decimal import Decimal
        
       t@@ -143,8 +138,11 @@ if __name__ == '__main__':
            parser.add_option("-c", "--changeaddr", dest="change_addr", default=None, help="set the change address for payto/mktx. default is a spare address, or the source address if it's not in the wallet")
            parser.add_option("-s", "--server", dest="server", default=None, help="set server host:port:protocol, where protocol is t or h")
            parser.add_option("-p", "--proxy", dest="proxy", default=None, help="set proxy [type:]host[:port], where type is socks4,socks5 or http")
       +    #parser.add_option("-v", "--verbose", action="store_true", dest="verbose", default=False, help="show debugging information")
            options, args = parser.parse_args()
        
       +    #set_verbosity(options.verbose)
       +
            # config is an object passed to the various constructors (wallet, interface, gui)
            config = SimpleConfig(options)
            wallet = Wallet(config)
   DIR diff --git a/lib/__init__.py b/lib/__init__.py
       t@@ -1,4 +1,4 @@
       -from util import format_satoshis
       +from util import format_satoshis, print_error, set_verbosity
        from wallet import Wallet, WalletSynchronizer
        from verifier import WalletVerifier
        from interface import Interface, pick_random_server, DEFAULT_SERVERS
   DIR diff --git a/lib/gui_text.py b/lib/gui_text.py
       t@@ -1,7 +1,6 @@
        import curses, datetime
        from decimal import Decimal
       -from electrum import format_satoshis
       -
       +from util import format_satoshis, set_verbosity
        
        WIDTH=150
        
       t@@ -16,6 +15,8 @@ class ElectrumGui:
                curses.start_color()
                self.stdscr.keypad(1)
                self.stdscr.border(0)
       +        self.maxy, self.maxx = self.stdscr.getmaxyx()
       +        set_verbosity(False)
                
            def server_list_changed(self):
                pass
       t@@ -24,56 +25,63 @@ class ElectrumGui:
                pass
        
            def print_history(self):
       -        lines = self.wallet.get_tx_history()
                b = 0 
       -        i = 0
       -        for i in range(20):
       -            if i < len(lines):
       -                line = lines[i]
       -                v = line['value'] 
       -                b += v
       -                try:
       -                    time_str = str( datetime.datetime.fromtimestamp( line['timestamp']))
       -                except:
       -                    print line['timestamp']
       -                    time_str = 'pending'
       -                label = line.get('label')
       -                if not label: label = line['tx_hash']
       -                else: label = label + ' '*(64 - len(label) )
       -                msg = time_str + "  " + label + "  " + format_satoshis(v)+ "  "+ format_satoshis(b)
       -            else:
       -                msg = ""
       -        
       -            msg += " "*(WIDTH - len(msg))
       -            self.stdscr.addstr( i+2, 1, msg[0:WIDTH])
       +        messages = []
       +        for line in self.wallet.get_tx_history():
       +            v = line['value'] 
       +            b += v
       +            try:
       +                time_str = str( datetime.datetime.fromtimestamp( line['timestamp']))
       +            except:
       +                print line['timestamp']
       +                time_str = 'pending'
       +            label = line.get('label')
       +            if not label: label = line['tx_hash']
       +            else: label = label + ' '*(64 - len(label) )
       +            messages.append( time_str + "  " + label + "  " + format_satoshis(v)+ "  "+ format_satoshis(b) )
       +
       +        self.print_list(messages, "%19s  %64s %14s %10s"%("Date", "Description", "Amount", "Balance"))
       +
        
            def print_balance(self):
                c, u =  self.wallet.get_balance()
       -        msg = "Balance: %f %f"%(Decimal( c ) / 100000000 , Decimal( u ) / 100000000)
       -        self.stdscr.addstr( 22, 1, msg)
       -        self.stdscr.addstr( 24, 1, "History Send Receive Contacts Quit")
       +        msg = "Balance: %f"%(Decimal( c ) / 100000000)
       +        if u:
       +            msg += "  [%f unconfirmed]"%(Decimal( u ) / 100000000)
       +        self.stdscr.addstr( self.maxy -3, 2, msg)
       +        self.stdscr.addstr( self.maxy -1, 1, " History Send Receive Contacts Quit ")
        
            def print_contacts(self):
       -        for i in range(20):
       -            if i < len(self.wallet.addressbook):
       -                addr = self.wallet.addressbook[i]
       -                msg = "%30s    %30s       "%(addr, self.wallet.labels.get(addr,"") )
       -            else:
       -                msg = ""
       -
       -            msg += " "*(WIDTH - len(msg))
       -            self.stdscr.addstr( i+2, 1, msg[0:WIDTH])
       +        messages = map(lambda addr: "%30s    %30s       "%(addr, self.wallet.labels.get(addr,"")), self.wallet.addressbook)
       +        self.print_list(messages, "%19s  %25s "%("Address", "Label"))
        
            def print_receive(self):
       -        for i in range(20):
       -            if i < len(self.wallet.addresses):
       -                addr = self.wallet.addresses[i]
       -                msg = "%30s    %30s       "%(addr, self.wallet.labels.get(addr,"") )
       -            else:
       -                msg = ""
       -                
       -            msg += " "*(WIDTH - len(msg))
       -            self.stdscr.addstr( i+2, 1, msg[0:WIDTH])
       +        messages = map(lambda addr: "%30s    %30s       "%(addr, self.wallet.labels.get(addr,"")), self.wallet.addresses)
       +        self.print_list(messages, "%19s  %25s "%("Address", "Label"))
       +
       +    def print_send_dialog(self):
       +        self.stdscr.clear()
       +        self.stdscr.addstr( 3, 2, "Pay to")
       +        self.stdscr.addstr( 5, 2, "Description")
       +        self.stdscr.addstr( 7, 2, "Amount")
       +        self.stdscr.addstr( 9, 2, "Fee")
       +        
       +        while True:
       +            curses.echo()
       +            s = self.stdscr.getstr(3, 15)
       +            curses.noecho()
       +
       +            if s: break
       +        pass
       +
       +
       +    def print_list(self, list, firstline):
       +        firstline += " "*(self.maxx -2 - len(firstline))
       +        self.stdscr.addstr( 1, 1, firstline )
       +        for i in range(self.maxy-6):
       +            msg = list[i] if i < len(list) else ""
       +            msg += " "*(self.maxx -2 - len(msg))
       +            self.stdscr.addstr( i+2, 1, msg[0:self.maxx - 2])
        
            def refresh(self):
                self.print_balance()
       t@@ -88,6 +96,7 @@ class ElectrumGui:
                    if c == ord('h'): self.print_history()
                    if c == ord('c'): self.print_contacts()
                    if c == ord('r'): self.print_receive()
       +            if c == ord('s'): self.print_send_dialog()
                    elif c == ord('q'): break
                    elif c == curses.KEY_HOME: x = y = 0
                    self.refresh()
   DIR diff --git a/lib/util.py b/lib/util.py
       t@@ -1,7 +1,14 @@
        import os, sys
        import platform
        
       +is_verbose = True
       +
       +def set_verbosity(b):
       +    global is_verbose
       +    is_verbose = b
       +
        def print_error(*args):
       +    if not is_verbose: return
            # Stringify args
            args = [str(item) for item in args]
            sys.stderr.write(" ".join(args) + "\n")
   DIR diff --git a/lib/verifier.py b/lib/verifier.py
       t@@ -215,7 +215,7 @@ class WalletVerifier(threading.Thread):
                    # undo verifications
                    for tx_hash, tx_height in self.verified_tx.items():
                        if tx_height >= height:
       -                    print "redoing", tx_hash
       +                    print_error("redoing", tx_hash)
                            self.verified_tx.pop(tx_hash)
                            if tx_hash in self.merkle_roots: self.merkle_roots.pop(tx_hash)
                    # return False to request previous header.
       t@@ -269,7 +269,7 @@ class WalletVerifier(threading.Thread):
                if os.path.exists(filename):
                    f = open(filename,'rb+')
                else:
       -            print "creating file", filename
       +            print_error( "creating file", filename )
                    f = open(filename,'wb+')
                f.seek(index*2016*80)
                h = f.write(chunk)