3 # Electrum - lightweight Bitcoin client
4 # Copyright (C) 2012 thomasv@gitorious
6 # This program is free software: you can redistribute it and/or modify
7 # it under the terms of the GNU General Public License as published by
8 # the Free Software Foundation, either version 3 of the License, or
9 # (at your option) any later version.
11 # This program is distributed in the hope that it will be useful,
12 # but WITHOUT ANY WARRANTY; without even the implied warranty of
13 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 # GNU General Public License for more details.
16 # You should have received a copy of the GNU General Public License
17 # along with this program. If not, see <http://www.gnu.org/licenses/>.
19 import sys, time, datetime, re, threading
20 from electrum.i18n import _, set_language
21 from electrum.util import print_error, print_msg, parse_url
22 from electrum.plugins import run_hook
23 import os.path, json, ast, traceback
30 sys.exit("Error: Could not import PyQt4 on Linux systems, you may try 'sudo apt-get install python-qt4'")
32 from PyQt4.QtGui import *
33 from PyQt4.QtCore import *
34 import PyQt4.QtCore as QtCore
36 from electrum import WalletStorage, Wallet
37 from electrum.i18n import _
38 from electrum.bitcoin import MIN_RELAY_TX_FEE
43 sys.exit("Error: Could not import icons_rc.py, please generate it with: 'pyrcc4 icons.qrc -o gui/gui_classic/icons_rc.py'")
46 from main_window import ElectrumWindow
47 from electrum.plugins import init_plugins
49 class Timer(QtCore.QThread):
52 self.emit(QtCore.SIGNAL('timersignal'))
55 class OpenFileEventFilter(QObject):
56 def __init__(self, windows):
57 self.windows = windows
58 super(OpenFileEventFilter, self).__init__()
60 def eventFilter(self, obj, event):
61 if event.type() == QtCore.QEvent.FileOpen:
62 if len(self.windows) >= 1:
63 self.windows[0].set_url(event.url().toString())
70 def __init__(self, config, network, app=None):
71 self.network = network
74 self.efilter = OpenFileEventFilter(self.windows)
76 self.app = QApplication(sys.argv)
77 self.app.installEventFilter(self.efilter)
84 """Hide the lite mode window and show pro-mode."""
85 self.config.set_key('lite_mode', False, True)
90 self.config.set_key('lite_mode', True, True)
94 def init_lite(self, wallet, expert, url):
96 if not self.check_qt_version():
99 actuator = lite_window.MiniActuator(self.config, wallet)
100 # Should probably not modify the current path but instead
101 # change the behaviour of rsrc(...)
102 old_path = QDir.currentPath()
103 actuator.load_theme()
105 mini = lite_window.MiniWindow(actuator, self.expand, self.config)
106 driver = lite_window.MiniDriver(wallet, mini)
108 # Reset path back to original value now that loading the GUI
110 QDir.setCurrent(old_path)
112 payto, amount, label, message, signature, identity, url = parse_url(url)
113 mini.set_payment_fields(payto, amount)
117 def check_qt_version(self):
118 qtVersion = qVersion()
119 return int(qtVersion[0]) >= 4 and int(qtVersion[2]) >= 7
124 storage = WalletStorage(self.config)
125 if not storage.file_exists:
127 wizard = installwizard.InstallWizard(self.config, self.network, storage)
128 wallet = wizard.run()
132 wallet = Wallet(storage)
134 wallet.start_threads(self.network)
137 self.main_window = w = ElectrumWindow(self.config, self.network, self.minimize)
139 # plugins that need to change the GUI do it here
142 w.load_wallet(wallet)
147 self.windows.append(w)
148 if url: w.set_url(url)
154 self.mini = self.init_lite(wallet, w, url)
156 if self.config.get('lite_mode'):
158 QMessageBox.warning(None,"Could not start Lite GUI.", "Electrum was unable to load the 'Lite GUI' because it needs Qt version >= 4.7.\nChanging your config to use the 'Classic' GUI")
159 self.config.set_key('lite_mode', False, True)
170 wallet.stop_threads()