first commit
[bitcoin:spesmilo.git] / send.py
1 from PySide.QtCore import *
2 from PySide.QtGui import *
3 from PySide.QtWebKit import *
4
5 class SendDialog(QDialog):
6     def __init__(self, core, parent):
7         super(SendDialog, self).__init__(parent)
8         self.core = core
9         
10         formlay = QFormLayout()
11         self.destaddy = QLineEdit()
12         self.amount = QLineEdit()
13         self.amount.setAlignment(Qt.AlignRight|Qt.AlignVCenter)
14         dv = QDoubleValidator()
15         dv.setDecimals(2)
16         dv.setNotation(QDoubleValidator.StandardNotation)
17         self.amount.setValidator(dv)
18         formlay.addRow(self.tr('Pay to:'), self.destaddy)
19         amountlay = QHBoxLayout()
20         amountlay.addWidget(self.amount)
21         amountlay.addStretch()
22         formlay.addRow(self.tr('Amount:'), amountlay)
23
24         actionlay = QHBoxLayout()
25         sendbtn = QPushButton(self.tr('Send'))
26         sendbtn.clicked.connect(self.do_payment)
27         cancelbtn = QPushButton(self.tr('Cancel'))
28         cancelbtn.clicked.connect(self.reject)
29         actionlay.addStretch()
30         actionlay.addWidget(sendbtn)
31         actionlay.addWidget(cancelbtn)
32
33         # layout includes form + instructions
34         instructions = QLabel(self.tr('<i>Enter a bitcoin address (e.g. 1A9Pv2PYuZYvfqku7sJxovw99Az72mZ4YH)</i>'))
35         mainlay = QVBoxLayout(self)
36         mainlay.addWidget(instructions)
37         mainlay.addLayout(formlay)
38         mainlay.addLayout(actionlay)
39
40         if parent is not None:
41             self.setWindowIcon(parent.bitcoin_icon)
42         self.setWindowTitle(self.tr('Send bitcoins'))
43         self.show()
44
45     def do_payment(self):
46         if not self.amount.text():
47             self.amount.setFocus(Qt.OtherFocusReason)
48             return
49         self.hide()
50
51         addy = self.destaddy.text()
52         if not self.core.validate_address(addy):
53             error = QMessageBox(QMessageBox.Critical, 
54                                 self.tr('Invalid address'),
55                                 self.tr('Invalid address: %s')%addy)
56             error.exec_()
57             self.reject()
58             return
59
60         amount = float(self.amount.text())
61         balance = self.core.balance()
62         if amount > balance:
63             error = QMessageBox(QMessageBox.Critical, 
64                                 self.tr('Insufficient balance'),
65                             self.tr('Balance of %g is too small.')%balance)
66             error.exec_()
67             self.reject()
68             return
69
70         self.core.send(addy, amount)
71         self.accept()
72
73 if __name__ == '__main__':
74     import os
75     import sys
76     import core_interface
77     os.system('bitcoind')
78     translator = QTranslator()
79     #translator.load('data/translations/eo_EO')
80     app = QApplication(sys.argv)
81     core = core_interface.CoreInterface()
82     send = SendDialog(core, None)
83     sys.exit(app.exec_())