electrum

Electrum Bitcoin wallet
git clone https://git.parazyd.org/electrum
Log | Files | Refs | Submodules

commit a579e1555e1b3fc33fc3aab98605d2ff008cfd0a
parent e05e0e971179a25881cd1272f63aa26391ea35ad
Author: ThomasV <thomasv@gitorious>
Date:   Sat, 31 Mar 2012 14:03:30 +0200

radio buttons for ports

Diffstat:
Mclient/gui_qt.py | 67++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++---
Mclient/interface.py | 8+++++---
Mclient/wallet.py | 5++++-
3 files changed, 73 insertions(+), 7 deletions(-)

diff --git a/client/gui_qt.py b/client/gui_qt.py @@ -849,6 +849,15 @@ class ElectrumWindow(QMainWindow): status = "Please choose a server." server = random.choice( interface.servers ) + plist = {} + for item in wallet.interface.servers: + host, pp = item + z = {} + for item2 in pp: + protocol, port = item2 + z[protocol] = port + plist[host] = z + d = QDialog(parent) d.setModal(1) d.setWindowTitle('Server') @@ -872,13 +881,65 @@ class ElectrumWindow(QMainWindow): hbox.addWidget(host_line) vbox.addLayout(hbox) + hbox = QHBoxLayout() + + buttonGroup = QGroupBox("protocol") + radio1 = QRadioButton("tcp", buttonGroup) + radio2 = QRadioButton("http", buttonGroup) + radio3 = QRadioButton("native", buttonGroup) + + def current_line(): + return unicode(host_line.text()).split(':') + + def set_button(protocol): + if protocol == 't': + radio1.setChecked(1) + elif protocol == 'h': + radio2.setChecked(1) + elif protocol == 'n': + radio3.setChecked(1) + + def set_protocol(protocol): + host = current_line()[0] + pp = plist[host] + if protocol not in pp.keys(): + protocol = pp.keys()[0] + set_button(protocol) + port = pp[protocol] + host_line.setText( host + ':' + port + ':' + protocol) + + radio1.clicked.connect(lambda x: set_protocol('t') ) + radio2.clicked.connect(lambda x: set_protocol('h') ) + radio3.clicked.connect(lambda x: set_protocol('n') ) + + set_button(current_line()[2]) + + hbox.addWidget(QLabel('Protocol:')) + hbox.addWidget(radio1) + hbox.addWidget(radio2) + hbox.addWidget(radio3) + + vbox.addLayout(hbox) + if wallet.interface.servers: servers_list = QTreeWidget(parent) servers_list.setHeaderLabels( [ 'Active servers'] ) servers_list.setMaximumHeight(150) - for item in wallet.interface.servers: - servers_list.addTopLevelItem(QTreeWidgetItem( [ item ] )) - servers_list.connect(servers_list, SIGNAL('itemClicked(QTreeWidgetItem*, int)'), lambda x:host_line.setText( x.text(0) )) + for host in plist.keys(): + servers_list.addTopLevelItem(QTreeWidgetItem( [ host ] )) + + def do_set_line(x): + host = unicode(x.text(0)) + pp = plist[host] + if 't' in pp.keys(): + protocol = 't' + else: + protocol = pp.keys()[0] + port = pp[protocol] + host_line.setText( host + ':' + port + ':' + protocol) + set_button(protocol) + + servers_list.connect(servers_list, SIGNAL('itemClicked(QTreeWidgetItem*, int)'), do_set_line) vbox.addWidget(servers_list) else: hbox = QHBoxLayout() diff --git a/client/interface.py b/client/interface.py @@ -21,7 +21,7 @@ import random, socket, ast, re import threading, traceback, sys, time, json, Queue DEFAULT_TIMEOUT = 5 -DEFAULT_SERVERS = ['ecdsa.org:50001:t'] # ['electrum.bitcoins.sk','ecdsa.org','electrum.novit.ro'] # list of default servers +DEFAULT_SERVERS = [ ('ecdsa.org', [('t','50001')]) ] # ['electrum.bitcoins.sk','ecdsa.org','electrum.novit.ro'] # list of default servers def old_to_new(s): @@ -371,15 +371,17 @@ class WalletSynchronizer(threading.Thread): for item in result: s = [] host = item[1] + ports = [] if len(item)>2: for v in item[2]: if re.match("[thn]\d+",v): - s.append(host+":"+v[1:]+":"+v[0]) + ports.append((v[0],v[1:])) #if not s: # s.append(host+":50000:n") #else: # s.append(host+":50000:n") - servers = servers + s + if ports: + servers.append( (host, ports) ) self.interface.servers = servers elif method == 'blockchain.address.subscribe': diff --git a/client/wallet.py b/client/wallet.py @@ -283,7 +283,9 @@ class Wallet: def pick_random_server(self): - self.server = random.choice( DEFAULT_SERVERS ) # random choice when the wallet is created + host, pp = random.choice( DEFAULT_SERVERS ) # random choice when the wallet is created + protocol, port = pp[0] + self.server = host + ':' + port + ':' + protocol def is_up_to_date(self): return self.interface.responses.empty() and not ( self.addresses_waiting_for_status or self.addresses_waiting_for_history ) @@ -292,6 +294,7 @@ class Wallet: def set_server(self, server): if server != self.server: self.server = server + self.save() self.interface.is_connected = False # this exits the polling loop def set_path(self, wallet_path):