1
0

Improve text gui. Disable print_error when text gui is used.

This commit is contained in:
thomasv
2012-10-29 16:22:53 +01:00
parent cdb52c30d2
commit 5e28ccd09d
5 changed files with 68 additions and 54 deletions

View File

@@ -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
@@ -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
@@ -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()
@@ -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()