commit 3f499d7048bd5053d8ed75233b26667145c28520
parent 89a4045e3a377f68def0961f4ffc80fa1c552de1
Author: Maran <maran.hidskes@gmail.com>
Date: Tue, 4 Sep 2012 17:30:19 +0200
Merge branch 'fallback'
Diffstat:
5 files changed, 70 insertions(+), 19 deletions(-)
diff --git a/electrum b/electrum
@@ -40,8 +40,9 @@ try:
from lib import Wallet, WalletSynchronizer, format_satoshis, mnemonic, prompt_password
except ImportError:
from electrum import Wallet, WalletSynchronizer, format_satoshis, mnemonic, prompt_password
-
+
from decimal import Decimal
+from lib import SimpleConfig
known_commands = {
'help':'Prints this help',
@@ -101,9 +102,12 @@ protected_commands = ['payto', 'password', 'mktx', 'seed', 'import','signmessage
if __name__ == '__main__':
+ # Load simple config class
+ simple_config = SimpleConfig()
+
usage = "usage: %prog [options] command\nCommands: "+ (', '.join(known_commands))
parser = optparse.OptionParser(prog=usage)
- parser.add_option("-g", "--gui", dest="gui", default="lite", help="gui")
+ parser.add_option("-g", "--gui", dest="gui", default=simple_config.config["gui"], help="gui")
parser.add_option("-w", "--wallet", dest="wallet_path", help="wallet path (default: electrum.dat)")
parser.add_option("-o", "--offline", action="store_true", dest="offline", default=False, help="remain offline")
parser.add_option("-a", "--all", action="store_true", dest="show_all", default=False, help="show all addresses")
@@ -115,6 +119,7 @@ if __name__ == '__main__':
parser.add_option("-r", "--remote", dest="remote_url", default=None, help="URL of a remote wallet")
options, args = parser.parse_args()
+
wallet = Wallet()
wallet.set_path(options.wallet_path)
wallet.read()
@@ -157,17 +162,19 @@ if __name__ == '__main__':
qtVersion = qVersion()
if not(int(qtVersion[0]) >= 4 and int(qtVersion[2]) >= 7):
app = QApplication(sys.argv)
+ QMessageBox.warning(None,"Could not start Lite GUI.", "Electrum was unable to load the 'Lite GUI' because it needs Qt version >= 4.7.\nElectrum is now setup to load the Pro GUI.")
- error_message = QErrorMessage()
- error_message.setFixedSize(350,200)
- error_message.showMessage("<p>Sorry, Electrum requires Qt >= 4.7 to run.</p><p>Check your distributions packages or download it at http://qt.nokia.com/downloads</p>")
- app.exec_()
- sys.exit(0)
-
- #use the lite version if no toolkit specified
- try:
+ simple_config.set_key("gui", "qt")
+
+ try:
+ import lib.gui_qt as gui
+ except ImportError:
+ import electrum.gui_qt as gui
+ else:
+ #use the lite version if no toolkit specified
+ try:
import lib.gui_lite as gui
- except ImportError:
+ except ImportError:
import electrum.gui_lite as gui
else:
sys.exit("Error: Unknown GUI: " + options.gui)
diff --git a/lib/__init__.py b/lib/__init__.py
@@ -1,3 +1,4 @@
from wallet import Wallet, format_satoshis, prompt_password
from interface import WalletSynchronizer
from interface import TcpStratumInterface
+from simple_config import SimpleConfig
diff --git a/lib/simple_config.py b/lib/simple_config.py
@@ -0,0 +1,38 @@
+import json
+import os
+from lib.util import user_dir
+
+class SimpleConfig:
+ default_options = {"gui": "lite"}
+
+ def set_key(self, key, value, save = True):
+ self.config[key] = value
+ if save == True:
+ self.save_config()
+
+ def save_config(self):
+ f = open(self.config_file_path(), "w+")
+ f.write(json.dumps(self.config))
+
+ def load_config(self):
+ f = open(self.config_file_path(), "r")
+ file_contents = f.read()
+ if file_contents:
+ self.config = json.loads(file_contents)
+ else:
+ self.config = self.default_options
+ self.save_config()
+
+ def config_file_path(self):
+ return "%s" % (self.config_folder + "/config.json")
+
+ def __init__(self):
+ # Find electrum data folder
+ self.config_folder = user_dir()
+ # Read the file
+ if os.path.exists(self.config_file_path()):
+ self.load_config()
+ else:
+ self.config = self.default_options
+ self.save_config()
+
diff --git a/lib/util.py b/lib/util.py
@@ -8,6 +8,16 @@ def print_error(*args):
sys.stderr.write(" ".join(args) + "\n")
sys.stderr.flush()
+def user_dir():
+ if "HOME" in os.environ:
+ return os.path.join(os.environ["HOME"], ".electrum")
+ elif "LOCALAPPDATA" in os.environ:
+ return os.path.join(os.environ["LOCALAPPDATA"], "Electrum")
+ elif "APPDATA" in os.environ:
+ return os.path.join(os.environ["APPDATA"], "Electrum")
+ else:
+ raise BaseException("No home directory found in environment variables.")
+
def appdata_dir():
"""Find the path to the application data directory; add an electrum folder and return path."""
if platform.system() == "Windows":
diff --git a/lib/wallet.py b/lib/wallet.py
@@ -32,6 +32,7 @@ import ecdsa
from ecdsa.util import string_to_number, number_to_string
from util import print_error
+from util import user_dir
############ functions from pywallet #####################
@@ -365,14 +366,8 @@ class Wallet:
return
# Look for wallet file in the default data directory.
# Keeps backwards compatibility.
- if "HOME" in os.environ:
- wallet_dir = os.path.join(os.environ["HOME"], ".electrum")
- elif "LOCALAPPDATA" in os.environ:
- wallet_dir = os.path.join(os.environ["LOCALAPPDATA"], "Electrum")
- elif "APPDATA" in os.environ:
- wallet_dir = os.path.join(os.environ["APPDATA"], "Electrum")
- else:
- raise BaseException("No home directory found in environment variables.")
+ wallet_dir = user_dir()
+
# Make wallet directory if it does not yet exist.
if not os.path.exists(wallet_dir):
os.mkdir(wallet_dir)