fix get_pubkeys call
[electrum-nvc.git] / gui / text.py
index ce4a546..0c6a148 100644 (file)
@@ -22,7 +22,7 @@ class ElectrumGui:
             exit()
 
         self.wallet = Wallet(storage)
-        self.wallet.start_threads(network)
+        self.wallet.start_threads(self.network)
 
         locale.setlocale(locale.LC_ALL, '')
         self.encoding = locale.getpreferredencoding()
@@ -50,11 +50,13 @@ class ElectrumGui:
         self.str_amount = ""
         self.str_fee = ""
         self.history = None
-        
-        self.network.register_callback('updated', self.update)
-        self.network.register_callback('connected', self.refresh)
-        self.network.register_callback('disconnected', self.refresh)
-        self.network.register_callback('disconnecting', self.refresh)
+       
+        if self.network: 
+            self.network.register_callback('updated', self.update)
+            self.network.register_callback('connected', self.refresh)
+            self.network.register_callback('disconnected', self.refresh)
+            self.network.register_callback('disconnecting', self.refresh)
+
         self.tab_names = [_("History"), _("Send"), _("Receive"), _("Contacts"), _("Wall")]
         self.num_tabs = len(self.tab_names)
 
@@ -62,7 +64,7 @@ class ElectrumGui:
     def set_cursor(self, x):
         try:
             curses.curs_set(x)
-        except:
+        except Exception:
             pass
 
     def restore_or_create(self):
@@ -110,7 +112,7 @@ class ElectrumGui:
             if conf:
                 try:
                     time_str = datetime.datetime.fromtimestamp( timestamp).isoformat(' ')[:-3]
-                except:
+                except Exception:
                     time_str = "------"
             else:
                 time_str = 'pending'
@@ -120,15 +122,17 @@ class ElectrumGui:
 
 
     def print_balance(self):
-        if self.network.interface and self.network.interface.is_connected:
+        if not self.network:
+            msg = _("Offline")
+        elif self.network.interface and self.network.interface.is_connected:
             if not self.wallet.up_to_date:
-                msg = _( "Synchronizing..." )
+                msg = _("Synchronizing...")
             else: 
                 c, u =  self.wallet.get_balance()
                 msg = _("Balance")+": %f  "%(Decimal( c ) / 100000000)
                 if u: msg += "  [%f unconfirmed]"%(Decimal( u ) / 100000000)
         else:
-                msg = _( "Not connected" )
+            msg = _("Not connected")
             
         self.stdscr.addstr( self.maxy -1, 3, msg)
 
@@ -162,7 +166,8 @@ class ElectrumGui:
         self.stdscr.addstr( 12, 25, _("[Clear]"), curses.A_REVERSE if self.pos%6==5 else curses.color_pair(2))
 
     def print_banner(self):
-        self.print_list( self.network.banner.split('\n'))
+        if self.network:
+            self.print_list( self.network.banner.split('\n'))
 
     def print_list(self, list, firstline = None):
         self.maxpos = len(list)
@@ -286,12 +291,12 @@ class ElectrumGui:
             return
         try:
             amount = int( Decimal( self.str_amount) * 100000000 )
-        except:
+        except Exception:
             self.show_message(_('Invalid Amount'))
             return
         try:
             fee = int( Decimal( self.str_fee) * 100000000 )
-        except:
+        except Exception:
             self.show_message(_('Invalid Fee'))
             return
 
@@ -304,7 +309,7 @@ class ElectrumGui:
 
         try:
             tx = self.wallet.mktx( [(self.str_recipient, amount)], password, fee)
-        except BaseException, e:
+        except Exception as e:
             self.show_message(str(e))
             return
             
@@ -314,7 +319,7 @@ class ElectrumGui:
         h = self.wallet.send_tx(tx)
         self.show_message(_("Please wait..."), getchar=False)
         self.wallet.tx_event.wait()
-        status, msg = self.wallet.receive_tx( h )
+        status, msg = self.wallet.receive_tx( h, tx )
 
         if status:
             self.show_message(_('Payment sent.'))
@@ -339,6 +344,7 @@ class ElectrumGui:
 
 
     def network_dialog(self):
+        if not self.network: return
         auto_connect = self.network.config.get('auto_cycle')
         host, port, protocol = self.network.default_server.split(':')
         srv = 'auto-connect' if auto_connect else self.network.default_server
@@ -354,7 +360,7 @@ class ElectrumGui:
                 if not auto_connect:
                     try:
                         host, port, protocol = server.split(':')
-                    except:
+                    except Exception:
                         self.show_message("Error:" + server + "\nIn doubt, type \"auto-connect\"")
                         return False
 
@@ -462,7 +468,7 @@ class ElectrumGui:
                     choices = item.get('choices')
                     try:
                         j = choices.index(item.get('value'))
-                    except:
+                    except Exception:
                         j = 0
                     new_choice = choices[(j + 1)% len(choices)]
                     item['value'] = new_choice