relocate export_history code
authorThomasV <thomasv@gitorious>
Fri, 18 Apr 2014 08:04:25 +0000 (10:04 +0200)
committerThomasV <thomasv@gitorious>
Fri, 18 Apr 2014 08:04:25 +0000 (10:04 +0200)
gui/qt/lite_window.py
gui/qt/main_window.py

index e2d5678..f86c0a0 100644 (file)
@@ -27,7 +27,6 @@ import webbrowser
 import history_widget
 import receiving_widget
 from electrum import util
-import csv
 import datetime
 
 from electrum.version import ELECTRUM_VERSION as electrum_version
@@ -83,51 +82,6 @@ def load_theme_paths():
     return theme_paths
 
 
-def csv_transaction(wallet):
-    try:
-        select_export = _('Select file to export your wallet transactions to')
-        fileName = QFileDialog.getSaveFileName(QWidget(), select_export, os.path.expanduser('~/electrum-history.csv'), "*.csv")
-        if fileName:
-            with open(fileName, "w+") as csvfile:
-                transaction = csv.writer(csvfile)
-                transaction.writerow(["transaction_hash","label", "confirmations", "value", "fee", "balance", "timestamp"])
-                for item in wallet.get_tx_history():
-                    tx_hash, confirmations, is_mine, value, fee, balance, timestamp = item
-                    if confirmations:
-                        if timestamp is not None:
-                            try:
-                                time_string = datetime.datetime.fromtimestamp(timestamp).isoformat(' ')[:-3]
-                            except [RuntimeError, TypeError, NameError] as reason:
-                                time_string = "unknown"
-                                pass
-                        else:
-                          time_string = "unknown"
-                    else:
-                        time_string = "pending"
-
-                    if value is not None:
-                        value_string = format_satoshis(value, True)
-                    else:
-                        value_string = '--'
-
-                    if fee is not None:
-                        fee_string = format_satoshis(fee, True)
-                    else:
-                        fee_string = '0'
-
-                    if tx_hash:
-                        label, is_default_label = wallet.get_label(tx_hash)
-                        label = label.encode('utf-8')
-                    else:
-                      label = ""
-
-                    balance_string = format_satoshis(balance, False)
-                    transaction.writerow([tx_hash, label, confirmations, value_string, fee_string, balance_string, time_string])
-                QMessageBox.information(None,_("CSV Export created"), _("Your CSV export has been successfully created."))
-    except (IOError, os.error), reason:
-        export_error_label = _("Electrum was unable to produce a transaction export.")
-        QMessageBox.critical(None,_("Unable to create csv"), export_error_label + "\n" + str(reason))
-
 
 
 class TransactionWindow(QDialog):
index 6f8bd7c..c4da354 100644 (file)
@@ -2072,8 +2072,54 @@ class ElectrumWindow(QMainWindow):
 
 
     def do_export_history(self):
-        from lite_window import csv_transaction
-        csv_transaction(self.wallet)
+        wallet = self.wallet
+        select_export = _('Select file to export your wallet transactions to')
+        fileName = QFileDialog.getSaveFileName(QWidget(), select_export, os.path.expanduser('~/electrum-history.csv'), "*.csv")
+        if not fileName:
+            return
+
+        try:
+            with open(fileName, "w+") as csvfile:
+                transaction = csv.writer(csvfile)
+                transaction.writerow(["transaction_hash","label", "confirmations", "value", "fee", "balance", "timestamp"])
+                for item in wallet.get_tx_history():
+                    tx_hash, confirmations, is_mine, value, fee, balance, timestamp = item
+                    if confirmations:
+                        if timestamp is not None:
+                            try:
+                                time_string = datetime.datetime.fromtimestamp(timestamp).isoformat(' ')[:-3]
+                            except [RuntimeError, TypeError, NameError] as reason:
+                                time_string = "unknown"
+                                pass
+                        else:
+                          time_string = "unknown"
+                    else:
+                        time_string = "pending"
+
+                    if value is not None:
+                        value_string = format_satoshis(value, True)
+                    else:
+                        value_string = '--'
+
+                    if fee is not None:
+                        fee_string = format_satoshis(fee, True)
+                    else:
+                        fee_string = '0'
+
+                    if tx_hash:
+                        label, is_default_label = wallet.get_label(tx_hash)
+                        label = label.encode('utf-8')
+                    else:
+                      label = ""
+
+                    balance_string = format_satoshis(balance, False)
+                    transaction.writerow([tx_hash, label, confirmations, value_string, fee_string, balance_string, time_string])
+                QMessageBox.information(None,_("CSV Export created"), _("Your CSV export has been successfully created."))
+
+        except (IOError, os.error), reason:
+            export_error_label = _("Electrum was unable to produce a transaction export.")
+            QMessageBox.critical(None,_("Unable to create csv"), export_error_label + "\n" + str(reason))
+
 
 
     @protected