commit a7345418bef5b108cb46d3fd9b09c807dacccc69
parent 0a36a557cccc369897745ba672ffa99eccf1ee2a
Author: thomasv <thomasv@gitorious>
Date: Mon, 13 Feb 2012 15:44:16 +0100
network dialog
Diffstat:
3 files changed, 70 insertions(+), 6 deletions(-)
diff --git a/client/gui.py b/client/gui.py
@@ -354,12 +354,9 @@ def run_network_dialog( wallet, parent ):
else:
return
- if host!= wallet.interface.host or port!=wallet.interface.port:
- wallet.interface.host = host
- wallet.interface.set_port( port )
- wallet.interface.is_connected = False
- if parent:
- wallet.save()
+ wallet.interface.set_server(host, port)
+ if parent:
+ wallet.save()
diff --git a/client/gui_qt.py b/client/gui_qt.py
@@ -376,6 +376,7 @@ class ElectrumWindow(QMainWindow):
b.setToolTip("Network")
b.setFlat(True)
b.setMaximumWidth(25)
+ b.clicked.connect(self.network_dialog)
hbox.addWidget(b)
sb.addPermanentWidget(buttons)
@@ -537,6 +538,66 @@ class ElectrumWindow(QMainWindow):
self.wallet.fee = fee
self.wallet.save()
+ def network_dialog(self, parent=True):
+ wallet = self.wallet
+ if parent:
+ if wallet.interface.is_connected:
+ status = "Connected to %s.\n%d blocks\nresponse time: %f"%(wallet.interface.host, wallet.interface.blocks, wallet.interface.rtime)
+ else:
+ status = "Not connected"
+ host = wallet.interface.host
+ port = wallet.interface.port
+ else:
+ import random
+ status = "Please choose a server."
+ host = random.choice( wallet.interface.servers )
+ port = 50000
+
+ d = QDialog(self)
+ d.setModal(1)
+
+ grid = QGridLayout()
+ grid.setSpacing(8)
+ grid.addWidget(QLabel(status), 0, 0, 1, 2)
+
+ host_line = QLineEdit()
+ host_line.setText("%s:%d"% (host,port) )
+ grid.addWidget(QLabel('Server'), 2, 0)
+ grid.addWidget(host_line, 2, 1)
+
+ b = QPushButton("Cancel")
+ grid.addWidget(b, 5, 1)
+ b.clicked.connect(d.reject)
+
+ b = QPushButton("OK")
+ grid.addWidget(b, 5, 2)
+ b.clicked.connect(d.accept)
+
+ d.setLayout(grid)
+
+ if not d.exec_(): return
+ hh = str( host_line.text() )
+
+ try:
+ if ':' in hh:
+ host, port = hh.split(':')
+ port = int(port)
+ else:
+ host = hh
+ port = 50000
+ except:
+ show_message("error")
+ if parent == None:
+ sys.exit(1)
+ else:
+ return
+
+ wallet.interface.set_server(host, port)
+
+ if parent:
+ wallet.save()
+
+
class BitcoinGUI():
diff --git a/client/interface.py b/client/interface.py
@@ -201,3 +201,9 @@ class Interface:
def get_servers(self):
thread.start_new_thread(self.update_servers_thread, ())
+
+ def set_server(self, host, port):
+ if host!= self.host or port!=self.port:
+ self.host = host
+ self.set_port( port )
+ self.is_connected = False