From d2099d94e5b3ac3be5a8e09566189bb04317a8b6 Mon Sep 17 00:00:00 2001 From: thomasv Date: Wed, 4 Sep 2013 10:57:15 +0200 Subject: [PATCH] manual merge: tc scv import by harningt --- gui/gui_classic.py | 50 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 50 insertions(+) diff --git a/gui/gui_classic.py b/gui/gui_classic.py index 243434801..83b0c3235 100644 --- a/gui/gui_classic.py +++ b/gui/gui_classic.py @@ -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: @@ -413,6 +414,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")) @@ -1827,6 +1836,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"])