diff --git a/client/electrum b/client/electrum index e066763d1..8b3242869 100755 --- a/client/electrum +++ b/client/electrum @@ -31,7 +31,7 @@ urldecode = lambda x: _ud.sub(lambda m: chr(int(m.group(1), 16)), x) from wallet import format_satoshis if __name__ == '__main__': - known_commands = ['help', 'validateaddress', 'balance', 'contacts', 'create', 'payto', 'sendtx', 'password', 'newaddress', 'addresses', 'history', 'label', 'gui', 'mktx','seed','import','signmessage','verifymessage','eval'] + known_commands = ['help', 'validateaddress', 'balance', 'contacts', 'create', 'payto', 'sendtx', 'password', 'newaddress', 'addresses', 'history', 'label', 'mktx','seed','import','signmessage','verifymessage','eval', 'gtk','qt'] usage = "usage: %prog [options] command args\nCommands: "+ (', '.join(known_commands)) @@ -44,23 +44,30 @@ if __name__ == '__main__': parser.add_option("-s", "--fromaddr", dest="from_addr", default=None, help="set source address for payto/mktx. if it isn't in the wallet, it will ask for the private key unless supplied in the format public_key:private_key. It's not saved in the wallet.") parser.add_option("-c", "--changeaddr", dest="change_addr", default=None, help="set the change address for payto/mktx. default is a spare address, or the source address if it's not in the wallet") options, args = parser.parse_args() - try: - cmd = args[0] - except: - cmd = "gui" - try: - firstarg = args[1] - except: - firstarg = '' interface = Interface() wallet = Wallet(interface) wallet.set_path(options.wallet_path) - if cmd == 'gui' or re.match('^bitcoin:', cmd): - import gui + cmd = args[0] if len(args) > 0 else 'gtk' + firstarg = args[1] if len(args) > 1 else '' + + + if cmd in ['gtk','qt'] or re.match('^bitcoin:', cmd): + if cmd == 'qt': + import gui_qt as gui + else: + import gui + interface.get_servers() - gui.init_wallet(wallet) + try: + found = wallet.read() + if not found: + gui.restore_create_dialog(wallet) + except BaseException, e: + show_message(e.message) + exit(1) + gui = gui.BitcoinGUI(wallet) interface.start(wallet) @@ -213,7 +220,7 @@ if __name__ == '__main__': print "show the transaction history" elif cmd2 == 'label': print "assign a label to an item" - elif cmd2 == 'gui': + elif cmd2 == 'gtk': print "start the GUI" elif cmd2 == 'mktx': print "create a signed transaction. password protected" diff --git a/client/gui.py b/client/gui.py index 1d1ed04ae..92729b1c6 100644 --- a/client/gui.py +++ b/client/gui.py @@ -74,81 +74,74 @@ def show_seed_dialog(wallet, password, parent): dialog.run() dialog.destroy() -def init_wallet(wallet): +def restore_create_dialog(wallet): - try: - found = wallet.read() - except BaseException, e: - show_message(e.message) - exit(1) - - if not found: - # ask if the user wants to create a new wallet, or recover from a seed. - # if he wants to recover, and nothing is found, do not create wallet - dialog = gtk.Dialog("electrum", parent=None, - flags=gtk.DIALOG_MODAL|gtk.DIALOG_NO_SEPARATOR, - buttons= ("create", 0, "restore",1, "cancel",2) ) + # ask if the user wants to create a new wallet, or recover from a seed. + # if he wants to recover, and nothing is found, do not create wallet + dialog = gtk.Dialog("electrum", parent=None, + flags=gtk.DIALOG_MODAL|gtk.DIALOG_NO_SEPARATOR, + buttons= ("create", 0, "restore",1, "cancel",2) ) - label = gtk.Label("Wallet file not found.\nDo you want to create a new wallet,\n or to restore an existing one?" ) - label.show() - dialog.vbox.pack_start(label) - dialog.show() - r = dialog.run() - dialog.destroy() - if r==2: - sys.exit(1) + label = gtk.Label("Wallet file not found.\nDo you want to create a new wallet,\n or to restore an existing one?" ) + label.show() + dialog.vbox.pack_start(label) + dialog.show() + r = dialog.run() + dialog.destroy() + if r==2: + sys.exit(1) - is_recovery = (r==1) + is_recovery = (r==1) - if not is_recovery: + if not is_recovery: - wallet.new_seed(None) + wallet.new_seed(None) + + # ask for the server. + run_network_dialog( wallet, parent=None ) + + # generate first key + wallet.synchronize() - # ask for the server. - run_network_dialog( wallet, parent=None ) + # run a dialog indicating the seed, ask the user to remember it + show_seed_dialog(wallet, None, None) + + #ask for password + change_password_dialog(wallet, None, None) + + else: + # ask for the server. + run_network_dialog( wallet, parent=None ) + + # ask for seed and gap. + run_recovery_dialog( wallet ) + + dialog = gtk.MessageDialog( + parent = None, + flags = gtk.DIALOG_MODAL, + buttons = gtk.BUTTONS_CANCEL, + message_format = "Please wait..." ) + dialog.show() - # generate first key + def recover_thread( wallet, dialog ): + wallet.init_mpk( wallet.seed ) # not encrypted at this point wallet.synchronize() - # run a dialog indicating the seed, ask the user to remember it - show_seed_dialog(wallet, None, None) - - #ask for password - change_password_dialog(wallet, None, None) + if wallet.is_found(): + # history and addressbook + wallet.update_tx_history() + wallet.fill_addressbook() + print "recovery successful" + wallet.save() - else: - # ask for the server. - run_network_dialog( wallet, parent=None ) - - # ask for seed and gap. - run_recovery_dialog( wallet ) - - dialog = gtk.MessageDialog( - parent = None, - flags = gtk.DIALOG_MODAL, - buttons = gtk.BUTTONS_CANCEL, - message_format = "Please wait..." ) - dialog.show() - - def recover_thread( wallet, dialog ): - wallet.init_mpk( wallet.seed ) # not encrypted at this point - wallet.synchronize() - - if wallet.is_found(): - # history and addressbook - wallet.update_tx_history() - wallet.fill_addressbook() - print "recovery successful" - wallet.save() - - gobject.idle_add( dialog.destroy ) - - thread.start_new_thread( recover_thread, ( wallet, dialog ) ) - r = dialog.run() - dialog.destroy() - if r==gtk.RESPONSE_CANCEL: sys.exit(1) - if not wallet.is_found: - show_message("No transactions found for this seed") + gobject.idle_add( dialog.destroy ) + + thread.start_new_thread( recover_thread, ( wallet, dialog ) ) + r = dialog.run() + dialog.destroy() + if r==gtk.RESPONSE_CANCEL: sys.exit(1) + if not wallet.is_found: + show_message("No transactions found for this seed") def run_recovery_dialog(wallet): diff --git a/client/gui_qt.py b/client/gui_qt.py new file mode 100644 index 000000000..89a1b6b83 --- /dev/null +++ b/client/gui_qt.py @@ -0,0 +1,42 @@ +import sys + +from PyQt4.QtGui import * +import PyQt4.QtCore as QtCore + +def restore_create_dialog(wallet): + pass + + +class BitcoinWidget(QWidget): + + def __init__(self, wallet): + super(BitcoinWidget, self).__init__() + self.wallet = wallet + self.initUI() + + def initUI(self): + qbtn = QPushButton('Quit', self) + qbtn.clicked.connect(QtCore.QCoreApplication.instance().quit) + qbtn.resize(qbtn.sizeHint()) + qbtn.move(50, 50) + + self.setGeometry(300, 300, 250, 150) + self.setWindowTitle( 'Electrum ' + self.wallet.electrum_version ) + self.show() + +class BitcoinGUI(): + + def __init__(self, wallet): + self.wallet = wallet + + def main(self): + + app = QApplication(sys.argv) + w = BitcoinWidget(self.wallet) + app.exec_() + + + + + +