setWindowIcon() to electrum.png
[electrum-nvc.git] / lib / gui_lite.py
index bbd9222..58895a9 100644 (file)
@@ -1,10 +1,11 @@
 from PyQt4.QtCore import *
 from PyQt4.QtGui import *
 from decimal import Decimal as D
-from util import get_resource_path as rsrc
+from util import appdata_dir, get_resource_path as rsrc
 from i18n import _
 import decimal
 import exchange_rate
+import os.path
 import random
 import re
 import sys
@@ -40,7 +41,10 @@ class ElectrumGui:
     def __init__(self, wallet):
         self.wallet = wallet
         self.app = QApplication(sys.argv)
-        QDir.setCurrent(rsrc())
+        if os.path.exists("data"):
+            QDir.setCurrent("data")
+        else:
+            QDir.setCurrent(appdata_dir())
         with open(rsrc("style.css")) as style_file:
             self.app.setStyleSheet(style_file.read())
 
@@ -59,7 +63,7 @@ class ElectrumGui:
         self.expert.connect_slots(timer)
         self.expert.update_wallet()
 
-        sys.exit(self.app.exec_())
+        self.app.exec_()
 
     def expand(self):
         self.mini.hide()
@@ -116,7 +120,8 @@ class MiniWindow(QDialog):
         self.connect(expand_button, SIGNAL("clicked()"), expand_callback)
 
         self.btc_balance = None
-        self.quote_currencies = ("EUR", "USD", "GBP")
+        self.quote_currencies = ["EUR", "USD", "GBP"]
+        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
         # which needs to be sent back to this main one to update the GUI
@@ -136,7 +141,7 @@ class MiniWindow(QDialog):
         self.connect(self.address_input, SIGNAL("textEdited(QString)"),
                      self.address_field_changed)
         resize_line_edit_width(self.address_input,
-                               "1E4vM9q25xsyDwWwdqHUWnwshdWC9PykmL")
+                               "1BtaFUr3qVvAmwrsuDuu5zk6e4s2rxd2Gy")
 
         self.address_completions = QStringListModel()
         address_completer = QCompleter(self.address_input)
@@ -185,6 +190,12 @@ class MiniWindow(QDialog):
         main_layout.addLayout(amount_layout, 2, 1)
         main_layout.addWidget(send_button, 2, 2)
 
+        quit_shortcut = QShortcut(QKeySequence("Ctrl+Q"), self)
+        self.connect(quit_shortcut, SIGNAL("activated()"), self.close)
+        close_shortcut = QShortcut(QKeySequence("Ctrl+W"), self)
+        self.connect(close_shortcut, SIGNAL("activated()"), self.close)
+
+        self.setWindowIcon(QIcon(":electrum.png"))
         self.setWindowTitle("Electrum")
         self.setWindowFlags(Qt.Window|Qt.MSWindowsFixedSizeDialogHint)
         self.layout().setSizeConstraint(QLayout.SetFixedSize)
@@ -208,9 +219,16 @@ class MiniWindow(QDialog):
     def deactivate(self):
         pass
 
+    def set_quote_currency(self, currency):
+        assert currency in self.quote_currencies
+        self.quote_currencies.remove(currency)
+        self.quote_currencies = [currency] + self.quote_currencies
+        self.refresh_balance()
+
     def change_quote_currency(self):
         self.quote_currencies = \
             self.quote_currencies[1:] + self.quote_currencies[0:1]
+        self.actuator.set_config_currency(self.quote_currencies[0])
         self.refresh_balance()
 
     def refresh_balance(self):
@@ -436,9 +454,21 @@ class MiniActuator:
     def __init__(self, wallet):
         self.wallet = wallet
 
+    def set_configured_currency(self, set_quote_currency):
+        currency = self.wallet.conversion_currency
+        # currency can be none when Electrum is used for the first
+        # time and no setting has been created yet.
+        if currency is not None:
+            set_quote_currency(currency)
+
+    def set_config_currency(self, conversion_currency):
+        self.wallet.conversion_currency = conversion_currency
+
     def copy_address(self, receive_popup):
         addrs = [addr for addr in self.wallet.all_addresses()
                  if not self.wallet.is_change(addr)]
+        # Select most recent addresses from gap limit
+        addrs = addrs[-self.wallet.gap_limit:]
         copied_address = random.choice(addrs)
         qApp.clipboard().setText(copied_address)
         receive_popup.setup(copied_address)
@@ -528,6 +558,7 @@ class MiniDriver(QObject):
 
         self.initializing()
         self.connect(self, SIGNAL("updatesignal()"), self.update)
+        self.update_callback()
 
     # This is a hack to workaround that Qt does not like changing the
     # window properties from this other thread before the runloop has