ca021e139f74d7459925fa57fbe81c6335491148
[electrum-nvc.git] / gui / qt / seed_dialog.py
1 #!/usr/bin/env python
2 #
3 # Electrum - lightweight Bitcoin client
4 # Copyright (C) 2013 ecdsa@github
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 from PyQt4.QtGui import *
20 from PyQt4.QtCore import *
21 import PyQt4.QtCore as QtCore
22 from electrum.i18n import _
23 from electrum import mnemonic
24 from qrcodewidget import QRCodeWidget, QRDialog
25 from util import close_button
26 from qrtextedit import QRTextEdit
27
28 class SeedDialog(QDialog):
29     def __init__(self, parent, seed, imported_keys):
30         QDialog.__init__(self, parent)
31         self.setModal(1)
32         self.setWindowTitle('Electrum' + ' - ' + _('Seed'))
33         vbox = show_seed_box(seed)
34         if imported_keys:
35             vbox.addWidget(QLabel("<b>"+_("WARNING")+":</b> " + _("Your wallet contains imported keys. These keys cannot be recovered from seed.") + "</b><p>"))
36         vbox.addLayout(close_button(self))
37         self.setLayout(vbox)
38
39
40 def icon_filename(sid):
41     if sid == 'cold':
42         return ":icons/cold_seed.png" 
43     elif sid == 'hot':
44         return ":icons/hot_seed.png" 
45     else:
46         return ":icons/seed.png" 
47     
48
49
50
51 def show_seed_box(seed, sid=None):
52
53     save_msg = _("Please save these %d words on paper (order is important).")%len(seed.split()) + " " 
54     qr_msg = _("Your seed is also displayed as QR code, in case you want to transfer it to a mobile phone.") + "<p>"
55     warning_msg = "<b>"+_("WARNING")+":</b> " + _("Never disclose your seed. Never type it on a website.") + "</b><p>"
56
57     if sid is None:
58         msg =  _("Your wallet generation seed is")
59         msg2 = save_msg + " " \
60                + _("This seed will allow you to recover your wallet in case of computer failure.") + "<br/>" \
61                + warning_msg
62         
63     elif sid == 'cold':
64         msg =  _("Your cold storage seed is")
65         msg2 = save_msg + " " \
66                + _("This seed will be permanently deleted from your wallet file. Make sure you have saved it before you press 'next'") + " " \
67             
68     elif sid == 'hot':
69         msg =  _("Your hot seed is")
70         msg2 = save_msg + " " \
71                + _("If you ever need to recover your wallet from seed, you will need both this seed and your cold seed.") + " " \
72
73     label1 = QLabel(msg+ ":")
74     seed_text = QRTextEdit(seed)
75     seed_text.setReadOnly(True)
76     seed_text.setMaximumHeight(130)
77
78     label2 = QLabel(msg2)
79     label2.setWordWrap(True)
80
81     logo = QLabel()
82
83     logo.setPixmap(QPixmap(icon_filename(sid)).scaledToWidth(56))
84     logo.setMaximumWidth(60)
85
86     grid = QGridLayout()
87     grid.addWidget(logo, 0, 0)
88     grid.addWidget(label1, 0, 1)
89     grid.addWidget(seed_text, 1, 0, 1, 2)
90     #qrw = QRCodeWidget(seed)
91     #grid.addWidget(qrw, 0, 2, 2, 1)
92     vbox = QVBoxLayout()
93     vbox.addLayout(grid)
94     vbox.addWidget(label2)
95     vbox.addStretch(1)
96     
97     return vbox
98
99
100 def enter_seed_box(msg, sid=None):
101
102     vbox = QVBoxLayout()
103     logo = QLabel()
104     logo.setPixmap(QPixmap(icon_filename(sid)).scaledToWidth(56))
105     logo.setMaximumWidth(60)
106
107     label = QLabel(msg)
108     label.setWordWrap(True)
109
110     seed_e = QRTextEdit()
111     seed_e.setMaximumHeight(100)
112     seed_e.setTabChangesFocus(True)
113
114     vbox.addWidget(label)
115
116     grid = QGridLayout()
117     grid.addWidget(logo, 0, 0)
118     grid.addWidget(seed_e, 0, 1)
119
120     vbox.addLayout(grid)
121     return vbox, seed_e