path of icons_rc
[electrum-nvc.git] / gui / qt / __init__.py
1 #!/usr/bin/env python
2 #
3 # Electrum - lightweight Bitcoin client
4 # Copyright (C) 2012 thomasv@gitorious
5 #
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.
10 #
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.
15 #
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/>.
18
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
24 import shutil
25
26
27 try:
28     import PyQt4
29 except:
30     sys.exit("Error: Could not import PyQt4 on Linux systems, you may try 'sudo apt-get install python-qt4'")
31
32 from PyQt4.QtGui import *
33 from PyQt4.QtCore import *
34 import PyQt4.QtCore as QtCore
35
36 from electrum import WalletStorage, Wallet
37 from electrum.i18n import _
38 from electrum.bitcoin import MIN_RELAY_TX_FEE
39
40 try:
41     import icons_rc
42 except:
43     sys.exit("Error: Could not import icons_rc.py, please generate it with: 'pyrcc4 icons.qrc -o gui/qt/icons_rc.py'")
44
45 from util import *
46 from main_window import ElectrumWindow
47 from electrum.plugins import init_plugins
48
49 class Timer(QtCore.QThread):
50     def run(self):
51         while True:
52             self.emit(QtCore.SIGNAL('timersignal'))
53             time.sleep(0.5)
54
55 class OpenFileEventFilter(QObject):
56     def __init__(self, windows):
57         self.windows = windows
58         super(OpenFileEventFilter, self).__init__()
59
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())
64                 return True
65         return False
66
67
68 class ElectrumGui:
69
70     def __init__(self, config, network, app=None):
71         self.network = network
72         self.config = config
73         self.windows = []
74         self.efilter = OpenFileEventFilter(self.windows)
75         if app is None:
76             self.app = QApplication(sys.argv)
77         self.app.installEventFilter(self.efilter)
78
79         init_plugins(self)
80
81
82     def main(self, url):
83
84         storage = WalletStorage(self.config)
85         if not storage.file_exists:
86             import installwizard
87             wizard = installwizard.InstallWizard(self.config, self.network, storage)
88             wallet = wizard.run()
89             if not wallet: 
90                 exit()
91         else:
92             wallet = Wallet(storage)
93             wallet.start_threads(self.network)
94             
95         self.main_window = w = ElectrumWindow(self.config, self.network)
96
97         # plugins that need to change the GUI do it here
98         run_hook('init')
99
100         w.load_wallet(wallet)
101
102         s = Timer()
103         s.start()
104
105         self.windows.append(w)
106         if url: w.set_url(url)
107         w.app = self.app
108         w.connect_slots(s)
109         w.update_wallet()
110
111         self.app.exec_()
112
113         wallet.stop_threads()
114
115