separate blockchain and network
[electrum-nvc.git] / gui / gui_classic.py
index 5269490..076f97d 100644 (file)
@@ -21,6 +21,7 @@ from i18n import _, set_language
 from electrum.util import print_error, print_msg
 import os.path, json, ast, traceback
 import shutil
+import StringIO
 
 
 try:
@@ -32,7 +33,7 @@ from PyQt4.QtGui import *
 from PyQt4.QtCore import *
 import PyQt4.QtCore as QtCore
 
-from electrum.bitcoin import MIN_RELAY_TX_FEE
+from electrum.bitcoin import MIN_RELAY_TX_FEE, is_valid
 
 try:
     import icons_rc
@@ -40,7 +41,7 @@ except:
     sys.exit("Error: Could not import icons_rc.py, please generate it with: 'pyrcc4 icons.qrc -o gui/icons_rc.py'")
 
 from electrum.wallet import format_satoshis
-from electrum.bitcoin import Transaction, is_valid
+from electrum import Transaction
 from electrum import mnemonic
 from electrum import util, bitcoin, commands, Interface, Wallet
 from electrum import SimpleConfig, Wallet, WalletStorage
@@ -178,6 +179,7 @@ class StatusBarButton(QPushButton):
         self.setMaximumWidth(25)
         self.clicked.connect(func)
         self.func = func
+        self.setIconSize(QSize(25,25))
 
     def keyPressEvent(self, e):
         if e.key() == QtCore.Qt.Key_Return:
@@ -316,7 +318,7 @@ class ElectrumWindow(QMainWindow):
         self.notify_transactions()
 
         # account selector
-        accounts = self.wallet.get_accounts()
+        accounts = self.wallet.get_account_names()
         self.account_selector.clear()
         if len(accounts) > 1:
             self.account_selector.addItems([_("All accounts")] + accounts.values())
@@ -413,6 +415,14 @@ class ElectrumWindow(QMainWindow):
         raw_transaction_text = raw_transaction_menu.addAction(_("&From text"))
         raw_transaction_text.triggered.connect(self.do_process_from_text)
 
+        csv_transaction_menu = wallet_menu.addMenu(_("&Load CSV transaction"))
+
+        csv_transaction_file = csv_transaction_menu.addAction(_("&From file"))
+        csv_transaction_file.triggered.connect(self.do_process_from_csv_file)
+
+        csv_transaction_text = csv_transaction_menu.addAction(_("&From text"))
+        csv_transaction_text.triggered.connect(self.do_process_from_csv_text)
+
         wallet_menu.addSeparator()
 
         show_menu = wallet_menu.addMenu(_("Show"))
@@ -558,8 +568,6 @@ class ElectrumWindow(QMainWindow):
             self.config.set_key('io_dir', os.path.dirname(fileName), True)
         return fileName
 
-
-
     def close(self):
         QMainWindow.close(self)
         self.run_hook('close_main_window')
@@ -1013,6 +1021,10 @@ class ElectrumWindow(QMainWindow):
             except:
                 QMessageBox.warning(self, _('Error'), _('Could not write transaction to file'), _('OK'))
 
+        # add recipient to addressbook
+        if to_address not in self.wallet.addressbook and not self.wallet.is_mine(to_address):
+            self.wallet.addressbook.append(to_address)
+
 
 
 
@@ -1272,7 +1284,7 @@ class ElectrumWindow(QMainWindow):
             account_items = []
 
         for k, account in account_items:
-            name = self.wallet.labels.get(k, 'unnamed account')
+            name = self.wallet.get_account_name(k)
             c,u = self.wallet.get_account_balance(k)
             account_item = QTreeWidgetItem( [ name, '', self.format_amount(c+u), ''] )
             l.addTopLevelItem(account_item)
@@ -1353,7 +1365,7 @@ class ElectrumWindow(QMainWindow):
         console.history = self.config.get("console-history",[])
         console.history_index = len(console.history)
 
-        console.updateNamespace({'wallet' : self.wallet, 'interface' : self.wallet.interface, 'gui':self})
+        console.updateNamespace({'wallet' : self.wallet, 'network' : self.wallet.network, 'gui':self})
         console.updateNamespace({'util' : util, 'bitcoin':bitcoin})
 
         c = commands.Commands(self.wallet, self.wallet.interface, lambda: self.console.set_json(True))
@@ -1371,7 +1383,7 @@ class ElectrumWindow(QMainWindow):
         if s == _("All accounts"):
             self.current_account = None
         else:
-            accounts = self.wallet.get_accounts()
+            accounts = self.wallet.get_account_names()
             for k, v in accounts.items():
                 if v == s:
                     self.current_account = k
@@ -1444,7 +1456,7 @@ class ElectrumWindow(QMainWindow):
         if self.lite:
             self.lite.mini.show()
         else:
-            self.lite = gui_lite.ElectrumGui(self.wallet, self.config, self)
+            self.lite = gui_lite.ElectrumGui(self.config, None, None, self)
             self.lite.main(None)
 
 
@@ -1823,6 +1835,47 @@ class ElectrumWindow(QMainWindow):
         if tx_dict: 
             self.create_process_transaction_window(tx_dict)
 
+    def do_process_from_csvReader(self, csvReader):
+        outputs = []
+        try:
+            for row in csvReader:
+                address = row[0]
+                amount = float(row[1])
+                amount = int(100000000*amount)
+                outputs.append((address, amount))
+        except (ValueError, IOError, os.error), reason:
+            QMessageBox.critical(None,"Unable to read file or no transaction found", _("Electrum was unable to open your transaction file") + "\n" + str(reason))
+            return
+
+        try:
+            tx = self.wallet.make_unsigned_transaction(outputs, None, None, account=self.current_account)
+        except BaseException, e:
+            self.show_message(str(e))
+            return
+
+        tx_dict = tx.as_dict()
+        self.create_process_transaction_window(tx_dict)
+
+    def do_process_from_csv_file(self):
+        fileName = self.getOpenFileName(_("Select your transaction CSV"), "*.csv")
+        if not fileName:
+            return
+        try:
+            with open(fileName, "r") as f:
+                csvReader = csv.reader(f)
+                self.do_process_from_csvReader(csvReader)
+        except (ValueError, IOError, os.error), reason:
+            QMessageBox.critical(None,"Unable to read file or no transaction found", _("Electrum was unable to open your transaction file") + "\n" + str(reason))
+            return
+
+    def do_process_from_csv_text(self):
+        text = text_dialog(self, _('Input CSV'), _("CSV:"), _("Load CSV"))
+        if not text:
+            return
+        f = StringIO.StringIO(text)
+        csvReader = csv.reader(f)
+        self.do_process_from_csvReader(csvReader)
+
     def create_process_transaction_window(self, tx_dict):
         tx = Transaction(tx_dict["hex"])
             
@@ -2203,10 +2256,11 @@ class OpenFileEventFilter(QObject):
 
 class ElectrumGui:
 
-    def __init__(self, config, interface, blockchain, app=None):
-        self.interface = interface
+    def __init__(self, config, network, app=None):
+        self.network = network
+        #self.interface = interface
         self.config = config
-        self.blockchain = blockchain
+        #self.blockchain = network.blockchain
         self.windows = []
         self.efilter = OpenFileEventFilter(self.windows)
         if app is None:
@@ -2226,7 +2280,7 @@ class ElectrumGui:
         else:
             wallet = Wallet(storage)
 
-        wallet.start_threads(self.interface, self.blockchain)
+        wallet.start_threads(self.network)
 
         s = Timer()
         s.start()