forked from etotheipi/BitcoinArmory
-
Notifications
You must be signed in to change notification settings - Fork 0
/
qtdialogs.py
14276 lines (11552 loc) · 579 KB
/
qtdialogs.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
################################################################################
# #
# Copyright (C) 2011-2013, Armory Technologies, Inc. #
# Distributed under the GNU Affero General Public License (AGPL v3) #
# See LICENSE or http://www.gnu.org/licenses/agpl.html #
# #
################################################################################
import sys
import time
import shutil
import functools
from PyQt4.QtCore import *
from PyQt4.QtGui import *
from qtdefines import *
from armoryengine import *
from armorymodels import *
from armorycolors import Colors, htmlColor
import qrc_img_resources
MIN_PASSWD_WIDTH = lambda obj: tightSizeStr(obj, '*'*16)[0]
################################################################################
class DlgUnlockWallet(ArmoryDialog):
def __init__(self, wlt, parent=None, main=None, unlockMsg='Unlock Wallet', \
returnResult=False):
super(DlgUnlockWallet, self).__init__(parent, main)
self.wlt = wlt
self.returnResult = returnResult
##### Upper layout
lblDescr = QLabel("Enter your passphrase to unlock this wallet")
lblPasswd = QLabel("Passphrase:")
self.edtPasswd = QLineEdit()
self.edtPasswd.setEchoMode(QLineEdit.Password)
self.edtPasswd.setMinimumWidth(MIN_PASSWD_WIDTH(self))
self.edtPasswd.setSizePolicy(QSizePolicy.Fixed, QSizePolicy.Expanding)
self.btnAccept = QPushButton("Unlock")
self.btnCancel = QPushButton("Cancel")
self.connect(self.btnAccept, SIGNAL('clicked()'), self.acceptPassphrase)
self.connect(self.btnCancel, SIGNAL('clicked()'), self.reject)
buttonBox = QDialogButtonBox()
buttonBox.addButton(self.btnAccept, QDialogButtonBox.AcceptRole)
buttonBox.addButton(self.btnCancel, QDialogButtonBox.RejectRole)
layoutUpper = QGridLayout()
layoutUpper.addWidget(lblDescr, 1, 0, 1, 2)
layoutUpper.addWidget(lblPasswd, 2, 0, 1, 1)
layoutUpper.addWidget(self.edtPasswd, 2, 1, 1, 1)
self.frmUpper = QFrame()
self.frmUpper.setLayout(layoutUpper)
##### Lower layout
# Add scrambled keyboard (EN-US only)
ttipScramble= self.main.createToolTipWidget( \
'Using a visual keyboard to enter your passphrase '
'protects you against simple keyloggers. Scrambling '
'makes it difficult to use, but prevents even loggers '
'that record mouse clicks.')
self.createKeyButtons()
self.rdoScrambleNone = QRadioButton('Regular Keyboard')
self.rdoScrambleLite = QRadioButton('Scrambled (Simple)')
self.rdoScrambleFull = QRadioButton('Scrambled (Dynamic)')
btngrp = QButtonGroup(self)
btngrp.addButton(self.rdoScrambleNone)
btngrp.addButton(self.rdoScrambleLite)
btngrp.addButton(self.rdoScrambleFull)
btngrp.setExclusive(True)
defaultScramble = self.main.getSettingOrSetDefault('ScrambleDefault', 0)
if defaultScramble==0:
self.rdoScrambleNone.setChecked(True)
elif defaultScramble==1:
self.rdoScrambleLite.setChecked(True)
elif defaultScramble==2:
self.rdoScrambleFull.setChecked(True)
self.connect(self.rdoScrambleNone, SIGNAL('clicked()'), self.changeScramble)
self.connect(self.rdoScrambleLite, SIGNAL('clicked()'), self.changeScramble)
self.connect(self.rdoScrambleFull, SIGNAL('clicked()'), self.changeScramble)
btnRowFrm = makeHorizFrame([self.rdoScrambleNone, \
self.rdoScrambleLite, \
self.rdoScrambleFull, \
'Stretch'])
self.layoutKeyboard = QGridLayout()
self.frmKeyboard = QFrame()
self.frmKeyboard.setLayout(self.layoutKeyboard)
showOSD = self.main.getSettingOrSetDefault('KeybdOSD',False)
self.layoutLower = QGridLayout()
self.layoutLower.addWidget( btnRowFrm , 0,0)
self.layoutLower.addWidget( self.frmKeyboard , 1,0)
self.frmLower = QFrame()
self.frmLower.setLayout(self.layoutLower)
self.frmLower.setVisible(showOSD)
##### Expand button
self.btnShowOSD = QPushButton('Show Keyboard >>>')
self.btnShowOSD.setCheckable(True)
self.btnShowOSD.setChecked(showOSD)
self.connect(self.btnShowOSD, SIGNAL('toggled(bool)'), self.toggleOSD)
frmAccept = makeHorizFrame([self.btnShowOSD, ttipScramble, 'Stretch', buttonBox])
##### Complete Layout
layout = QVBoxLayout()
layout.addWidget(self.frmUpper)
layout.addWidget(frmAccept)
layout.addWidget(self.frmLower)
self.setLayout(layout)
self.setWindowTitle(unlockMsg + ' - ' + wlt.uniqueIDB58)
# Add scrambled keyboard
self.layout().setSizeConstraint(QLayout.SetFixedSize)
self.changeScramble()
self.redrawKeys()
#############################################################################
def toggleOSD(self):
isChk = self.btnShowOSD.isChecked()
self.main.settings.set('KeybdOSD', isChk)
self.frmLower.setVisible(isChk)
if isChk:
self.btnShowOSD.setText('Hide Keyboard <<<')
else:
self.btnShowOSD.setText('Show Keyboard >>>')
#############################################################################
def createKeyboardKeyButton(self, keyLow, keyUp, defRow, special=None):
theBtn = LetterButton(keyLow, keyUp, defRow, special, self.edtPasswd, self)
self.connect(theBtn, SIGNAL('clicked()'), theBtn.insertLetter)
theBtn.setMaximumWidth(40)
return theBtn
#############################################################################
def redrawKeys(self):
for btn in self.btnList:
btn.setText(btn.upper if self.btnShift.isChecked() else btn.lower)
self.btnShift.setText('SHIFT')
self.btnSpace.setText('SPACE')
self.btnDelete.setText('DEL')
#############################################################################
def deleteKeyboard(self):
for btn in self.btnList:
btn.setParent(None)
del btn
self.btnList = []
self.btnShift.setParent(None)
self.btnSpace.setParent(None)
self.btnDelete.setParent(None)
del self.btnShift
del self.btnSpace
del self.btnDelete
del self.frmKeyboard
del self.layoutKeyboard
#############################################################################
def createKeyButtons(self):
# TODO: Add some locale-agnostic method here, that could replace
# the letter arrays with something more appropriate for non en-us
self.letLower = r"`1234567890-=qwertyuiop[]\asdfghjkl;'zxcvbnm,./"
self.letUpper = r'~!@#$%^&*()_+QWERTYUIOP{}|ASDFGHJKL:"ZXCVBNM<>?'
self.letRows = r'11111111111112222222222222333333333334444444444'
self.letPairs = zip(self.letLower,self.letUpper,self.letRows)
self.btnList = []
for l,u,r in zip(self.letLower, self.letUpper, self.letRows):
if l=='7':
# Because QPushButtons interpret ampersands as special characters
u = 2*u
if l.isdigit():
self.btnList.append(self.createKeyboardKeyButton('#'+l,u,int(r)))
else:
self.btnList.append(self.createKeyboardKeyButton(l,u,int(r)))
# Add shift and space keys
self.btnShift = self.createKeyboardKeyButton('', '', 5,'shift')
self.btnSpace = self.createKeyboardKeyButton(' ',' ',5,'space')
self.btnDelete= self.createKeyboardKeyButton(' ',' ',5,'delete')
self.btnShift.setCheckable(True)
self.btnShift.setChecked(False)
#############################################################################
def reshuffleKeys(self):
if self.rdoScrambleFull.isChecked():
self.changeScramble()
#############################################################################
def changeScramble(self):
self.deleteKeyboard()
self.frmKeyboard = QFrame()
self.layoutKeyboard = QGridLayout()
self.createKeyButtons()
if self.rdoScrambleNone.isChecked():
opt = 0
prevRow = 1
col=0
for btn in self.btnList:
row = btn.defRow
if not row==prevRow:
col=0
if row>3 and col==0:
col+=1
prevRow = row
self.layoutKeyboard.addWidget(btn, row, col)
col += 1
self.layoutKeyboard.addWidget(self.btnShift, self.btnShift.defRow, 0, 1,3)
self.layoutKeyboard.addWidget(self.btnSpace, self.btnSpace.defRow, 4, 1,5)
self.layoutKeyboard.addWidget(self.btnDelete, self.btnDelete.defRow, 11, 1,2)
self.btnShift.setMaximumWidth(1000)
self.btnSpace.setMaximumWidth(1000)
self.btnDelete.setMaximumWidth(1000)
elif self.rdoScrambleLite.isChecked():
opt = 1
nchar = len(self.btnList)
rnd = SecureBinaryData().GenerateRandom(2*nchar).toBinStr()
newBtnList = [[self.btnList[i], rnd[2*i:2*(i+1)]] for i in range(nchar)]
newBtnList.sort(key=lambda x: x[1])
prevRow = 0
col=0
for i,btn in enumerate(newBtnList):
row = i/12
if not row==prevRow:
col=0
prevRow = row
self.layoutKeyboard.addWidget(btn[0], row, col)
col += 1
self.layoutKeyboard.addWidget(self.btnShift, self.btnShift.defRow, 0, 1,3)
self.layoutKeyboard.addWidget(self.btnSpace, self.btnSpace.defRow, 4, 1,5)
self.layoutKeyboard.addWidget(self.btnDelete, self.btnDelete.defRow, 10, 1,2)
self.btnShift.setMaximumWidth(1000)
self.btnSpace.setMaximumWidth(1000)
self.btnDelete.setMaximumWidth(1000)
elif self.rdoScrambleFull.isChecked():
opt = 2
extBtnList = self.btnList[:]
extBtnList.extend([self.btnShift, self.btnSpace])
nchar = len(extBtnList)
rnd = SecureBinaryData().GenerateRandom(2*nchar).toBinStr()
newBtnList = [[extBtnList[i], rnd[2*i:2*(i+1)]] for i in range(nchar)]
newBtnList.sort(key=lambda x: x[1])
prevRow = 0
col=0
for i,btn in enumerate(newBtnList):
row = i/12
if not row==prevRow:
col=0
prevRow = row
self.layoutKeyboard.addWidget(btn[0], row, col)
col += 1
self.layoutKeyboard.addWidget(self.btnDelete, self.btnDelete.defRow-1, 11, 1,2)
self.btnShift.setMaximumWidth(40)
self.btnSpace.setMaximumWidth(40)
self.btnDelete.setMaximumWidth(40)
self.frmKeyboard.setLayout(self.layoutKeyboard)
self.layoutLower.addWidget(self.frmKeyboard, 1,0)
self.main.settings.set('ScrambleDefault', opt)
self.redrawKeys()
#############################################################################
def acceptPassphrase(self):
self.securePassphrase = SecureBinaryData(str(self.edtPasswd.text()))
if self.returnResult:
self.accept()
return
try:
self.wlt.unlock(securePassphrase=self.securePassphrase)
self.securePassphrase.destroy()
self.edtPasswd.setText('')
self.accept()
except PassphraseError:
QMessageBox.critical(self, 'Invalid Passphrase', \
'That passphrase is not correct!', QMessageBox.Ok)
self.securePassphrase.destroy()
self.edtPasswd.setText('')
return
#############################################################################
class LetterButton(QPushButton):
def __init__(self, Low, Up, Row, Spec, edtTarget, parent):
super(LetterButton, self).__init__('')
self.lower = Low
self.upper = Up
self.defRow = Row
self.special = Spec
self.target = edtTarget
self.parent = parent
if self.special:
super(LetterButton, self).setFont(GETFONT('Var',8))
else:
super(LetterButton, self).setFont(GETFONT('Fixed',10))
if self.special == 'space':
self.setText('SPACE')
self.lower = ' '
self.upper = ' '
self.special = 5
elif self.special == 'shift':
self.setText('SHIFT')
self.special = 5
self.insertLetter = self.pressShift
elif self.special == 'delete':
self.setText('DEL')
self.special = 5
self.insertLetter = self.pressBackspace
def insertLetter(self):
currPwd = str(self.parent.edtPasswd.text())
insChar = self.upper if self.parent.btnShift.isChecked() else self.lower
if len(insChar)==2 and insChar.startswith('#'):
insChar = insChar[1]
self.parent.edtPasswd.setText( currPwd + insChar )
self.parent.reshuffleKeys()
def pressShift(self):
self.parent.redrawKeys()
def pressBackspace(self):
currPwd = str(self.parent.edtPasswd.text())
if len(currPwd)>0:
self.parent.edtPasswd.setText( currPwd[:-1])
self.parent.redrawKeys()
################################################################################
class DlgTooltip(ArmoryDialog):
def __init__(self, parentDlg=None, parentLbl=None, tiptext=''):
super(DlgTooltip, self).__init__(parentDlg, main=None)
if not parentDlg or not tiptext:
self.accept()
qc = QCursor.pos()
qp = QPoint(qc.x()-20, qc.y()-20)
self.move(qp)
tiptext += '<font size=2 color="#000044"><br>[Click to close]</font>'
lblText = QRichLabel(tiptext, doWrap=True)
lblText.mousePressEvent = lambda ev: self.accept()
lblText.mouseReleaseEvent = lambda ev: self.accept()
layout = QVBoxLayout()
layout.addWidget( makeHorizFrame([lblText], STYLE_RAISED) )
layout.setContentsMargins(0,0,0,0)
self.setLayout(layout)
self.setStyleSheet('QDialog { background-color : %s }' % htmlColor('Foreground'))
lblText.setStyleSheet('QLabel { background-color : %s }' % htmlColor('SlightBkgdDark'))
lblText.setContentsMargins(3,3,3,3)
self.setMinimumWidth(150)
self.setWindowFlags(Qt.SplashScreen)
#def mouseReleaseEvent(self, ev):
#self.accept()
def mousePressEvent(self, ev):
self.accept()
def keyPressEvent(self, ev):
self.accept()
################################################################################
class DlgGenericGetPassword(ArmoryDialog):
def __init__(self, descriptionStr, parent=None, main=None):
super(DlgGenericGetPassword, self).__init__(parent, main)
lblDescr = QRichLabel(descriptionStr)
lblPasswd = QRichLabel("Password:")
self.edtPasswd = QLineEdit()
self.edtPasswd.setEchoMode(QLineEdit.Password)
self.edtPasswd.setMinimumWidth(MIN_PASSWD_WIDTH(self))
self.edtPasswd.setSizePolicy(QSizePolicy.Fixed, QSizePolicy.Expanding)
self.btnAccept = QPushButton("OK")
self.btnCancel = QPushButton("Cancel")
self.connect(self.btnAccept, SIGNAL('clicked()'), self.accept)
self.connect(self.btnCancel, SIGNAL('clicked()'), self.reject)
buttonBox = QDialogButtonBox()
buttonBox.addButton(self.btnAccept, QDialogButtonBox.AcceptRole)
buttonBox.addButton(self.btnCancel, QDialogButtonBox.RejectRole)
layout = QGridLayout()
layout.addWidget(lblDescr, 1, 0, 1, 2)
layout.addWidget(lblPasswd, 2, 0, 1, 1)
layout.addWidget(self.edtPasswd, 2, 1, 1, 1)
layout.addWidget(buttonBox, 3, 1, 1, 2)
self.setLayout(layout)
self.setWindowTitle('Enter Password')
self.setWindowIcon(QIcon(self.main.iconfile))
################################################################################
class DlgNewWallet(ArmoryDialog):
def __init__(self, parent=None, main=None, initLabel=''):
super(DlgNewWallet, self).__init__(parent, main)
self.selectedImport = False
# Options for creating a new wallet
lblDlgDescr = QLabel('Create a new wallet for managing your funds.\n'
'The name and description can be changed at any time.')
lblDlgDescr.setWordWrap(True)
self.edtName = QLineEdit()
self.edtName.setMaxLength(32)
self.edtName.setText(initLabel)
lblName = QLabel("Wallet &name:")
lblName.setBuddy(self.edtName)
self.edtDescr = QTextEdit()
self.edtDescr.setMaximumHeight(75)
lblDescr = QLabel("Wallet &description:")
lblDescr.setAlignment(Qt.AlignVCenter)
lblDescr.setBuddy(self.edtDescr)
buttonBox = QDialogButtonBox(QDialogButtonBox.Ok | \
QDialogButtonBox.Cancel)
# Advanced Encryption Options
lblComputeDescr = QLabel( \
'Armory will test your system\'s speed to determine the most '
'challenging encryption settings that can be performed '
'in a given amount of time. High settings make it much harder '
'for someone to guess your passphrase. This is used for all '
'encrypted wallets, but the default parameters can be changed below.\n')
lblComputeDescr.setWordWrap(True)
timeDescrTip = self.main.createToolTipWidget( \
'This is the amount of time it will take for your computer '
'to unlock your wallet after you enter your passphrase. '
'(the actual time used will be less than the specified '
'time, but more than one half of it). ')
# Set maximum compute time
self.edtComputeTime = QLineEdit()
self.edtComputeTime.setText('250 ms')
self.edtComputeTime.setMaxLength(12)
lblComputeTime = QLabel('Target compute &time (s, ms):')
memDescrTip = self.main.createToolTipWidget( \
'This is the <b>maximum</b> memory that will be '
'used as part of the encryption process. The actual value used '
'may be lower, depending on your system\'s speed. If a '
'low value is chosen, Armory will compensate by chaining '
'together more calculations to meet the target time. High '
'memory target will make GPU-acceleration useless for '
'guessing your passphrase.')
lblComputeTime.setBuddy(self.edtComputeTime)
# Set maximum memory usage
self.edtComputeMem = QLineEdit()
self.edtComputeMem.setText('32.0 MB')
self.edtComputeMem.setMaxLength(12)
lblComputeMem = QLabel('Max &memory usage (kB, MB):')
lblComputeMem.setBuddy(self.edtComputeMem)
self.edtComputeTime.setMaximumWidth( tightSizeNChar(self, 20)[0] )
self.edtComputeMem.setMaximumWidth( tightSizeNChar(self, 20)[0] )
# Fork watching-only wallet
cryptoLayout = QGridLayout()
cryptoLayout.addWidget(lblComputeDescr, 0, 0, 1, 3)
cryptoLayout.addWidget(timeDescrTip, 1, 0, 1, 1)
cryptoLayout.addWidget(lblComputeTime, 1, 1, 1, 1)
cryptoLayout.addWidget(self.edtComputeTime, 1, 2, 1, 1)
cryptoLayout.addWidget(memDescrTip, 2, 0, 1, 1)
cryptoLayout.addWidget(lblComputeMem, 2, 1, 1, 1)
cryptoLayout.addWidget(self.edtComputeMem, 2, 2, 1, 1)
self.cryptoFrame = QFrame()
self.cryptoFrame.setFrameStyle(STYLE_SUNKEN)
self.cryptoFrame.setLayout(cryptoLayout)
self.cryptoFrame.setVisible(False)
self.chkUseCrypto = QCheckBox("Use wallet &encryption")
self.chkUseCrypto.setChecked(True)
usecryptoTooltip = self.main.createToolTipWidget(
'Encryption prevents anyone who accesses your computer '
'or wallet file from being able to spend your money, as '
'long as they do not have the passphrase.'
'You can choose to encrypt your wallet at a later time '
'through the wallet properties dialog by double clicking '
'the wallet on the dashboard.')
# For a new wallet, the user may want to print out a paper backup
self.chkPrintPaper = QCheckBox("Print a paper-backup of this wallet")
self.chkPrintPaper.setChecked(True)
paperBackupTooltip = self.main.createToolTipWidget(
'A paper-backup allows you to recover your wallet/funds even '
'if you lose your original wallet file, any time in the future. '
'Because Armory uses "deterministic wallets," '
'a single backup when the wallet is first made is sufficient '
'for all future transactions (except ones to imported '
'addresses).\n\n'
'Anyone who gets ahold of your paper backup will be able to spend '
'the money in your wallet, so please secure it appropriately.')
self.btnAccept = QPushButton("Accept")
self.btnCancel = QPushButton("Cancel")
self.btnAdvCrypto = QPushButton("Adv. Encrypt Options>>>")
self.btnAdvCrypto.setCheckable(True)
self.btnbox = QDialogButtonBox()
self.btnbox.addButton(self.btnAdvCrypto, QDialogButtonBox.ActionRole)
self.btnbox.addButton(self.btnCancel, QDialogButtonBox.RejectRole)
self.btnbox.addButton(self.btnAccept, QDialogButtonBox.AcceptRole)
self.connect(self.btnAdvCrypto, SIGNAL('toggled(bool)'), \
self.cryptoFrame, SLOT('setVisible(bool)'))
self.connect(self.btnAccept, SIGNAL('clicked()'), \
self.verifyInputsBeforeAccept)
self.connect(self.btnCancel, SIGNAL('clicked()'), \
self, SLOT('reject()'))
self.btnImportWlt = QPushButton("Import wallet...")
self.connect( self.btnImportWlt, SIGNAL("clicked()"), \
self.importButtonClicked)
masterLayout = QGridLayout()
masterLayout.addWidget(lblDlgDescr, 1, 0, 1, 2)
#masterLayout.addWidget(self.btnImportWlt, 1, 2, 1, 1)
masterLayout.addWidget(lblName, 2, 0, 1, 1)
masterLayout.addWidget(self.edtName, 2, 1, 1, 2)
masterLayout.addWidget(lblDescr, 3, 0, 1, 2)
masterLayout.addWidget(self.edtDescr, 3, 1, 2, 2)
masterLayout.addWidget(self.chkUseCrypto, 5, 0, 1, 1)
masterLayout.addWidget(usecryptoTooltip, 5, 1, 1, 1)
masterLayout.addWidget(self.chkPrintPaper, 6, 0, 1, 1)
masterLayout.addWidget(paperBackupTooltip, 6, 1, 1, 1)
masterLayout.addWidget(self.cryptoFrame, 8, 0, 3, 3)
masterLayout.addWidget(self.btnbox, 11, 0, 1, 2)
masterLayout.setVerticalSpacing(5)
self.setLayout(masterLayout)
self.layout().setSizeConstraint(QLayout.SetFixedSize)
self.connect(self.chkUseCrypto, SIGNAL("clicked()"), \
self.cryptoFrame, SLOT("setEnabled(bool)"))
self.setWindowTitle('Create Armory wallet')
self.setWindowIcon(QIcon( self.main.iconfile))
def importButtonClicked(self):
self.selectedImport = True
self.accept()
def verifyInputsBeforeAccept(self):
### Confirm that the name and descr are within size limits #######
wltName = self.edtName.text()
wltDescr = self.edtDescr.toPlainText()
if len(wltName)<1:
QMessageBox.warning(self, 'Invalid wallet name', \
'You must enter a name for this wallet, up to 32 characters.', \
QMessageBox.Ok)
return False
if len(wltDescr)>256:
reply = QMessageBox.warning(self, 'Input too long', \
'The wallet description is limited to 256 characters. Only the first '
'256 characters will be used.', \
QMessageBox.Ok | QMessageBox.Cancel)
if reply==QMessageBox.Ok:
self.edtDescr.setText( wltDescr[:256])
else:
return False
### Check that the KDF inputs are well-formed ####################
try:
kdfT, kdfUnit = str(self.edtComputeTime.text()).strip().split(' ')
if kdfUnit.lower()=='ms':
self.kdfSec = float(kdfT)/1000.
elif kdfUnit.lower() in ('s', 'sec', 'seconds'):
self.kdfSec = float(kdfT)
if not (self.kdfSec <= 20.0):
QMessageBox.critical(self, 'Invalid KDF Parameters', \
'Please specify a compute time no more than 20 seconds. '
'Values above one second are usually unnecessary.')
return False
kdfM, kdfUnit = str(self.edtComputeMem.text()).split(' ')
if kdfUnit.lower()=='mb':
self.kdfBytes = round(float(kdfM)*(1024.0**2) )
if kdfUnit.lower()=='kb':
self.kdfBytes = round(float(kdfM)*(1024.0))
if not (2**15 <= self.kdfBytes <= 2**31):
QMessageBox.critical(self, 'Invalid KDF Parameters', \
'Please specify a maximum memory usage between 32 kB '
'and 2048 MB.')
return False
LOGINFO('KDF takes %0.2f seconds and %d bytes', self.kdfSec, self.kdfBytes)
except:
QMessageBox.critical(self, 'Invalid Input', \
'Please specify time with units, such as '
'"250 ms" or "2.1 s". Specify memory as kB or MB, such as '
'"32 MB" or "256 kB". ', QMessageBox.Ok)
return False
self.accept()
def getImportWltPath(self):
self.importFile = QFileDialog.getOpenFileName(self, 'Import Wallet File', \
ARMORY_HOME_DIR, 'Wallet files (*.wallet);; All files (*)')
if self.importFile:
self.accept()
################################################################################
class DlgChangePassphrase(ArmoryDialog):
def __init__(self, parent=None, main=None, noPrevEncrypt=True):
super(DlgChangePassphrase, self).__init__(parent, main)
layout = QGridLayout()
if noPrevEncrypt:
lblDlgDescr = QLabel('Please enter an passphrase for wallet encryption.\n\n'
'A good passphrase consists of at least 8 or more\n'
'random letters, or 5 or more random words.\n')
lblDlgDescr.setWordWrap(True)
layout.addWidget(lblDlgDescr, 0, 0, 1, 2)
else:
lblDlgDescr = QLabel("Change your wallet encryption passphrase")
layout.addWidget(lblDlgDescr, 0, 0, 1, 2)
self.edtPasswdOrig = QLineEdit()
self.edtPasswdOrig.setEchoMode(QLineEdit.Password)
self.edtPasswdOrig.setMinimumWidth(MIN_PASSWD_WIDTH(self))
lblCurrPasswd = QLabel('Current Passphrase:')
layout.addWidget(lblCurrPasswd, 1, 0)
layout.addWidget(self.edtPasswdOrig, 1, 1)
lblPwd1 = QLabel("New Passphrase:")
self.edtPasswd1 = QLineEdit()
self.edtPasswd1.setEchoMode(QLineEdit.Password)
self.edtPasswd1.setMinimumWidth(MIN_PASSWD_WIDTH(self))
lblPwd2 = QLabel("Again:")
self.edtPasswd2 = QLineEdit()
self.edtPasswd2.setEchoMode(QLineEdit.Password)
self.edtPasswd2.setMinimumWidth(MIN_PASSWD_WIDTH(self))
layout.addWidget(lblPwd1, 2,0)
layout.addWidget(lblPwd2, 3,0)
layout.addWidget(self.edtPasswd1, 2,1)
layout.addWidget(self.edtPasswd2, 3,1)
self.lblMatches = QLabel(' '*20)
self.lblMatches.setTextFormat(Qt.RichText)
layout.addWidget(self.lblMatches, 4,1)
self.chkDisableCrypt = QCheckBox('Disable encryption for this wallet')
if not noPrevEncrypt:
self.connect(self.chkDisableCrypt, SIGNAL('toggled(bool)'), \
self.disablePassphraseBoxes)
layout.addWidget(self.chkDisableCrypt, 4,0)
self.btnAccept = QPushButton("Accept")
self.btnCancel = QPushButton("Cancel")
buttonBox = QDialogButtonBox()
buttonBox.addButton(self.btnAccept, QDialogButtonBox.AcceptRole)
buttonBox.addButton(self.btnCancel, QDialogButtonBox.RejectRole)
layout.addWidget(buttonBox, 5, 0, 1, 2)
if noPrevEncrypt:
self.setWindowTitle("Set Encryption Passphrase")
else:
self.setWindowTitle("Change Encryption Passphrase")
self.setWindowIcon(QIcon( self.main.iconfile))
self.setLayout(layout)
self.connect(self.edtPasswd1, SIGNAL('textChanged(QString)'), \
self.checkPassphrase)
self.connect(self.edtPasswd2, SIGNAL('textChanged(QString)'), \
self.checkPassphrase)
self.connect(self.btnAccept, SIGNAL('clicked()'), \
self.checkPassphraseFinal)
self.connect(self.btnCancel, SIGNAL('clicked()'), \
self, SLOT('reject()'))
def disablePassphraseBoxes(self, noEncrypt=True):
self.edtPasswd1.setEnabled(not noEncrypt)
self.edtPasswd2.setEnabled(not noEncrypt)
def checkPassphrase(self):
if self.chkDisableCrypt.isChecked():
return True
p1 = self.edtPasswd1.text()
p2 = self.edtPasswd2.text()
goodColor = htmlColor('TextGreen')
badColor = htmlColor('TextRed')
if not isASCII(unicode(p1)) or \
not isASCII(unicode(p2)):
self.lblMatches.setText('<font color=%s><b>Passphrase is non-ASCII!</b></font>' % badColor)
return False
if not p1==p2:
self.lblMatches.setText('<font color=%s><b>Passphrases do not match!</b></font>' % badColor)
return False
if len(p1)<5:
self.lblMatches.setText('<font color=%s><b>Passphrase is too short!</b></font>' % badColor)
return False
self.lblMatches.setText('<font color=%s><b>Passphrases match!</b></font>' % goodColor)
return True
def checkPassphraseFinal(self):
if self.chkDisableCrypt.isChecked():
self.accept()
else:
if self.checkPassphrase():
dlg = DlgPasswd3(self, self.main)
if dlg.exec_():
if not str(dlg.edtPasswd3.text()) == str(self.edtPasswd1.text()):
QMessageBox.critical(self, 'Invalid Passphrase', \
'You entered your confirmation passphrase incorrectly!', QMessageBox.Ok)
else:
self.accept()
else:
self.reject()
class DlgPasswd3(ArmoryDialog):
def __init__(self, parent=None, main=None):
super(DlgPasswd3, self).__init__(parent, main)
lblWarnImgL = QLabel()
lblWarnImgL.setPixmap(QPixmap(':/MsgBox_warning48.png'))
lblWarnImgL.setAlignment(Qt.AlignHCenter | Qt.AlignVCenter)
lblWarnTxt1 = QRichLabel( \
'<font color="red"><b>!!! DO NOT FORGET YOUR PASSPHRASE !!!</b></font>', size=4)
lblWarnTxt1.setAlignment(Qt.AlignHCenter | Qt.AlignVCenter)
lblWarnTxt2 = QRichLabel( \
'<b>No one can help you recover you bitcoins if you forget the '
'passphrase and don\'t have a paper backup!</b> Your wallet and '
'any <u>digital</u> backups are useless if you forget it. '
'<br><br>'
'A <u>paper</u> backup protects your wallet forever, against '
'hard-drive loss and losing your passphrase. It also protects you '
'from theft, if the wallet was encrypted and the paper backup '
'was not stolen with it. Please make a paper backup and keep it in '
'a safe place.'
'<br><br>'
'Please enter your passphrase a third time to indicate that you '
'are aware of the risks of losing your passphrase!</b>', doWrap=True)
self.edtPasswd3 = QLineEdit()
self.edtPasswd3.setEchoMode(QLineEdit.Password)
self.edtPasswd3.setMinimumWidth(MIN_PASSWD_WIDTH(self))
bbox = QDialogButtonBox()
btnOk = QPushButton('Accept')
btnNo = QPushButton('Cancel')
self.connect(btnOk, SIGNAL('clicked()'), self.accept)
self.connect(btnNo, SIGNAL('clicked()'), self.reject)
bbox.addButton(btnOk, QDialogButtonBox.AcceptRole)
bbox.addButton(btnNo, QDialogButtonBox.RejectRole)
layout = QGridLayout()
layout.addWidget(lblWarnImgL, 0, 0, 4, 1)
layout.addWidget(lblWarnTxt1, 0, 1, 1, 1)
layout.addWidget(lblWarnTxt2, 2, 1, 1, 1)
layout.addWidget(self.edtPasswd3, 5, 1, 1, 1)
layout.addWidget(bbox, 6, 1, 1, 2)
self.setLayout(layout)
self.setWindowTitle('WARNING!')
################################################################################
class DlgChangeLabels(ArmoryDialog):
def __init__(self, currName='', currDescr='', parent=None, main=None):
super(DlgChangeLabels, self).__init__(parent, main)
self.edtName = QLineEdit()
self.edtName.setMaxLength(32)
lblName = QLabel("Wallet &name:")
lblName.setBuddy(self.edtName)
self.edtDescr = QTextEdit()
tightHeight = tightSizeNChar(self.edtDescr, 1)[1]
self.edtDescr.setMaximumHeight(tightHeight*4.2)
lblDescr = QLabel("Wallet &description:")
lblDescr.setAlignment(Qt.AlignVCenter)
lblDescr.setBuddy(self.edtDescr)
self.edtName.setText(currName)
self.edtDescr.setText(currDescr)
buttonBox = QDialogButtonBox(QDialogButtonBox.Ok | \
QDialogButtonBox.Cancel)
self.connect(buttonBox, SIGNAL('accepted()'), self.accept)
self.connect(buttonBox, SIGNAL('rejected()'), self.reject)
layout = QGridLayout()
layout.addWidget(lblName, 1, 0, 1, 1)
layout.addWidget(self.edtName, 1, 1, 1, 1)
layout.addWidget(lblDescr, 2, 0, 1, 1)
layout.addWidget(self.edtDescr, 2, 1, 2, 1)
layout.addWidget(buttonBox, 4, 0, 1, 2)
self.setLayout(layout)
self.setWindowTitle('Wallet Descriptions')
def accept(self, *args):
if not isASCII(unicode(self.edtName.text())) or \
not isASCII(unicode(self.edtDescr.toPlainText())):
UnicodeErrorBox(self)
return
if len(str(self.edtName.text()).strip())==0:
QMessageBox.critical(self, 'Empty Name', \
'All wallets must have a name. ', QMessageBox.Ok)
return
super(DlgChangeLabels, self).accept(*args)
################################################################################
class DlgWalletDetails(ArmoryDialog):
""" For displaying the details of a specific wallet, with options """
#############################################################################
def __init__(self, wlt, usermode=USERMODE.Standard, parent=None, main=None):
super(DlgWalletDetails, self).__init__(parent, main)
self.setAttribute(Qt.WA_DeleteOnClose)
self.wlt = wlt
self.usermode = usermode
self.wlttype, self.typestr = determineWalletType(wlt, parent)
if self.typestr=='Encrypted':
self.typestr='Encrypted (AES256)'
self.labels = [wlt.labelName, wlt.labelDescr]
self.passphrase = ''
self.setMinimumSize(800,400)
w,h = relaxedSizeNChar(self,60)
viewWidth,viewHeight = w, 10*h
# Address view
self.wltAddrModel = WalletAddrDispModel(wlt, self)
self.wltAddrProxy = WalletAddrSortProxy(self)
self.wltAddrProxy.setSourceModel(self.wltAddrModel)
self.wltAddrView = QTableView()
self.wltAddrView.setModel(self.wltAddrProxy)
self.wltAddrView.setSortingEnabled(True)
self.wltAddrView.setSelectionBehavior(QTableView.SelectRows)
self.wltAddrView.setSelectionMode(QTableView.SingleSelection)
self.wltAddrView.horizontalHeader().setStretchLastSection(True)
self.wltAddrView.verticalHeader().setDefaultSectionSize(20)
self.wltAddrView.setMinimumWidth(550)
self.wltAddrView.setMinimumHeight(150)
iWidth = tightSizeStr(self.wltAddrView, 'Imp')[0]
initialColResize(self.wltAddrView, [iWidth*1.5, 0.35, 0.4, 64, 0.2])
self.wltAddrView.sizeHint = lambda: QSize(700, 225)
self.wltAddrView.setSizePolicy(QSizePolicy.Preferred, QSizePolicy.Expanding)
self.wltAddrView.setContextMenuPolicy(Qt.CustomContextMenu)
self.wltAddrView.customContextMenuRequested.connect(self.showContextMenu)
self.wltAddrProxy.sort(ADDRESSCOLS.ChainIdx, Qt.AscendingOrder)
uacfv = lambda x: self.main.updateAddressCommentFromView(self.wltAddrView, self.wlt)
self.connect(self.wltAddrView, SIGNAL('doubleClicked(QModelIndex)'), \
self.dblClickAddressView)
# Now add all the options buttons, dependent on the type of wallet.
lbtnChangeLabels = QLabelButton('Change Wallet Labels');
self.connect(lbtnChangeLabels, SIGNAL('clicked()'), self.changeLabels)
if not self.wlt.watchingOnly:
s = ''
if self.wlt.useEncryption:
s = 'Change or Remove Passphrase'
else:
s = 'Encrypt Wallet'
lbtnChangeCrypto = QLabelButton(s)
self.connect(lbtnChangeCrypto, SIGNAL('clicked()'), self.changeEncryption)
lbtnSendBtc = QLabelButton('Send Bitcoins')
lbtnGenAddr = QLabelButton('Receive Bitcoins')
lbtnImportA = QLabelButton('Import/Sweep Private Keys')
lbtnDeleteA = QLabelButton('Remove Imported Address')
#lbtnSweepA = QLabelButton('Sweep Wallet/Address')
lbtnForkWlt = QLabelButton('Create Watching-Only Copy')
lbtnBackups = QLabelButton('<b>Backup This Wallet</b>')
lbtnRemove = QLabelButton('Delete/Remove Wallet')
#LOGERROR('remove me!')
#fnfrag = lambda: DlgFragBackup(self, self.main, self.wlt).exec_()
#LOGERROR('remove me!')
self.connect(lbtnSendBtc, SIGNAL('clicked()'), self.execSendBtc)
self.connect(lbtnGenAddr, SIGNAL('clicked()'), self.getNewAddress)
self.connect(lbtnBackups, SIGNAL('clicked()'), self.execBackupDlg)
#self.connect(lbtnBackups, SIGNAL('clicked()'), fnfrag)
self.connect(lbtnRemove, SIGNAL('clicked()'), self.execRemoveDlg)
self.connect(lbtnImportA, SIGNAL('clicked()'), self.execImportAddress)
self.connect(lbtnDeleteA, SIGNAL('clicked()'), self.execDeleteAddress)
self.connect(lbtnForkWlt, SIGNAL('clicked()'), self.forkOnlineWallet)
lbtnSendBtc.setToolTip('<u></u>Send bitcoins to other users, or transfer '
'between wallets')
if self.wlt.watchingOnly:
lbtnSendBtc.setToolTip('<u></u>If you have a full-copy of this wallet '
'on another computer, you can prepare a '
'transaction, to be signed by that computer.')
lbtnGenAddr.setToolTip('<u></u>Get a new address from this wallet for receiving '
'bitcoins. Right click on the address list below '
'to copy an existing address.')
lbtnImportA.setToolTip('<u></u>Import or "Sweep" an address which is not part '
'of your wallet. Useful for VanityGen addresses '
'and redeeming Casascius physical bitcoins.')
lbtnDeleteA.setToolTip('<u></u>Permanently delete an imported address from '
'this wallet. You cannot delete addresses that '
'were generated natively by this wallet.')
#lbtnSweepA .setToolTip('')
lbtnForkWlt.setToolTip('<u></u>Save a copy of this wallet that can only be used '
'for generating addresses and monitoring incoming '
'payments. A watching-only wallet cannot spend '
'the funds, and thus cannot be compromised by an '
'attacker')
lbtnBackups.setToolTip('<u></u>See lots of options for backing up your wallet '
'to protect the funds in it.')
lbtnRemove.setToolTip('<u></u>Permanently delete this wallet, or just delete '
'the private keys to convert it to a watching-only '
'wallet.')
if not self.wlt.watchingOnly:
lbtnChangeCrypto.setToolTip('<u></u>Add/Remove/Change wallet encryption settings.')
optFrame = QFrame()
optFrame.setFrameStyle(STYLE_SUNKEN)
optLayout = QVBoxLayout()