URI: 
       tmove start_session into wallet methods. replace get_servers with network dialog - electrum - Electrum Bitcoin wallet
  HTML git clone https://git.parazyd.org/electrum
   DIR Log
   DIR Files
   DIR Refs
   DIR Submodules
       ---
   DIR commit 505c1a388799f6072234c96d4d1f1e039df82f92
   DIR parent 6c55410820038538626fc5adbc1afa7836131f1a
  HTML Author: thomasv <thomasv@gitorious>
       Date:   Wed,  2 May 2012 14:21:58 +0200
       
       move start_session into wallet methods. replace get_servers with network dialog
       
       Diffstat:
         M gui_qt.py                           |      57 +++++++++++++++++--------------
         M interface.py                        |      43 +++++--------------------------
         M wallet.py                           |      14 ++++++++++++++
       
       3 files changed, 52 insertions(+), 62 deletions(-)
       ---
   DIR diff --git a/gui_qt.py b/gui_qt.py
       t@@ -920,8 +920,17 @@ class ElectrumWindow(QMainWindow):
                    status = "Please choose a server."
                    server = random.choice( DEFAULT_SERVERS )
        
       +        if not wallet.interface.servers:
       +            servers_list = []
       +            from interface import DEFAULT_SERVERS
       +            for x in DEFAULT_SERVERS:
       +                h,port,protocol = x.split(':')
       +                servers_list.append( (h,[(protocol,port)] ) )
       +        else:
       +            servers_list = wallet.interface.servers
       +            
                plist = {}
       -        for item in wallet.interface.servers:
       +        for item in servers_list:
                    host, pp = item
                    z = {}
                    for item2 in pp:
       t@@ -988,31 +997,29 @@ class ElectrumWindow(QMainWindow):
                vbox.addLayout(hbox)
        
                if wallet.interface.servers:
       -            servers_list = QTreeWidget(parent)
       -            servers_list.setHeaderLabels( [ 'Active servers'] )
       -            servers_list.setMaximumHeight(150)
       -            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)
       +            label = 'Active Servers'
                else:
       -            hbox = QHBoxLayout()
       -            hbox.addWidget(QLabel('No nodes available'))
       -            b = EnterButton("Find nodes", lambda: wallet.interface.get_servers(wallet) )
       -            hbox.addWidget(b)
       -            vbox.addLayout(hbox)
       +            label = 'Default Servers'
       +        
       +        servers_list_widget = QTreeWidget(parent)
       +        servers_list_widget.setHeaderLabels( [ label ] )
       +        servers_list_widget.setMaximumHeight(150)
       +        for host in plist.keys():
       +            servers_list_widget.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_widget.connect(servers_list_widget, SIGNAL('itemClicked(QTreeWidgetItem*, int)'), do_set_line)
       +        vbox.addWidget(servers_list_widget)
        
                vbox.addLayout(ok_cancel_buttons(d))
                d.setLayout(vbox) 
   DIR diff --git a/interface.py b/interface.py
       t@@ -20,6 +20,8 @@
        import random, socket, ast, re
        import threading, traceback, sys, time, json, Queue
        
       +from version import ELECTRUM_VERSION
       +
        DEFAULT_TIMEOUT = 5
        DEFAULT_SERVERS = [ 'ecdsa.org:50001:t', 'electrum.novit.ro:50001:t', 'electrum.bitcoins.sk:50001:t']  # list of default servers
        
       t@@ -93,31 +95,6 @@ class Interface(threading.Thread):
                self.send(messages)
        
        
       -    def get_servers(self, wallet):
       -        # loop over default servers
       -        # requesting servers could be an independent process
       -        addresses = wallet.all_addresses()
       -        version = wallet.electrum_version
       -
       -        for server in DEFAULT_SERVERS:
       -            print "connecting to", server
       -            try:
       -                self.host = server
       -                self.start_session(addresses, version)
       -                wallet.host = self.host
       -                break
       -            except socket.timeout:
       -                continue
       -            except socket.error:
       -                continue
       -            except:
       -                traceback.print_exc(file=sys.stdout)
       -
       -
       -    def start_session(self, addresses, version):
       -        #print "Starting new session: %s:%d"%(self.host,self.port)
       -        self.send([('server.version', [version]), ('server.banner',[]), ('blockchain.numblocks.subscribe',[]), ('server.peers.subscribe',[])])
       -        self.subscribe(addresses)
        
        
        class PollingInterface(Interface):
       t@@ -240,6 +217,7 @@ class TcpStratumInterface(Interface):
                try:
                    self.s.connect(( self.host, self.port))
                    self.is_connected = True
       +            self.send([('server.version', [ELECTRUM_VERSION])])
                except:
                    self.is_connected = False
                    print "not connected"
       t@@ -367,21 +345,12 @@ class WalletSynchronizer(threading.Thread):
                    InterfaceClass = TcpStratumInterface
        
                self.interface = InterfaceClass(host, port)
       +        self.interface.start()
                self.wallet.interface = self.interface
        
       -        with self.wallet.lock:
       -            self.wallet.addresses_waiting_for_status = []
       -            self.wallet.addresses_waiting_for_history = []
       -            addresses = self.wallet.all_addresses()
       -            version = self.wallet.electrum_version
       -            for addr in addresses:
       -                self.wallet.addresses_waiting_for_status.append(addr)
       +        if self.interface.is_connected:
       +            self.wallet.start_session(self.interface)
        
       -        try:
       -            self.interface.start()
       -            self.interface.start_session(addresses,version)
       -        except:
       -            self.interface.is_connected = False
        
        
            def run(self):
   DIR diff --git a/wallet.py b/wallet.py
       t@@ -947,4 +947,18 @@ class Wallet:
                self.up_to_date_event.wait()
        
        
       +    def start_session(self, interface):
       +        self.interface = interface
       +        with self.lock:
       +            self.addresses_waiting_for_status = []
       +            self.addresses_waiting_for_history = []
       +            addresses = self.all_addresses()
       +            for addr in addresses:
       +                self.addresses_waiting_for_status.append(addr)
       +
       +        self.interface.send([('server.banner',[]), ('blockchain.numblocks.subscribe',[]), ('server.peers.subscribe',[])])
       +        self.interface.subscribe(addresses)
       +
       +
       +