add switch-gui button for qt
[electrum-nvc.git] / lib / gui_lite.py
index 1cfec05..dbf9291 100644 (file)
@@ -31,6 +31,7 @@ import util
 import csv 
 import datetime
 
+from version import ELECTRUM_VERSION as electrum_version
 from wallet import format_satoshis
 import gui_qt
 import shutil
@@ -85,16 +86,62 @@ def load_theme_paths():
     return theme_paths
 
 
+def csv_transaction(wallet):
+    try:
+        fileName = QFileDialog.getSaveFileName(QWidget(), 'Select file to export your wallet transactions to', os.path.expanduser('~/'), "*.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, wallet.num_zeros)
+                    else:
+                        value_string = '--'
+
+                    if fee is not None:
+                        fee_string = format_satoshis(fee, True, wallet.num_zeros)
+                    else:
+                        fee_string = '0'
+
+                    if tx_hash:
+                        label, is_default_label = wallet.get_label(tx_hash)
+                    else:
+                      label = ""
+
+                    balance_string = format_satoshis(balance, False, wallet.num_zeros)
+                    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 succesfully created.")
+    except (IOError, os.error), reason:
+        QMessageBox.critical(None,"Unable to create csv", "Electrum was unable to produce a transaction export.\n" + str(reason))
+
+
 class ElectrumGui(QObject):
 
-    def __init__(self, wallet, config):
+    def __init__(self, wallet, config, expert=None):
         super(QObject, self).__init__()
 
         self.wallet = wallet
         self.config = config
         self.check_qt_version()
-        self.app = QApplication(sys.argv)
-
+        self.expert = expert
+        if self.expert != None:
+            self.app = self.expert.app
+        else:
+            self.app = QApplication(sys.argv)
 
     def check_qt_version(self):
         qtVersion = qVersion()
@@ -121,14 +168,15 @@ class ElectrumGui(QObject):
 
         if url:
             self.set_url(url)
-
-        timer = Timer()
-        timer.start()
-        self.expert = gui_qt.ElectrumWindow(self.wallet, self.config)
-        self.expert.app = self.app
-        self.expert.connect_slots(timer)
-        self.expert.update_wallet()
-        self.app.exec_()
+            
+        if self.expert == None:
+            timer = Timer()
+            timer.start()
+            self.expert = gui_qt.ElectrumWindow(self.wallet, self.config)
+            self.expert.app = self.app
+            self.expert.connect_slots(timer)
+            self.expert.update_wallet()
+            self.app.exec_()
 
     def expand(self):
         """Hide the lite mode window and show pro-mode."""
@@ -153,16 +201,50 @@ class ElectrumGui(QObject):
         qt_gui_object = gui_qt.ElectrumGui(self.wallet, self.app)
         return qt_gui_object.restore_or_create()
 
+class TransactionWindow(QDialog):
+
+    def set_label(self):
+        label = unicode(self.label_edit.text())
+        self.parent.wallet.labels[self.tx_id] = label
+
+        super(TransactionWindow, self).accept() 
+
+    def __init__(self, transaction_id, parent):
+        super(TransactionWindow, self).__init__()
+
+        self.tx_id = str(transaction_id)
+        self.parent = parent
+
+        self.setModal(True)
+        self.resize(200,100)
+        self.setWindowTitle("Transaction successfully sent")
+
+        self.layout = QGridLayout(self)
+        self.layout.addWidget(QLabel("Your transaction has been sent.\nPlease enter a label for this transaction for future reference."))
+
+        self.label_edit = QLineEdit()
+        self.label_edit.setPlaceholderText(_("Transaction label"))
+        self.label_edit.setObjectName("label_input")
+        self.label_edit.setAttribute(Qt.WA_MacShowFocusRect, 0)
+        self.label_edit.setFocusPolicy(Qt.ClickFocus)
+        self.layout.addWidget(self.label_edit)
+
+        self.save_button = QPushButton(_("Save"))
+        self.layout.addWidget(self.save_button)
+        self.save_button.clicked.connect(self.set_label)
+
+        self.exec_()
+
 class MiniWindow(QDialog):
 
     def __init__(self, actuator, expand_callback, config):
         super(MiniWindow, self).__init__()
+        tx = "e08115d0f7819aee65b9d24f81ef9d46eb62bb67ddef5318156cbc3ceb7b703e"
 
         self.actuator = actuator
         self.config = config
-
         self.btc_balance = None
-        self.quote_currencies = ["EUR", "USD", "GBP"]
+        self.quote_currencies = ["BRL", "CNY", "EUR", "GBP", "RUB", "USD"]
         self.actuator.set_configured_currency(self.set_quote_currency)
         self.exchanger = exchange_rate.Exchanger(self)
         # Needed because price discovery is done in a different thread
@@ -175,11 +257,12 @@ class MiniWindow(QDialog):
 
         # Bitcoin address code
         self.address_input = QLineEdit()
-        self.address_input.setPlaceholderText(_("Enter a Bitcoin address..."))
+        self.address_input.setPlaceholderText(_("Enter a Bitcoin address or contact"))
         self.address_input.setObjectName("address_input")
 
+        self.address_input.setFocusPolicy(Qt.ClickFocus)
 
-        self.address_input.textEdited.connect(self.address_field_changed)
+        self.address_input.textChanged.connect(self.address_field_changed)
         resize_line_edit_width(self.address_input,
                                "1BtaFUr3qVvAmwrsuDuu5zk6e4s2rxd2Gy")
 
@@ -195,6 +278,8 @@ class MiniWindow(QDialog):
         self.amount_input = QLineEdit()
         self.amount_input.setPlaceholderText(_("... and amount"))
         self.amount_input.setObjectName("amount_input")
+
+        self.amount_input.setFocusPolicy(Qt.ClickFocus)
         # This is changed according to the user's displayed balance
         self.amount_validator = QDoubleValidator(self.amount_input)
         self.amount_validator.setNotation(QDoubleValidator.StandardNotation)
@@ -280,7 +365,7 @@ class MiniWindow(QDialog):
         backup_wallet.triggered.connect(self.backup_wallet)
 
         export_csv = extra_menu.addAction( _("&Export transactions to CSV") )
-        export_csv.triggered.connect(self.actuator.csv_transaction)
+        export_csv.triggered.connect(lambda: csv_transaction(self.wallet))
         
         master_key = extra_menu.addAction( _("Copy master public key to clipboard") ) 
         master_key.triggered.connect(self.actuator.copy_master_public_key)
@@ -410,7 +495,7 @@ class MiniWindow(QDialog):
             quote_text = "(%s)" % quote_text
         btc_balance = "%.2f" % (btc_balance / bitcoin(1))
         self.balance_label.set_balance_text(btc_balance, quote_text)
-        self.setWindowTitle("Electrum - %s BTC" % btc_balance)
+        self.setWindowTitle("Electrum %s - %s BTC" % (electrum_version, btc_balance))
 
     def amount_input_changed(self, amount_text):
         """Update the number of bitcoins displayed."""
@@ -462,6 +547,13 @@ class MiniWindow(QDialog):
             self.send_button.setDisabled(True)
 
     def address_field_changed(self, address):
+        # label or alias, with address in brackets
+        match2 = re.match("(.*?)\s*\<([1-9A-HJ-NP-Za-km-z]{26,})\>",
+                          address)
+        if match2:
+          address = match2.group(2)
+          self.address_input.setText(address)
+
         if self.actuator.is_valid(address):
             self.check_button_status()
             self.address_input.setProperty("isValid", True)
@@ -507,11 +599,11 @@ class MiniWindow(QDialog):
 
     def show_about(self):
         QMessageBox.about(self, "Electrum",
-            _("Electrum's focus is speed, with low resource usage and simplifying Bitcoin. You do not need to perform regular backups, because your wallet can be recovered from a secret phrase that you can memorize or write on paper. Startup times are instant because it operates in conjuction with high-performance servers that handle the most complicated parts of the Bitcoin system.\n\nSend donations to 1JwTMv4GWaPdf931N6LNPJeZBfZgZJ3zX1"))
+            _("Electrum's focus is speed, with low resource usage and simplifying Bitcoin. You do not need to perform regular backups, because your wallet can be recovered from a secret phrase that you can memorize or write on paper. Startup times are instant because it operates in conjuction with high-performance servers that handle the most complicated parts of the Bitcoin system."))
 
     def show_report_bug(self):
         QMessageBox.information(self, "Electrum - " + _("Reporting Bugs"),
-            _("Email bug reports to %s") % "genjix" + "@" + "riseup.net")
+            _("Please report any bugs as issues on github: <a href=\"https://github.com/spesmilo/electrum/issues\">https://github.com/spesmilo/electrum/issues</a>"))
 
     def show_history(self, toggle_state):
         if toggle_state:
