def _startup(rootwindow, *args, **kwargs): if SpesmiloSettings.useInternalCore(): import os user, passwd, port = SpesmiloSettings.getInternalCoreAuth() cmd = ('bitcoind', '-rpcuser=%s' % (user,), '-rpcpassword=%s' % (passwd,), '-rpcallowip=127.0.0.1', '-rpcport=%d' % (port,)) if len(args): options = args[0] cmd += options.bitcoind quietPopen(cmd) import ipc ipcsrv = ipc.ipc_handler('Bitcoin') ipcsrv.have_uri.connect(lambda x: receive_uri(rootwindow, x), Qt.QueuedConnection) ipcsrv.start() rootwindow.ipcsrv = ipcsrv rootwindow.start(*args, **kwargs)
def stop(self, doQuit = True): try: self.refresh_state_timer.stop() if SpesmiloSettings.useInternalCore() and self.core: # Keep looping until connected so we can issue the stop command while True: try: self.core.stop() except core_interface.JSONRPCException: pass except IOError: break except socket.error: break except: raise else: break # Re-proprogate exception & trigger app exit so we can break out except: raise finally: self.core = None if hasattr(self, 'ipcsrv'): try: self.ipcsrv.stop() except: pass if doQuit: qApp.quit()
def __init__(self, core = None, parent = None, uri = None, autostart = True): super(SendDialog, self).__init__(parent) self.core = core _windows[id(self)] = self formlay = QFormLayout() self.destaddy = QLineEdit() self.amount = QLineEdit() self.amount.setAlignment(Qt.AlignRight|Qt.AlignVCenter) amount_max_width = self.fontMetrics().averageCharWidth() * 10 self.amount.setMaximumWidth(amount_max_width) dv = QDoubleValidator(self.amount) dv.setDecimals(2) dv.setNotation(QDoubleValidator.StandardNotation) self.dv = dv tv = QRegExpValidator(QRegExp('-?(?:[\d\\xe9d9-\\xe9df]+\.?|[\d\\xe9d9-\\xe9df]*\.[\d\\xe9d9-\\xe9df]{1,4})'), self.amount) self.tv = tv self.amount_unit = QComboBox(self) self.amount_unit.addItem(self.tr("BTC"), "BTC") self.amount_unit.addItem(self.tr("TBC"), "TBC") self.amount_unit.currentIndexChanged.connect(self.update_validator) prefunit = 'TBC' if SpesmiloSettings.getNumberSystem() == 'Tonal' else 'BTC' self.amount_unit.setCurrentIndex(self.amount_unit.findData(prefunit)) formlay.addRow(self.tr('Pay to:'), self.destaddy) amountlay = QHBoxLayout() amountlay.addWidget(self.amount) amountlay.addWidget(self.amount_unit) amountlay.addStretch() formlay.addRow(self.tr('Amount:'), amountlay) actionlay = QHBoxLayout() sendbtn = QPushButton(self.tr('&Send')) sendbtn.clicked.connect(self.do_payment) sendbtn.setAutoDefault(True) cancelbtn = QPushButton(self.tr('&Cancel')) cancelbtn.clicked.connect(self.reject) actionlay.addStretch() actionlay.addWidget(sendbtn) actionlay.addWidget(cancelbtn) # layout includes form + instructions instructions = QLabel(self.tr('<i>Enter a bitcoin address (e.g. 1A9Pv2PYuZYvfqku7sJxovw99Az72mZ4YH)</i>')) mainlay = QVBoxLayout(self) mainlay.addWidget(instructions) mainlay.addLayout(formlay) mainlay.addLayout(actionlay) if parent is not None: self.setWindowIcon(parent.bitcoin_icon) self.setWindowTitle(self.tr('Send bitcoins')) if not uri is None: self.load_uri(uri) if autostart: self.start()
def start(self, options = None, args = None): if not self.core: import core_interface uri = SpesmiloSettings.getEffectiveURI() self.core = core_interface.CoreInterface(uri) if args: self.load_uri(args[0]) self.show() self.destaddy.setFocus()
def load_uri(self, uri): m = re.match(r'^bitcoin\:([1-9A-HJ-NP-Za-km-z]*)(?:\?(.*))?$', uri) if m is None: raise RuntimeError(self.tr('Invalid bitcoin URI')) addr = m.group(1) query = m.group(2) param = {} if not query is None: query = re.split(r'[&?;]', query) for q in query: k, v = q.split('=', 1) param[k] = v self.destaddy.setText(addr) if 'amount' in param: amount = param['amount'] m = re.match(r'^(([\d.]+)(X(\d+))?|x([\da-f]*)(\.([\da-f]*))?(X([\da-f]+))?)$', amount, re.IGNORECASE) if m.group(5): # TBC amount = float(int(m.group(5), 16)) if m.group(7): amount += float(int(m.group(7), 16)) * pow(16, -(len(m.group(7)))) if m.group(9): amount *= pow(16, int(m.group(9), 16)) else: amount *= 0x10000 NU = 'Tonal' else: amount = Decimal(m.group(2)) if m.group(4): amount *= 10 ** int(m.group(4)) else: amount *= 100000000 NU = 'Decimal' amount = int(amount) NU = SpesmiloSettings.ChooseUnits(amount, NU) if NU == 'Tonal': self.amount_unit.setCurrentIndex(self.amount_unit.findData('TBC')) amount = SpesmiloSettings._toTBC(amount, addSign=False, wantTLA=False) else: self.amount_unit.setCurrentIndex(self.amount_unit.findData('BTC')) amount = SpesmiloSettings._toBTC(amount, addSign=False, wantTLA=False) self.amount.setText(amount)
def start(self, options = None, args = None): self.state = self.CLIENT_NONE self.uri = SpesmiloSettings.getEffectiveURI() self.core = core_interface.CoreInterface(self.uri) self.core.tr = lambda s: self.app.translate('CoreInterface', s) if hasattr(self, 'tray'): self.tray.hide() del self.tray self.tray = TrayIcon(self.core, self) refresh_state_timer = QTimer(self) self.refresh_state_timer = refresh_state_timer refresh_state_timer.timeout.connect(self.refresh_state) refresh_state_timer.start(1000) self.refresh_state()
del parser.rargs[:len(value) + 1] setattr(parser.values, option.dest, tuple(value)) import optparse import os import sys if hasattr(sys, 'frozen') and sys.frozen == "windows_exe": sys.stderr = sys.stdout app = QApplication(sys.argv) font = app.font() if not QFontMetrics(font).inFont(0xe9d9): font.setFamily(font.family() + ', tonal, Tonal (Luxi Mono)') app.setFont(font) SpesmiloSettings.loadTranslator() argp = optparse.OptionParser(usage=app.tr('Usage: %prog [options] [URI]')) #argp.add_option('URI', nargs='?', help=app.tr('a bitcoin: URI to open a send dialog to')) argp.add_option('--caption', dest='caption', nargs=1, default=None, help=app.tr('Use this caption for the cashier window')) #argp.add_option('--cashier', dest='cashier', action='store_true', default=False, # help=app.tr('Opens a view of your transactions')) #argp.add_option('--config', dest='config', nargs=1, # help=app.tr('Use an alternative config')) argp.add_option('--debug', dest='debug', action='store_true', default=False, help=app.tr('Opens an interactive Python prompt, and enables infinite in-RAM logging')) argp.add_option('--icon', dest='icon', nargs=1, default=None, help=app.tr('Use this window icon')) argp.add_option('--send', dest='send', action='store_true', default=False, help=app.tr('Opens a dialog to send funds'))
self.addy.setText(self.core.new_address()) def copy_address(self): self.clipboard.setText(self.addy.text()) def open_settings(self): if hasattr(self, "settingsdlg"): self.settingsdlg.show() self.settingsdlg.setFocus() else: import settings self.settingsdlg = settings.SettingsDialog(self) if __name__ == "__main__": import os import sys import core_interface from settings import SpesmiloSettings os.system("/home/genjix/src/bitcoin/bitcoind") app = QApplication(sys.argv) SpesmiloSettings.loadTranslator() uri = SpesmiloSettings.getEffectiveURI() core = core_interface.CoreInterface(uri) clipboard = qApp.clipboard() cashier = Cashier(core, clipboard) cashier.show() sys.exit(app.exec_())
try: self.core.send(addy, amount) except Exception, e: error = QMessageBox(QMessageBox.Critical, self.tr('Error sending'), self.tr('Your send failed: %s') % (e,)) error.exec_() self.reject() return self.accept() def accept(self): del _windows[id(self)] QDialog.accept(self) def reject(self): del _windows[id(self)] QDialog.reject(self) if __name__ == '__main__': import os import sys import core_interface from settings import SpesmiloSettings os.system('bitcoind') app = QApplication(sys.argv) SpesmiloSettings.loadTranslator() send = SendDialog(None, None, sys.argv[1] if len(sys.argv) > 1 else None, autostart=False) send.start() sys.exit(app.exec_())