forked from etotheipi/BitcoinArmory
-
Notifications
You must be signed in to change notification settings - Fork 0
/
qtdialogs.py
executable file
·7834 lines (6283 loc) · 314 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-2012, Alan C. Reiner <[email protected]>
# Distributed under the GNU Affero General Public License (AGPL v3)
# See LICENSE or http://www.gnu.org/licenses/agpl.html
#
################################################################################
import sys
from PyQt4.QtCore import *
from PyQt4.QtGui import *
from qtdefines import *
from armoryengine import *
from armorymodels import *
import qrc_img_resources
MIN_PASSWD_WIDTH = lambda obj: tightSizeStr(obj, '*'*16)[0]
################################################################################
class DlgUnlockWallet(QDialog):
def __init__(self, wlt, parent=None, main=None, unlockMsg='Unlock Wallet'):
super(DlgUnlockWallet, self).__init__(parent)
self.wlt = wlt
self.parent = parent
self.main = main
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)
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(unlockMsg + ' - ' + wlt.uniqueIDB58)
def acceptPassphrase(self):
securePwd = SecureBinaryData(str(self.edtPasswd.text()))
try:
self.wlt.unlock(securePassphrase=securePwd)
self.accept()
except PassphraseError:
QMessageBox.critical(self, 'Invalid Passphrase', \
'That passphrase is not correct!', QMessageBox.Ok)
self.edtPasswd.setText('')
return
################################################################################
class DlgGenericGetPassword(QDialog):
def __init__(self, descriptionStr, parent=None, main=None):
super(DlgGenericGetPassword, self).__init__(parent)
self.parent = parent
self.main = 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(QDialog):
def __init__(self, parent=None, main=None, initLabel=''):
super(DlgNewWallet, self).__init__(parent)
self.parent = parent
self.main = 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 = createToolTipObject(
'This is the amount of time it will take for your computer '
'to unlock your wallet after you enter your passphrase. '
'(the actual time will be between T/2 and T). ')
# Set maximum compute time
self.edtComputeTime = QLineEdit()
self.edtComputeTime.setText('250 ms')
self.edtComputeTime.setMaxLength(12)
lblComputeTime = QLabel('Target compute &time (s, ms):')
memDescrTip = createToolTipObject(
'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] )
#self.chkForkOnline = QCheckBox('Create an "&online" copy of this wallet')
#onlineToolTip = createToolTipObject(
#'An "online" wallet is a copy of your primary wallet, but '
#'without any sensitive data that would allow an attacker to '
#'obtain access to your funds. An "online" wallet can '
#'generate new addresses and verify incoming payments '
#'but cannot be used to spend any of the funds.')
# 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)
#cryptoLayout.addWidget(self.chkForkOnline, 3, 0, 1, 1)
#cryptoLayout.addWidget(onlineToolTip, 3, 1, 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 = createToolTipObject(
'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")
paperBackupTooltip = createToolTipObject(
'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/Import 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)
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)
print 'KDF takes', self.kdfSec, 'sec and', self.kdfBytes, 'bytes'
except:
QMessageBox.critical(self, 'Invalid KDF Parameters', \
'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:
print self.importFile
self.accept()
################################################################################
class DlgChangePassphrase(QDialog):
def __init__(self, parent=None, main=None, noPrevEncrypt=True):
super(DlgChangePassphrase, self).__init__(parent)
self.parent = parent
self.main = 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()
if not p1==p2:
self.lblMatches.setText('<font color="red"><b>Passphrases do not match!</b></font>')
return False
if len(p1)<5:
self.lblMatches.setText('<font color="red"><b>Passphrase is too short!</b></font>')
return False
self.lblMatches.setText('<font color="green"><b>Passphrases match!</b></font>')
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(QDialog):
def __init__(self, parent=None, main=None):
super(DlgPasswd3, self).__init__(parent)
self.parent = parent
self.main = main
lblWarnImg = QLabel()
lblWarnImg.setPixmap(QPixmap(':/MsgBox_warning48.png'))
lblWarnImg.setAlignment(Qt.AlignHCenter | Qt.AlignVCenter)
lblWarnTxt1 = QLabel( '<b>!!! DO NOT FORGET YOUR PASSPHRASE !!!</b>')
lblWarnTxt1.setAlignment(Qt.AlignHCenter | Qt.AlignVCenter)
lblWarnTxt2 = QLabel( \
'Bitcoin Armory wallet encryption is designed to be extremely difficult to '
'crack, even with GPU-acceleration. No one can help you recover your coins '
'if you forget your passphrase, not even the developers of this software. '
'If you are inclined to forget your passphrase, please write it down '
'or print a paper backup of your wallet and keep it in a secure location. ')
lblWarnTxt2.setTextFormat(Qt.RichText)
lblWarnTxt3 = QLabel( \
'If you are sure you will remember it, you will have no problem '
'typing it a third time to acknowledge '
'you understand the consequences of losing your passphrase.')
lblWarnTxt2.setWordWrap(True)
lblWarnTxt3.setWordWrap(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(lblWarnImg, 0, 0, 4, 1)
layout.addWidget(lblWarnTxt1, 0, 1, 1, 1)
layout.addWidget(lblWarnTxt2, 2, 1, 1, 1)
layout.addWidget(lblWarnTxt3, 4, 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(QDialog):
def __init__(self, currName='', currDescr='', parent=None, main=None):
super(DlgChangeLabels, self).__init__(parent)
self.parent = parent
self.main = 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')
################################################################################
class DlgWalletDetails(QDialog):
""" 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)
self.setAttribute(Qt.WA_DeleteOnClose)
self.wlt = wlt
self.usermode = usermode
self.parent = parent
self.main = main
self.wlttype, self.typestr = determineWalletType(wlt, parent)
self.labels = [wlt.labelName, wlt.labelDescr]
self.passphrase = ''
self.setMinimumSize(800,400)
w,h = relaxedSizeNChar(self,60)
viewWidth,viewHeight = w, 10*h
# Address view
lblAddrList = QLabel('Addresses in Wallet:')
self.wltAddrModel = WalletAddrDispModel(wlt, self)
self.wltAddrView = QTableView()
self.wltAddrView.setModel(self.wltAddrModel)
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, 'Imported')[0]
initialColResize(self.wltAddrView, [0.4, 0.45, 64, iWidth*1.3, 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)
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')
if self.wlt.watchingOnly:
lbtnSendBtc = QLabelButton('Prepare Offline Transaction')
lbtnGenAddr = QLabelButton('Receive Bitcoins')
lbtnImportA = QLabelButton('Import Private Key')
lbtnDeleteA = QLabelButton('Remove Imported Address')
#lbtnSweepA = QLabelButton('Sweep Wallet/Address')
lbtnForkWlt = QLabelButton('Create Watching-Only Copy')
lbtnMkPaper = QLabelButton('Make Paper Backup')
lbtnVwKeys = QLabelButton('Backup Individual Keys')
lbtnExport = QLabelButton('Make Digital Backup')
lbtnRemove = QLabelButton('Delete/Remove Wallet')
lbtnUnspent = QLabelButton('View unspent transactions')
self.connect(lbtnSendBtc, SIGNAL('clicked()'), self.execSendBtc)
self.connect(lbtnGenAddr, SIGNAL('clicked()'), self.getNewAddress)
self.connect(lbtnMkPaper, SIGNAL('clicked()'), self.execPrintDlg)
self.connect(lbtnVwKeys, SIGNAL('clicked()'), self.execKeyList)
self.connect(lbtnRemove, SIGNAL('clicked()'), self.execRemoveDlg)
self.connect(lbtnImportA, SIGNAL('clicked()'), self.execImportAddress)
self.connect(lbtnDeleteA, SIGNAL('clicked()'), self.execDeleteAddress)
self.connect(lbtnExport, SIGNAL('clicked()'), self.saveWalletCopy)
self.connect(lbtnForkWlt, SIGNAL('clicked()'), self.forkOnlineWallet)
optFrame = QFrame()
optFrame.setFrameStyle(STYLE_SUNKEN)
optLayout = QVBoxLayout()
hasPriv = not self.wlt.watchingOnly
adv = (self.main.usermode in (USERMODE.Advanced, USERMODE.Developer))
def createVBoxSeparator():
frm = QFrame()
frm.setFrameStyle(QFrame.HLine | QFrame.Plain)
return frm
if True: optLayout.addWidget(lbtnSendBtc)
if True: optLayout.addWidget(lbtnGenAddr)
if hasPriv: optLayout.addWidget(lbtnChangeCrypto)
if True: optLayout.addWidget(lbtnChangeLabels)
if True: optLayout.addWidget(createVBoxSeparator())
if hasPriv: optLayout.addWidget(lbtnMkPaper)
if True: optLayout.addWidget(lbtnVwKeys)
if True: optLayout.addWidget(lbtnExport)
if hasPriv and adv: optLayout.addWidget(lbtnForkWlt)
if True: optLayout.addWidget(lbtnRemove)
if hasPriv and adv: optLayout.addWidget(createVBoxSeparator())
if hasPriv and adv: optLayout.addWidget(lbtnImportA)
if hasPriv and adv: optLayout.addWidget(lbtnDeleteA)
#if hasPriv and adv: optLayout.addWidget(lbtnSweepA)
optLayout.addStretch()
optFrame.setLayout(optLayout)
btnGoBack = QPushButton('<<< Go Back')
self.connect(btnGoBack, SIGNAL('clicked()'), self.accept)
self.frm = QFrame()
self.setWltDetailsFrame()
totalFunds = self.wlt.getBalance('Total')
spendFunds = self.wlt.getBalance('Spendable')
unconfFunds= self.wlt.getBalance('Unconfirmed')
uncolor = 'red' if unconfFunds>0 else 'black'
btccolor = '#999999' if spendFunds==totalFunds else 'green'
lblcolor = '#999999' if spendFunds==totalFunds else 'black'
lblTot = QRichLabel('<b><font color="%s">Maximum Funds:</font></b>'%lblcolor, doWrap=False);
lblSpd = QRichLabel('<b>Spendable Funds:</b>', doWrap=False);
lblUcn = QRichLabel('<b>Unconfirmed:</b>', doWrap=False);
totStr = '<b><font color="%s">%s</font></b>' % (btccolor, coin2str(totalFunds))
spdStr = '<b><font color="green">%s</font></b>' % (coin2str(spendFunds))
ucnStr = '<b><font color="%s">%s</font></b>' % (uncolor,coin2str(unconfFunds))
lblTotalFunds = QRichLabel(totStr, doWrap=False)
lblSpendFunds = QRichLabel(spdStr, doWrap=False)
lblUnconfFunds = QRichLabel(ucnStr, doWrap=False)
lblTotalFunds.setAlignment(Qt.AlignRight | Qt.AlignVCenter)
lblSpendFunds.setAlignment(Qt.AlignRight | Qt.AlignVCenter)
lblUnconfFunds.setAlignment(Qt.AlignRight | Qt.AlignVCenter)
lblTot.setAlignment(Qt.AlignRight | Qt.AlignVCenter)
lblSpd.setAlignment(Qt.AlignRight | Qt.AlignVCenter)
lblUcn.setAlignment(Qt.AlignRight | Qt.AlignVCenter)
lblBTC1 = QRichLabel('<b><font color="%s">BTC</font></b>'%lblcolor, doWrap=False)
lblBTC2 = QRichLabel('<b>BTC</b>', doWrap=False)
lblBTC3 = QRichLabel('<b>BTC</b>', doWrap=False)
ttipTot = createToolTipObject( \
'Total funds if all current transactions are confirmed. '
'Value appears gray when it is the same as your spendable funds.')
ttipSpd = createToolTipObject( 'Funds that can be spent <i>right now</i>')
ttipUcn = createToolTipObject( 'Funds that have less than 6 confirmations' )
frmTotals = QFrame()
frmTotals.setFrameStyle(STYLE_NONE)
frmTotalsLayout = QGridLayout()
frmTotalsLayout.addWidget(lblTot, 0,0)
frmTotalsLayout.addWidget(lblSpd, 1,0)
frmTotalsLayout.addWidget(lblUcn, 2,0)
frmTotalsLayout.addWidget(lblTotalFunds, 0,1)
frmTotalsLayout.addWidget(lblSpendFunds, 1,1)
frmTotalsLayout.addWidget(lblUnconfFunds, 2,1)
frmTotalsLayout.addWidget(lblBTC1, 0,2)
frmTotalsLayout.addWidget(lblBTC2, 1,2)
frmTotalsLayout.addWidget(lblBTC3, 2,2)
frmTotalsLayout.addWidget(ttipTot, 0,3)
frmTotalsLayout.addWidget(ttipSpd, 1,3)
frmTotalsLayout.addWidget(ttipUcn, 2,3)
# Temp disable unconf display until calc is fixed
#lblUcn.setVisible(False)
#lblUnconfFunds.setVisible(False)
#lblBTC3.setVisible(False)
#ttipUcn.setVisible(False)
frmTotals.setLayout(frmTotalsLayout)
lblWltAddr = QRichLabel('<b>Addresses in Wallet:</b>')
layout = QGridLayout()
layout.addWidget(self.frm, 0, 0, 3, 4)
layout.addWidget(lblWltAddr, 4, 0, 1, 4)
layout.addWidget(self.wltAddrView, 5, 0, 2, 4)
layout.addWidget(btnGoBack, 7, 0, 2, 1)
layout.addWidget(frmTotals, 7, 3, 2, 1)
layout.addWidget(QLabel("Available Actions:"), \
0, 4)
layout.addWidget(optFrame, 1, 4, 9, 2)
self.setLayout(layout)
self.setWindowTitle('Wallet Properties')
#############################################################################
def showContextMenu(self, pos):
menu = QMenu(self.wltAddrView)
std = (self.main.usermode==USERMODE.Standard)
adv = (self.main.usermode==USERMODE.Advanced)
dev = (self.main.usermode==USERMODE.Developer)
if True: actionCopyAddr = menu.addAction("Copy Address")
if dev: actionCopyHash160 = menu.addAction("Copy Hash160")
if True: actionCopyComment = menu.addAction("Copy Comment")
if True: actionCopyBalance = menu.addAction("Copy Balance")
idx = self.wltAddrView.selectedIndexes()[0]
action = menu.exec_(QCursor.pos())
if action==actionCopyAddr:
s = self.wltAddrView.model().index(idx.row(), ADDRESSCOLS.Address).data().toString()
elif dev and action==actionCopyHash160:
s = str(self.wltAddrView.model().index(idx.row(), ADDRESSCOLS.Address).data().toString())
s = binary_to_hex(addrStr_to_hash160(s))
elif action==actionCopyComment:
s = self.wltAddrView.model().index(idx.row(), ADDRESSCOLS.Comment).data().toString()
elif action==actionCopyBalance:
s = self.wltAddrView.model().index(idx.row(), ADDRESSCOLS.Balance).data().toString()
else:
return
clipb = QApplication.clipboard()
clipb.clear()
clipb.setText(str(s).strip())
#############################################################################
def dblClickAddressView(self, index):
model = index.model()
if index.column()==ADDRESSCOLS.Comment:
self.main.updateAddressCommentFromView(self.wltAddrView, self.wlt)
else:
addrStr = str(index.model().index(index.row(), ADDRESSCOLS.Address).data().toString())
dlg = DlgAddressInfo(self.wlt, addrStr_to_hash160(addrStr), self, self.main)
dlg.exec_()
#############################################################################
def changeLabels(self):
dlgLabels = DlgChangeLabels(self.wlt.labelName, self.wlt.labelDescr, self, self.main)
if dlgLabels.exec_():
# Make sure to use methods like this which not only update in memory,
# but guarantees the file is updated, too
newName = str(dlgLabels.edtName.text())
newDescr = str(dlgLabels.edtDescr.toPlainText())
self.wlt.setWalletLabels(newName, newDescr)
#self.setWltDetailsFrame()
self.labelValues[WLTFIELDS.Name].setText(newName)
self.labelValues[WLTFIELDS.Descr].setText(newDescr)
#############################################################################
def changeEncryption(self):
dlgCrypt = DlgChangePassphrase(self, self.main, not self.wlt.useEncryption)
if dlgCrypt.exec_():
self.disableEncryption = dlgCrypt.chkDisableCrypt.isChecked()
newPassphrase = SecureBinaryData(str(dlgCrypt.edtPasswd1.text()))
if self.wlt.useEncryption:
origPassphrase = SecureBinaryData(str(dlgCrypt.edtPasswdOrig.text()))
if self.wlt.verifyPassphrase(origPassphrase):
self.wlt.unlock(securePassphrase=origPassphrase)
else:
# Even if the wallet is already unlocked, enter pwd again to change it
QMessageBox.critical(self, 'Invalid Passphrase', \
'Previous passphrase is not correct! Could not unlock wallet.', \
QMessageBox.Ok)
if self.disableEncryption:
self.wlt.changeWalletEncryption(None, None)
#self.accept()
self.labelValues[WLTFIELDS.Secure].setText('No Encryption')
self.labelValues[WLTFIELDS.Crypto].setText('None')
self.labelValues[WLTFIELDS.Secure].setText('')
self.labelValues[WLTFIELDS.Secure].setText('')
else:
if not self.wlt.useEncryption:
kdfParams = self.wlt.computeSystemSpecificKdfParams(0.2)
self.wlt.changeKdfParams(*kdfParams)
self.wlt.changeWalletEncryption(securePassphrase=newPassphrase)
self.labelValues[WLTFIELDS.Secure].setText('Encrypted')
#self.accept()
def getNewAddress(self):
if showWatchOnlyRecvWarningIfNecessary(self.wlt, self.main):
DlgNewAddressDisp(self.wlt, self, self.main).exec_()
def execSendBtc(self):
dlgSend = DlgSendBitcoins(self.wlt, self, self.main)
dlgSend.exec_()
def changeKdf(self):
"""
This is a low-priority feature. I mean, the PyBtcWallet class has this
feature implemented, but I don't have a GUI for it
"""
pass
def execPrintDlg(self):
if self.wlt.isLocked:
unlockdlg = DlgUnlockWallet(self.wlt, self, self.main, 'Create Paper Backup')
if not unlockdlg.exec_():
return
if not self.wlt.addrMap['ROOT'].hasPrivKey():
QMessageBox.warning(self, 'Move along...', \
'This wallet does not contain any private keys. Nothing to backup!', QMessageBox.Ok)
return
dlg = DlgPaperBackup(self.wlt, self, self.main)
dlg.exec_()
def execRemoveDlg(self):
dlg = DlgRemoveWallet(self.wlt, self, self.main)
if dlg.exec_():
pass # not sure that I don't handle everything in the dialog itself
def execKeyList(self):
dlg = DlgShowKeyList(self.wlt, self, self.main)
dlg.exec_()
def execDeleteAddress(self):
selectedList = self.wltAddrView.selectedIndexes()
if len(selectedList)==0:
QMessageBox.warning(self, 'No Selection', \
'You must select an address to remove!', \
QMessageBox.Ok)
return
row = selectedList[0].row()
addrStr = str(self.wltAddrView.model().index(row, ADDRESSCOLS.Address).data().toString())
addr160 = addrStr_to_hash160(addrStr)
if self.wlt.addrMap[addr160].chainIndex==-2:
dlg = DlgRemoveAddress(self.wlt, addr160, self, self.main)
dlg.exec_()
else:
QMessageBox.warning(self, 'Invalid Selection', \
'You cannot delete addresses generated by your wallet. '
'Only imported addresses can be deleted.', \
QMessageBox.Ok)
return
def execImportAddress(self):
if not self.main.settings.getSettingOrSetDefault('DNAA_ImportWarning', False):
result = MsgBoxWithDNAA(MSGBOX.Warning, 'Import Address Warning', \
'Armory supports importing of external '
'addresses into your wallet, including encryption, '
'but imported addresses <b>cannot</b> be protected/saved '
'by a paper backups. Watching-only wallets will include '
'imported addresses if the watching-only wallet was '
'created after the address was imported.', None)
self.main.settings.set('DNAA_ImportWarning', result[1])
# Now we are past the [potential] warning box. Actually open
# The import dialog, now
dlg = DlgImportAddress(self.wlt, self, self.main)
dlg.exec_()
def saveWalletCopy(self):
fn = 'armory_%s_.wallet' % self.wlt.uniqueIDB58
if self.wlt.watchingOnly:
fn = 'armory_%s.watchonly.wallet' % self.wlt.uniqueIDB58
savePath = self.main.getFileSave(defaultFilename=fn)
if len(savePath)>0:
self.wlt.writeFreshWalletFile(savePath)
self.main.statusBar
self.main.statusBar().showMessage( \
'Successfully copied wallet to ' + savePath, 10000)
def forkOnlineWallet(self):
currPath = self.wlt.walletPath
pieces = os.path.splitext(currPath)
currPath = pieces[0] + '.watchonly' + pieces[1]
saveLoc = self.main.getFileSave('Save Watching-Only Copy',\
defaultFilename=currPath)
if not saveLoc.endswith('.wallet'):
saveLoc += '.wallet'
self.wlt.forkOnlineWallet(saveLoc, self.wlt.labelName, \
'(Watching-Only) ' + self.wlt.labelDescr)
# A possible way to remove an existing layout
#def setLayout(self, layout):
#self.clearLayout()
#QWidget.setLayout(self, layout)
#
#def clearLayout(self):
#if self.layout() is not None:
#old_layout = self.layout()
#for i in reversed(range(old_layout.count())):
#old_layout.itemAt(i).widget().setParent(None)
#import sip
#sip.delete(old_layout)
#############################################################################
def setWltDetailsFrame(self):
dispCrypto = self.wlt.useEncryption and (self.usermode==USERMODE.Advanced or \
self.usermode==USERMODE.Developer)
self.wltID = self.wlt.uniqueIDB58
if dispCrypto:
kdftimestr = "%0.3f seconds" % self.wlt.testKdfComputeTime()
mem = self.wlt.kdf.getMemoryReqtBytes()
kdfmemstr = str(mem/1024)+' kB'
if mem >= 1024*1024:
kdfmemstr = str(mem/(1024*1024))+' MB'
tooltips = [[]]*9
tooltips[WLTFIELDS.Name] = createToolTipObject(
'This is the name stored with the wallet file. Click on the '
'"Change Labels" button at the bottom of this '
'window to change this field' )
tooltips[WLTFIELDS.Descr] = createToolTipObject(
'This is the description of the wallet stored in the wallet file. '
'Press the "Change Labels" button at the bottom of this '
'window to change this field' )
tooltips[WLTFIELDS.WltID] = createToolTipObject(
'This is a unique identifier for this wallet, based on the root key. '
'No other wallet can have the same ID '
'unless it is a copy of this one, regardless of whether '
'the name and description match.')
tooltips[WLTFIELDS.NumAddr] = createToolTipObject(
'The number of addresses generated so far for this wallet. '
'This includes addresses imported manually')