2012-02-11 22:27:32 -08:00
|
|
|
import sys, time, datetime
|
2012-02-11 04:14:12 -08:00
|
|
|
|
2012-02-11 08:02:28 -08:00
|
|
|
# todo: see PySide
|
|
|
|
|
2012-02-11 04:14:12 -08:00
|
|
|
from PyQt4.QtGui import *
|
2012-02-11 08:02:28 -08:00
|
|
|
from PyQt4.QtCore import *
|
2012-02-11 04:14:12 -08:00
|
|
|
import PyQt4.QtCore as QtCore
|
2012-02-11 08:02:28 -08:00
|
|
|
import PyQt4.QtGui as QtGui
|
2012-02-11 04:14:12 -08:00
|
|
|
|
2012-02-11 13:19:22 -08:00
|
|
|
from wallet import format_satoshis
|
|
|
|
|
2012-02-11 04:14:12 -08:00
|
|
|
def restore_create_dialog(wallet):
|
|
|
|
pass
|
|
|
|
|
2012-02-11 13:19:22 -08:00
|
|
|
class Sender(QtCore.QThread):
|
|
|
|
def run(self):
|
|
|
|
while True:
|
|
|
|
self.emit(QtCore.SIGNAL('testsignal'))
|
|
|
|
time.sleep(0.5)
|
|
|
|
|
2012-02-11 04:14:12 -08:00
|
|
|
|
2012-02-11 08:38:44 -08:00
|
|
|
class BitcoinWidget(QMainWindow):
|
2012-02-11 04:14:12 -08:00
|
|
|
|
|
|
|
def __init__(self, wallet):
|
2012-02-11 08:38:44 -08:00
|
|
|
QMainWindow.__init__(self)
|
2012-02-11 04:14:12 -08:00
|
|
|
self.wallet = wallet
|
2012-02-11 13:19:22 -08:00
|
|
|
|
2012-02-11 08:38:44 -08:00
|
|
|
tabs = QTabWidget(self)
|
|
|
|
tabs.addTab(self.create_history_tab(), 'History')
|
|
|
|
tabs.addTab(self.create_send_tab(), 'Send')
|
|
|
|
tabs.addTab(self.create_receive_tab(), 'Receive')
|
|
|
|
tabs.addTab(self.create_contacts_tab(),'Contacts')
|
|
|
|
tabs.addTab(self.create_wall_tab(), 'Wall')
|
2012-02-11 13:19:22 -08:00
|
|
|
tabs.setMinimumSize(600, 400)
|
2012-02-11 22:27:32 -08:00
|
|
|
tabs.setSizePolicy(QtGui.QSizePolicy.Expanding, QtGui.QSizePolicy.Expanding)
|
|
|
|
|
2012-02-11 08:38:44 -08:00
|
|
|
tabs.show()
|
|
|
|
|
|
|
|
self.create_status_bar()
|
|
|
|
|
|
|
|
self.setGeometry(100,100,750,550)
|
|
|
|
self.setWindowTitle( 'Electrum ' + self.wallet.electrum_version )
|
|
|
|
self.show()
|
|
|
|
|
2012-02-11 13:19:22 -08:00
|
|
|
def connect_slots(self, sender):
|
|
|
|
self.connect(sender, QtCore.SIGNAL('testsignal'), self.update_wallet)
|
|
|
|
|
|
|
|
def update_wallet(self):
|
|
|
|
if self.wallet.interface.is_connected:
|
|
|
|
if self.wallet.interface.blocks == 0:
|
|
|
|
text = "Server not ready"
|
|
|
|
elif not self.wallet.interface.was_polled:
|
|
|
|
text = "Synchronizing..."
|
|
|
|
else:
|
|
|
|
c, u = self.wallet.get_balance()
|
|
|
|
text = "Balance: %s "%( format_satoshis(c) )
|
|
|
|
if u: text += "[%s unconfirmed]"%( format_satoshis(u,True) )
|
|
|
|
else:
|
|
|
|
text = "Not connected"
|
|
|
|
self.statusBar().showMessage(text)
|
|
|
|
|
|
|
|
if self.wallet.interface.was_updated:
|
|
|
|
self.textbox.setText( self.wallet.interface.message )
|
|
|
|
self.wallet.interface.was_updated = False
|
2012-02-11 22:27:32 -08:00
|
|
|
self.update_history_tab()
|
|
|
|
|
2012-02-11 04:14:12 -08:00
|
|
|
|
2012-02-11 08:02:28 -08:00
|
|
|
def create_history_tab(self):
|
2012-02-11 22:27:32 -08:00
|
|
|
self.history_list = w = QTreeWidget(self)
|
|
|
|
w.setColumnCount(5)
|
|
|
|
w.setHeaderLabels( ['conf', 'Date','Description','Amount','Balance'])
|
|
|
|
return w
|
|
|
|
|
|
|
|
|
|
|
|
def update_history_tab(self):
|
|
|
|
self.history_list.clear()
|
|
|
|
balance = 0
|
|
|
|
for tx in self.wallet.get_tx_history():
|
|
|
|
tx_hash = tx['tx_hash']
|
|
|
|
if tx['height']:
|
|
|
|
conf = self.wallet.interface.blocks - tx['height'] + 1
|
|
|
|
time_str = datetime.datetime.fromtimestamp( tx['nTime']).isoformat(' ')[:-3]
|
|
|
|
else:
|
|
|
|
conf = 0
|
|
|
|
time_str = 'pending'
|
|
|
|
v = tx['value']
|
|
|
|
balance += v
|
|
|
|
label = self.wallet.labels.get(tx_hash)
|
|
|
|
is_default_label = (label == '') or (label is None)
|
|
|
|
if is_default_label: label = tx['default_label']
|
|
|
|
item = QTreeWidgetItem( [ "%d"%conf, time_str, label, format_satoshis(v,True), format_satoshis(balance)] )
|
|
|
|
self.history_list.addTopLevelItem(item)
|
|
|
|
|
2012-02-11 08:02:28 -08:00
|
|
|
|
|
|
|
def create_send_tab(self):
|
2012-02-11 22:27:32 -08:00
|
|
|
w = QWidget()
|
|
|
|
|
|
|
|
paytoEdit = QtGui.QLineEdit()
|
|
|
|
descriptionEdit = QtGui.QLineEdit()
|
|
|
|
amountEdit = QtGui.QLineEdit()
|
|
|
|
feeEdit = QtGui.QLineEdit()
|
|
|
|
|
|
|
|
grid = QtGui.QGridLayout()
|
|
|
|
grid.setSpacing(8)
|
|
|
|
|
|
|
|
grid.addWidget(QLabel('Pay to'), 1, 0)
|
|
|
|
grid.addWidget(paytoEdit, 1, 1)
|
|
|
|
|
|
|
|
grid.addWidget(QLabel('Description'), 2, 0)
|
|
|
|
grid.addWidget(descriptionEdit, 2, 1)
|
|
|
|
|
|
|
|
grid.addWidget(QLabel('Amount'), 3, 0)
|
|
|
|
grid.addWidget(amountEdit, 3, 1)
|
|
|
|
|
|
|
|
grid.addWidget(QLabel('Fee'), 4, 0)
|
|
|
|
grid.addWidget(feeEdit, 4, 1)
|
|
|
|
|
|
|
|
w.setLayout(grid)
|
|
|
|
w.show()
|
|
|
|
|
|
|
|
w2 = QWidget()
|
|
|
|
vbox = QtGui.QVBoxLayout()
|
|
|
|
vbox.addWidget(w)
|
|
|
|
vbox.addStretch(1)
|
|
|
|
w2.setLayout(vbox)
|
|
|
|
|
|
|
|
return w2
|
2012-02-11 08:02:28 -08:00
|
|
|
|
|
|
|
def create_receive_tab(self):
|
2012-02-11 22:27:32 -08:00
|
|
|
self.addresses_list = w = QTreeWidget(self)
|
|
|
|
w.setColumnCount(3)
|
|
|
|
w.setHeaderLabels( ['Address', 'Label','Tx'])
|
|
|
|
return w
|
2012-02-11 08:02:28 -08:00
|
|
|
|
|
|
|
def create_contacts_tab(self):
|
2012-02-11 22:27:32 -08:00
|
|
|
self.contacts_list = w = QTreeWidget(self)
|
|
|
|
w.setColumnCount(3)
|
|
|
|
w.setHeaderLabels( ['Address', 'Label','Tx'])
|
|
|
|
return w
|
2012-02-11 08:02:28 -08:00
|
|
|
|
|
|
|
def create_wall_tab(self):
|
2012-02-11 13:19:22 -08:00
|
|
|
self.textbox = textbox = QTextEdit(self)
|
|
|
|
textbox.setReadOnly(True)
|
|
|
|
return textbox
|
2012-02-11 08:02:28 -08:00
|
|
|
|
2012-02-11 08:38:44 -08:00
|
|
|
def create_status_bar(self):
|
|
|
|
sb = QStatusBar()
|
2012-02-11 22:27:32 -08:00
|
|
|
sb.setFixedHeight(20)
|
2012-02-11 08:38:44 -08:00
|
|
|
self.setStatusBar(sb)
|
|
|
|
|
2012-02-11 04:14:12 -08:00
|
|
|
|
|
|
|
class BitcoinGUI():
|
|
|
|
|
|
|
|
def __init__(self, wallet):
|
|
|
|
self.wallet = wallet
|
|
|
|
|
|
|
|
def main(self):
|
2012-02-11 13:19:22 -08:00
|
|
|
s = Sender()
|
|
|
|
s.start()
|
2012-02-11 04:14:12 -08:00
|
|
|
app = QApplication(sys.argv)
|
|
|
|
w = BitcoinWidget(self.wallet)
|
2012-02-11 13:19:22 -08:00
|
|
|
w.connect_slots(s)
|
2012-02-11 04:14:12 -08:00
|
|
|
app.exec_()
|