@@ -724,47 +816,6 @@ class MiniActuator:
         w.exec_()
         w.destroy()
 
-    def csv_transaction(self):
-        try:
-          fileName = QFileDialog.getSaveFileName(QWidget(), 'Select file to export your wallet transactions to', os.path.expanduser('~/'), "*.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 self.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, self.wallet.num_zeros)
-                    else:
-                        value_string = '--'
-
-                    if fee is not None:
-                        fee_string = format_satoshis(fee, True, self.wallet.num_zeros)
-                    else:
-                        fee_string = '0'
-
-                    if tx_hash:
-                        label, is_default_label = self.wallet.get_label(tx_hash)
-                    else:
-                      label = ""
-
-                    balance_string = format_satoshis(balance, False, self.wallet.num_zeros)
-                    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 succesfully created.")
-        except (IOError, os.error), reason:
-          QMessageBox.critical(None,"Unable to create csv", "Electrum was unable to produce a transaction export.\n" + str(reason))
 
     def send(self, address, amount, parent_window):
         """Send bitcoins to the target address."""
@@ -813,9 +864,10 @@ class MiniActuator:
             print "Dumped error tx to", dumpf.name
             QMessageBox.warning(parent_window, _('Error'), message, _('OK'))
             return False
-
-        QMessageBox.information(parent_window, '',
-            _('Your transaction has been sent.') + '\n' + message, _('OK'))
+      
+        TransactionWindow(message, self)
+#        QMessageBox.information(parent_window, '',
+#            _('Your transaction has been sent.') + '\n' + message, _('OK'))
         return True
 
     def fetch_destination(self, address):
@@ -841,6 +893,7 @@ class MiniActuator:
 
     def is_valid(self, address):
         """Check if bitcoin address is valid."""
+
         return self.wallet.is_valid(address)
 
     def copy_master_public_key(self):