electrum-bitcoinprivate/lib/gui_text.py

130 lines
4.1 KiB
Python
Raw Normal View History

2012-10-17 00:24:31 -07:00
import curses, datetime
from decimal import Decimal
from util import format_satoshis, set_verbosity
2012-10-17 00:24:31 -07:00
WIDTH=150
class ElectrumGui:
def __init__(self, wallet, config, app=None):
self.wallet = wallet
self.config = config
self.stdscr = curses.initscr()
curses.noecho()
curses.cbreak()
curses.start_color()
self.stdscr.keypad(1)
self.stdscr.border(0)
self.maxy, self.maxx = self.stdscr.getmaxyx()
set_verbosity(False)
2012-10-29 09:23:50 -07:00
self.tab = 0
2012-10-17 00:24:31 -07:00
def server_list_changed(self):
pass
def restore_or_create(self):
pass
def print_history(self):
b = 0
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"))
2012-10-17 00:24:31 -07:00
def print_balance(self):
c, u = self.wallet.get_balance()
msg = "Balance: %f"%(Decimal( c ) / 100000000)
if u:
msg += " [%f unconfirmed]"%(Decimal( u ) / 100000000)
self.stdscr.addstr( self.maxy -3, 2, msg)
2012-10-29 09:23:50 -07:00
tab_names = ["History", "Send", "Receive", "Contacts"]
for i in range(4):
self.stdscr.addstr( 0, 2+9*i, tab_names[i], curses.A_BOLD if self.tab == i else 0)
self.stdscr.addstr( self.maxy -1, self.maxx-30, " Settings Network Quit ")
2012-10-17 00:24:31 -07:00
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"))
2012-10-17 00:24:31 -07:00
def print_receive(self):
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")
2012-10-29 09:23:50 -07:00
return
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])
2012-10-17 00:24:31 -07:00
def refresh(self):
2012-10-29 09:23:50 -07:00
self.stdscr.border(0)
2012-10-17 00:24:31 -07:00
self.print_balance()
self.stdscr.refresh()
def main(self,url):
self.print_history()
self.refresh()
while 1:
c = self.stdscr.getch()
2012-10-29 09:23:50 -07:00
if c == curses.KEY_RIGHT: self.tab = (self.tab + 1)%4
if c == curses.KEY_LEFT: self.tab = (self.tab - 1)%4
elif c == ord('h'): self.tab = 0
elif c == ord('s'): self.tab = 1
elif c == ord('r'): self.tab = 2
elif c == ord('c'): self.tab = 3
2012-10-17 00:24:31 -07:00
elif c == ord('q'): break
elif c == curses.KEY_HOME: x = y = 0
2012-10-29 09:23:50 -07:00
if self.tab == 0:
self.print_history()
elif self.tab == 1:
self.print_send_dialog()
elif self.tab == 2:
self.print_receive()
else:
self.print_contacts()
2012-10-17 00:24:31 -07:00
self.refresh()
curses.nocbreak();
self.stdscr.keypad(0);
curses.echo()
curses.endwin()