From f540adaf2ab5623380ea0c8c3686a1d4ba98db95 Mon Sep 17 00:00:00 2001 From: Maran Date: Sat, 18 Aug 2012 10:20:35 +0200 Subject: [PATCH 1/6] Load qt gui when qt 4.7 is not available --- electrum | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/electrum b/electrum index 967b5dcec..cb615be9f 100755 --- a/electrum +++ b/electrum @@ -157,13 +157,17 @@ if __name__ == '__main__': error_message = QErrorMessage() error_message.setFixedSize(350,200) - error_message.showMessage("

Sorry, Electrum requires Qt >= 4.7 to run.

Check your distributions packages or download it at http://qt.nokia.com/downloads

") + error_message.showMessage("

Sorry, the Electrum 'Lite GUI' requires Qt >= 4.7 to run. The pro GUI will be started instead.

Check your distributions packages for upgrades.

") app.exec_() - sys.exit(0) - try: + try: + import lib.gui_qt as gui + except ImportError: + import electrum.gui_qt as gui + else: + try: import lib.gui_lite as gui - except ImportError: + except ImportError: import electrum.gui_lite as gui else: print_error("Error: Unknown GUI: " + options.gui) From 3252b5ae4e01e027cb7f6238d46f161cd3898b3c Mon Sep 17 00:00:00 2001 From: Maran Date: Thu, 30 Aug 2012 00:03:38 +0200 Subject: [PATCH 2/6] Added SimpleConfig class to deal with simple config options added for fallback to other gui when missing deps --- electrum | 11 +++++++++-- lib/__init__.py | 1 + lib/simple_config.py | 40 ++++++++++++++++++++++++++++++++++++++++ 3 files changed, 50 insertions(+), 2 deletions(-) create mode 100644 lib/simple_config.py diff --git a/electrum b/electrum index 9a6bb66b6..1e5046d89 100755 --- 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() @@ -161,6 +166,8 @@ if __name__ == '__main__': error_message = QErrorMessage() error_message.setFixedSize(350,200) error_message.showMessage("

Sorry, the Electrum 'Lite GUI' requires Qt >= 4.7 to run. The pro GUI will be started instead.

Check your distributions packages for upgrades.

") + simple_config.config["gui"] = "qt" + simple_config.save_config app.exec_() try: diff --git a/lib/__init__.py b/lib/__init__.py index a2e1aca78..a9461ac88 100644 --- 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 new file mode 100644 index 000000000..47a17e08f --- /dev/null +++ b/lib/simple_config.py @@ -0,0 +1,40 @@ +import json +import os + +class SimpleConfig: + default_options = {"gui": "lite"} + + 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 + if "HOME" in os.environ: + self.config_folder = os.path.join(os.environ["HOME"], ".electrum") + elif "LOCALAPPDATA" in os.environ: + self.config_folder = os.path.join(os.environ["LOCALAPPDATA"], "Electrum") + elif "APPDATA" in os.environ: + self.config_folder = os.path.join(os.environ["APPDATA"], "Electrum") + else: + raise BaseException("No home directory found in environment variables.") + + # Read the file + if os.path.exists(self.config_file_path()): + self.load_config() + else: + self.config = self.default_options + self.save_config() + From 0d229383aae2e22a3a0fe50a72f931435a68d2d0 Mon Sep 17 00:00:00 2001 From: Maran Date: Thu, 30 Aug 2012 00:11:50 +0200 Subject: [PATCH 3/6] Write out the config file to <= 4.7 QT when QT > 4.7 can't be loaded. --- electrum | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/electrum b/electrum index 1e5046d89..d9e1347e4 100755 --- a/electrum +++ b/electrum @@ -150,6 +150,7 @@ if __name__ == '__main__': except ImportError: import electrum.gui_qt as gui elif options.gui == 'lite': + print 'ohhai' # Let's do some dep checking and handle missing ones gracefully try: from PyQt4.QtCore import * @@ -166,8 +167,10 @@ if __name__ == '__main__': error_message = QErrorMessage() error_message.setFixedSize(350,200) error_message.showMessage("

Sorry, the Electrum 'Lite GUI' requires Qt >= 4.7 to run. The pro GUI will be started instead.

Check your distributions packages for upgrades.

") + simple_config.config["gui"] = "qt" - simple_config.save_config + simple_config.save_config() + app.exec_() try: From fbf854bcb8fc53ae4e9f0fabc5618eca16f5dd57 Mon Sep 17 00:00:00 2001 From: Maran Date: Thu, 30 Aug 2012 17:52:03 +0200 Subject: [PATCH 4/6] Added a set_key setter method that can also write out the changes to file --- electrum | 3 +-- lib/simple_config.py | 5 +++++ 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/electrum b/electrum index d9e1347e4..a414d94f2 100755 --- a/electrum +++ b/electrum @@ -168,8 +168,7 @@ if __name__ == '__main__': error_message.setFixedSize(350,200) error_message.showMessage("

Sorry, the Electrum 'Lite GUI' requires Qt >= 4.7 to run. The pro GUI will be started instead.

Check your distributions packages for upgrades.

") - simple_config.config["gui"] = "qt" - simple_config.save_config() + simple_config.set_key("gui", "qt") app.exec_() diff --git a/lib/simple_config.py b/lib/simple_config.py index 47a17e08f..ce64c28db 100644 --- a/lib/simple_config.py +++ b/lib/simple_config.py @@ -4,6 +4,11 @@ import os 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)) From 6da25727f8ea4a411b28b2b381ed05fa8762405d Mon Sep 17 00:00:00 2001 From: Maran Date: Thu, 30 Aug 2012 18:00:08 +0200 Subject: [PATCH 5/6] Refactored user_dir to utils and replaced it in wallet and config --- electrum | 1 - lib/simple_config.py | 11 ++--------- lib/util.py | 10 ++++++++++ lib/wallet.py | 11 +++-------- 4 files changed, 15 insertions(+), 18 deletions(-) diff --git a/electrum b/electrum index a414d94f2..00126cea4 100755 --- a/electrum +++ b/electrum @@ -150,7 +150,6 @@ if __name__ == '__main__': except ImportError: import electrum.gui_qt as gui elif options.gui == 'lite': - print 'ohhai' # Let's do some dep checking and handle missing ones gracefully try: from PyQt4.QtCore import * diff --git a/lib/simple_config.py b/lib/simple_config.py index ce64c28db..e2c8b1016 100644 --- a/lib/simple_config.py +++ b/lib/simple_config.py @@ -1,5 +1,6 @@ import json import os +from lib.util import user_dir class SimpleConfig: default_options = {"gui": "lite"} @@ -27,15 +28,7 @@ class SimpleConfig: def __init__(self): # Find electrum data folder - if "HOME" in os.environ: - self.config_folder = os.path.join(os.environ["HOME"], ".electrum") - elif "LOCALAPPDATA" in os.environ: - self.config_folder = os.path.join(os.environ["LOCALAPPDATA"], "Electrum") - elif "APPDATA" in os.environ: - self.config_folder = os.path.join(os.environ["APPDATA"], "Electrum") - else: - raise BaseException("No home directory found in environment variables.") - + self.config_folder = user_dir() # Read the file if os.path.exists(self.config_file_path()): self.load_config() diff --git a/lib/util.py b/lib/util.py index 2aabcedf3..506d0941d 100644 --- 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 index 18125891b..80d285998 100644 --- 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) From a31733d06504320aab95ab183a2e17f37c1b74fd Mon Sep 17 00:00:00 2001 From: Maran Date: Thu, 30 Aug 2012 19:57:32 +0200 Subject: [PATCH 6/6] Reworked the qt warning dialog --- electrum | 7 +------ 1 file changed, 1 insertion(+), 6 deletions(-) diff --git a/electrum b/electrum index 00126cea4..1fc039b1f 100755 --- a/electrum +++ b/electrum @@ -162,15 +162,10 @@ if __name__ == '__main__': qtVersion = qVersion() if not(int(qtVersion[0]) >= 4 and int(qtVersion[2]) >= 7): app = QApplication(sys.argv) - - error_message = QErrorMessage() - error_message.setFixedSize(350,200) - error_message.showMessage("

Sorry, the Electrum 'Lite GUI' requires Qt >= 4.7 to run. The pro GUI will be started instead.

Check your distributions packages for upgrades.

") + 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.") simple_config.set_key("gui", "qt") - app.exec_() - try: import lib.gui_qt as gui except ImportError: