forked from morelo-network/Morelo-GUI
-
Notifications
You must be signed in to change notification settings - Fork 0
/
MRL-GUI-Wallet.py
1588 lines (1477 loc) · 59.1 KB
/
MRL-GUI-Wallet.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
import version
missingLibs = False
try:
import math
except:
pass
print('ERROR: Missing module, try install it by command: python -m pip install math')
missingLibs = True
try:
import io
except:
pass
print('ERROR: Missing module, try install it by command: python -m pip install io')
missingLibs = True
try:
import time
except:
pass
print('ERROR: Missing module, try install it by command: python -m pip install time')
missingLibs = True
try:
import datetime
except:
pass
print('ERROR: Missing module, try install it by command: python -m pip install datetime')
missingLibs = True
try:
import pathlib
except:
pass
print('ERROR: Missing module, try install it by command: python -m pip install pathlib')
missingLibs = True
try:
import sys
except:
pass
print('ERROR: Missing module, try install it by command: python -m pip install sys')
missingLibs = True
try:
import json
except:
pass
print('ERROR: Missing module, try install it by command: python -m pip install json')
missingLibs = True
try:
import threading
except:
pass
print('ERROR: Missing module, try install it by command: python -m pip install threading')
missingLibs = True
try:
from subprocess import run, Popen, PIPE, DEVNULL
except:
pass
print('ERROR: Missing module, try install it by command: python -m pip install subprocess')
missingLibs = True
try:
import configparser
except:
pass
print('ERROR: Missing module, try install it by command: python -m pip install configparser')
missingLibs = True
try:
from psutil import NoSuchProcess, AccessDenied, ZombieProcess, process_iter
except:
pass
print('ERROR: Missing module, try install it by command: python -m pip install psutil')
missingLibs = True
try:
from time import sleep
except:
pass
print('ERROR: Missing module, try install it by command: python -m pip install time')
missingLibs = True
try:
from tkinter import Tk, filedialog
except:
pass
print('ERROR: Missing module, try install it by command: python -m pip install tkinter')
missingLibs = True
try:
from random import choice
except:
pass
print('ERROR: Missing module, try install it by command: python -m pip install random')
missingLibs = True
try:
import string
except:
pass
print('ERROR: Missing module, try install it by command: python -m pip install string')
missingLibs = True
try:
import queue
except:
pass
print('ERROR: Missing module, try install it by command: python -m pip install queue')
missingLibs = True
try:
import os
except:
pass
print('ERROR: Missing module, try install it by command: python -m pip install os')
missingLibs = True
try:
import requests
except:
pass
print('ERROR: Missing module, try install it by command: python -m pip install requests')
missingLibs = True
try:
import pyperclip
except:
pass
print('ERROR: Missing module, try install it by command: python -m pip install pyperclip')
missingLibs = True
try:
import image
except:
pass
print('ERROR: Missing module, try install it by command: python -m pip install image')
missingLibs = True
try:
from PyQt5.QtWidgets import *
from PyQt5.QtGui import *
from PyQt5.QtCore import *
except:
pass
print('ERROR: Missing module, try install it by command: python -m pip install PyQt5')
missingLibs = True
if missingLibs:
sleep(5)
sys.exit()
#qrCode module is optional
noQR = False
try:
import qrcode
except:
noQR = True
print('INFO: QRCode module not found, running without it')
#time measurment
def TimerInit():
return int(round(time.time() * 1000))
def TimerDiff(hTimer):
return int(round(time.time() * 1000)) - hTimer
def randomString(stringLength=10):
letters = string.ascii_lowercase
return ''.join(choice(letters) for i in range(stringLength))
#Checking process exists
def ProcessExists(processName):
for proc in process_iter():
try:
if processName.lower() in proc.name().lower():
return True
except (NoSuchProcess, AccessDenied, ZombieProcess):
pass
return False
#closing process by name
def ProcessClose(processName):
for proc in process_iter():
try:
if processName.lower() in proc.name().lower():
proc.kill()
except (NoSuchProcess, AccessDenied, ZombieProcess):
pass
return False
#updating controls (widgets) style
def GUICtrlUpdateStyle(control):
style = control.type + '''#''' + control.objectName() + ''' {
font-size: ''' + control.myfontsize + ''';
font-weight: ''' + control.myfontweight + ''';
background: ''' + control.mybackgroundcolor + ''';
color: ''' + control.mycolor + ''';
border: ''' + control.myborder + ''';
}
'''
if control.type == 'QLineEdit':
style += control.type + '''#''' + control.objectName() + ''' {
padding: 0px 5px 0px 5px;
}
'''
if control.type == 'QPushButton':
style += control.type + '''#''' + control.objectName() + ''':hover {
background: ''' + control.myhoverbackgroundcolor + ''';
color: ''' + control.myhovercolor + ''';
}
'''
control.setStyleSheet(style)
initStyle = '''
QPushButton {
background: rgba(255, 255, 255, 15%);
color: rgb(26, 188, 156);
border-radius: 50%;
font-size: 22px;
}
QPushButton:hover {
background: rgba(26, 188, 156, 50%);
color: white;
}
'''
#modyfing controls (widgets) style attributes
def GUICtrlSetBkColor(control, color):
control.mybackgroundcolor = color
GUICtrlUpdateStyle(control)
def GUICtrlSetHoverBkColor(control, color):
control.myhoverbackgroundcolor = color
GUICtrlUpdateStyle(control)
def GUICtrlSetFontWeight(control, weight):
control.myfontweight = weight
GUICtrlUpdateStyle(control)
def GUICtrlSetColor(control, color):
control.mycolor = color
GUICtrlUpdateStyle(control)
def GUICtrlSetFontSize(control, size):
control.myfontsize = size
GUICtrlUpdateStyle(control)
#validating amount is propertly formatted
def ValidAmount(szAmount):
szChrset = "0123456789."
for iChr in range(0, len(szAmount), 1):
if not szAmount[iChr] in szChrset:
return 0
return 1
def find_str(s, char):
index = 0
if char in s:
c = char[0]
for ch in s:
if ch == c:
if s[index:index+len(char)] == char:
return index
index += 1
return -1
def SendTransaction(receiver, amount, pay_id):
response = requests.post('http://127.0.0.1:38420/json_rpc', data='{"jsonrpc":"2.0","id":"0","method":"transfer","params":{"destinations":[{"amount":' + str(int(amount * 1000000000)) +',"address":"' + receiver +'"}]}}', headers={'Content-Type':'application/json'})
return json.loads(response.text)
def GetWalletBalance():
response = -1
try:
response = requests.post('http://127.0.0.1:38420/json_rpc', data='{"jsonrpc":"2.0","id":"0","method":"get_balance","params":{"account_index":0}', headers={'Content-Type':'application/json'})
response = json.loads(response.text)
except:
pass
return response
def GetWalletAddress():
response = False
try:
response = requests.post('http://127.0.0.1:38420/json_rpc', data='{"jsonrpc":"2.0","id":"0","method":"get_address","params":{"account_index":0}', headers={'Content-Type':'application/json'})
response = json.loads(response.text)
except:
pass
return response
def GetWalletTransactions(start, count):
transactions = []
response = requests.post('http://127.0.0.1:38420/json_rpc', data='{"jsonrpc":"2.0","id":"0","method":"get_transfers","params":{"filter_by_height":true, "pending":true, "in":true, "out":true, "min_height":' + str(start) + ', "max_height":' + str(start + count) +'}}', headers={'Content-Type':'application/json'})
data = json.loads(response.text)
if 'in' in data['result']:
for block in data['result']['in']:
transactions.append(block['txid'])
if 'out' in data['result']:
for block in data['result']['out']:
transactions.append(block['txid'])
#else:
# print("ERROR: Can't get transaction list")
# print(data)
return transactions
def GetTransactionInfo(hash):
response = requests.post('http://127.0.0.1:38420/json_rpc',data='{"jsonrpc":"2.0","id":"0","method":"get_transfer_by_txid","params":{"txid":"' + hash + '"}}', headers={'Content-Type':'application/json'})
return json.loads(response.text)
class Worker(QRunnable):
def __init__(self, fn, *args, **kwargs):
super(Worker, self).__init__()
self.fn = fn
@pyqtSlot()
def run(self):
self.fn()
#Main window class
class App(QWidget):
addTx = pyqtSignal(list)
sortTx = pyqtSignal()
def __init__(self):
#initial values for some variables
super().__init__()
self.threadpool = QThreadPool()
self.ctrlCount = 0
self.walletRPC = 0
self.xi_daemon = 0
self.XiNetworkState, self.walletBalance, self.walletBalanceLocked = 0, 0, 0
self.wallet_address = ''
self.wallet_keys = {'view' : '', 'spend' : '', 'seed' : ''}
self.exit_from_tray = False
self.nodeSync = 0
self.networkSync = 0
self.lastScan = 0
self.notQueue = queue.Queue()
self.running = True
self.pwd = ''
self.scanning = False
self.pipe = 0
self.addTx.connect(self.AddTx)
self.sortTx.connect(self.SortTx)
print('INFO: Window config initialized')
self.initUI()
#custom close event
def closeEvent(self, event):
#checking if minimize to tray instead of closing checbox is checked
if self.hCheckboxTrayClose.isChecked() and not self.exit_from_tray:
#if yes just hide main window and ignore close event
self.hide()
event.ignore()
else:
#if no close wallet
#update config
with open("Wallet.ini", "w") as configfile:
config.write(configfile)
#check wallet was launched in offline mode
if not '--offline' in app.arguments():
try:
#send close signal to wallet's rpc
requests.post('http://127.0.0.1:38420/json_rpc', data='{"method" : "stop_wallet", "id" : "", "jsonrpc" : "2.0"}', headers={'Content-Type':'application/json'})
except:
pass
#close daemon
if self.xi_daemon: self.xi_daemon.terminate()
#destroy tray icon
self.tray_icon.hide()
#close background thread
self.running = False
event.accept()
def initUI(self):
print('INFO: Generating window controls')
#window title and size
self.setWindowTitle('Morelo GUI Wallet v' + version.version)
self.setFixedSize(800, 470)
self.tabsControls = {}
#Image background
background = QLabel(self)
background.setPixmap(QPixmap("./assets/bg.png").scaledToWidth(800, Qt.SmoothTransformation))
self.hLabelLogo = self.GUICtrlCreateLabel('MORELO', 0, 0, 800, 150, 0, 0, '60px')
self.hLabelLogo.setAlignment(Qt.AlignCenter)
self.hLabelInit = self.GUICtrlCreateLabel('Initializing...', 470, 100, 0, 0, 0, 0, '14px')
self.hLabelInit.hide()
#self.hLabelCopyrights = self.GUICtrlCreateLabel('All rights reserved © 2019-2020 MrKris7100', 520, 450, 0, 0, 0, 0, '12px')
self.hLabelTip = self.GUICtrlCreateLabel('What you want to do?', 250, 320, 300, 0, 0, 0, '14px')
self.hLabelTip.setAlignment(Qt.AlignCenter)
self.hLabelTip.hide()
self.hLabelInitErr = self.GUICtrlCreateLabel('Failed to start daemon', 250, 300, 300, 0, 0, '#b53b3b', '14px')
self.hLabelInitErr.setAlignment(Qt.AlignCenter)
#Pasword prompt controls
self.hLabelPass = self.GUICtrlCreateLabel('This wallet is protected, enter password to unlock', 250, 220, 300, 0, 0, 0, '11px')
self.hLabelPassSet = self.GUICtrlCreateLabel('Specify password for new wallet (can be empty)', 250, 220, 300, 0, 0, 0, '11px')
self.hInputPass = self.GUICtrlCreateInput('', 250, 240, 230, 30)
self.hButtonPass = self.GUICtrlCreateButton('Unlock', 485, 240, 60, 30)
self.hButtonPassSet = self.GUICtrlCreateButton('Done', 485, 240, 60, 30)
self.hLabelPassWrong = self.GUICtrlCreateLabel("Wrong password", 250, 270, 100, 20, 0, '#b53b3b')
self.hLabelPass.hide()
self.hButtonPass.hide()
self.hInputPass.hide()
self.hLabelPassSet.hide()
self.hButtonPassSet.hide()
self.hLabelPassWrong.hide()
self.hLabelInitErr.hide()
#create / open / restore wallet buttons
self.hButtonCreate = self.GUICtrlCreateButton('', 150, 200, 100, 100)
GUICtrlSetBkColor(self.hButtonCreate, "url('./assets/wallet_new.png')")
GUICtrlSetHoverBkColor(self.hButtonCreate, "url('./assets/wallet_new_hover.png')")
self.hButtonCreate.installEventFilter(self)
self.hButtonCreate.hide()
self.hButtonOpen = self.GUICtrlCreateButton('', 350, 200, 100, 100)
GUICtrlSetBkColor(self.hButtonOpen, "url('./assets/wallet_open.png')")
GUICtrlSetHoverBkColor(self.hButtonOpen, "url('./assets/wallet_open_hover.png')")
self.hButtonOpen.installEventFilter(self)
self.hButtonOpen.hide()
self.hButtonRestore = self.GUICtrlCreateButton('', 550, 200, 100, 100)
GUICtrlSetBkColor(self.hButtonRestore, "url('./assets/wallet_restore.png')")
GUICtrlSetHoverBkColor(self.hButtonRestore, "url('./assets/wallet_restore_hover.png')")
self.hButtonRestore.installEventFilter(self)
self.hButtonRestore.hide()
#left panel controls
#Background rects
self.box1 = self.GUICtrlCreateBox('rgba(255, 255, 255, 15%)', 0, 0, 200, 145)
self.box2 = self.GUICtrlCreateBox('rgba(255, 255, 255, 15%)', 0, 325, 200, 115)
self.box3 = self.GUICtrlCreateBox('rgba(255, 255, 255, 15%)', 0, 445, 800, 25)
#Log out button
self.hButtonLogout = self.GUICtrlCreateButton("Log Out", 725, 410, 70, 30)
self.hButtonLogout.hide()
#Balance labels
self.hLabelGalaxia = self.GUICtrlCreateLabel("MORELO", 0, 0, 200, 60, 0, 0, '32px')
self.hLabelGalaxia.setAlignment(Qt.AlignHCenter)
self.hLabelBalance = self.GUICtrlCreateLabel("Balance", 25, 60, 0, 0, 0, 0, '11px', 'normal')
self.hLabelBalanceValue = self.GUICtrlCreateLabel('0.000000', 25, 70, 175, 35, 0, 'white', '22px', 'normal')
self.hLabelBalanceLocked = self.GUICtrlCreateLabel("Locked balance", 25, 105, 0, 0, 0, 0, '11px' , 'normal')
self.hLabelBalanceLockedValue = self.GUICtrlCreateLabel('0.000000', 25, 115, 175, 25, 0, 'white', '18px', 'normal')
#Network status
self.hLabelNetwork = self.GUICtrlCreateLabel("Network status:", 5, 448, 0, 0, 'transparent', 0, '14px', 'bold')
self.hLabelNetworkStatus = self.GUICtrlCreateLabel("Disconnected", 125, 450, 150, 0, 'transparent', '#fc7c7c', '11px', 'bold')
self.hLabelNetworkDiff = self.GUICtrlCreateLabel("Network diff: 1000000000", 300, 450, 190, 0, 'transparent', 0, '11px', 'bold')
self.hLabelNetworkHashrate = self.GUICtrlCreateLabel("Network hashrate: 0", 555, 450, 190, 0, 'transparent', 0, '11px', 'bold')
#Navigation
self.activeTab = self.hButtonSend = self.GUICtrlCreateButton('Send', 0, 150, 200, 35, 'rgba(230, 140, 0, 50%)', 'white')
self.hButtonReceive = self.GUICtrlCreateButton("Receive", 0, 185, 200, 35)
self.hButtonHistory = self.GUICtrlCreateButton("Transactions", 0, 220, 200, 35)
self.hButtonSettings = self.GUICtrlCreateButton("Settings", 0, 255, 200, 35)
self.hButtonAbout = self.GUICtrlCreateButton("About", 0, 290, 200, 35)
self.navButtons = (self.hButtonSend, self.hButtonReceive, self.hButtonHistory, self.hButtonSettings, self.hButtonAbout)
#controls grouping
self.tabsControls['leftpanel'] = [self.box1, self.box2, self.box3, self.hLabelGalaxia, self.hLabelBalance,
self.hLabelBalanceValue, self.hLabelBalanceLocked, self.hLabelBalanceLockedValue,
self.hLabelNetwork, self.hButtonSend, self.hButtonReceive,
self.hButtonHistory, self.hButtonSettings, self.hLabelNetworkStatus, self.hButtonAbout,
self.hLabelNetworkDiff, self.hLabelNetworkHashrate]
#Send TAB
self.hInputAmount = self.GUICtrlCreateInput('', 215, 30, 250, 30, 'rgba(255, 0, 0, 15%)')
validator = QDoubleValidator()
validator.setBottom(0.000000001)
validator.setDecimals(9)
locale = QLocale('English')
locale.setNumberOptions(QLocale.RejectGroupSeparator);
validator.setLocale(locale)
self.hInputAmount.setValidator(validator)
self.hInputAddress = self.GUICtrlCreateInput('', 215, 80, 250, 30, 'rgba(255, 0, 0, 15%)')
validator = QRegExpValidator(QRegExp("[e][m][ois][1-9a-zA-Z]{95}"))
self.hInputAddress.setValidator(validator)
self.hInputPaymentID = self.GUICtrlCreateInput('', 215, 130, 125, 30)
validator = QRegExpValidator(QRegExp("([0-9a-fA-F]{16}|[0-9a-fA-F]{64})"))
self.hInputPaymentID.setValidator(validator)
self.hLabelAmount = self.GUICtrlCreateLabel("Amount", 215, 15)
self.hLabelAmountErr = self.GUICtrlCreateLabel("Please enter amount", 335, 60, 130, 20, 0, '#b53b3b')
self.hLabelAmountErr.setAlignment(Qt.AlignRight)
self.hLabelAddress = self.GUICtrlCreateLabel("Receiver address", 215, 65)
self.hLabelAddressErr = self.GUICtrlCreateLabel("Please enter address", 335, 110, 130, 20, 0, '#b53b3b')
self.hLabelAddressErr.setAlignment(Qt.AlignRight)
self.hLabelPaymentID = self.GUICtrlCreateLabel("Payment ID (Optional)", 215, 115)
self.hButtonAmountAll = self.GUICtrlCreateButton("or All", 475, 30, 50, 30)
self.hButtonAddressPaste = self.GUICtrlCreateButton("Paste", 475, 80, 50, 30)
self.hButtonSendSend = self.GUICtrlCreateButton("Send", 215, 170, 50, 30)
#grouping controls
self.tabsControls[self.hButtonSend.objectName()] = [self.hInputAmount, self.hInputAddress, self.hInputPaymentID, self.hLabelAmount, self.hLabelAmountErr,
self.hLabelAddress, self.hLabelAddressErr, self.hLabelPaymentID, self.hButtonAmountAll, self.hButtonAddressPaste,
self.hButtonSendSend]
#Receive TAB
self.hInputWalletAddress = self.GUICtrlCreateInput('', 215, 30, 250, 30, 'rgba(255, 255, 255, 15%)')
self.hInputWalletAddress.setReadOnly(True)
self.hLabelWalletAddress = self.GUICtrlCreateLabel("Wallet address", 215, 15)
self.QrAddress = self.GUICtrlCreateLabel('', 215, 65, 225, 225)
self.hButtonWalletCopy = self.GUICtrlCreateButton("Copy", 475, 30, 50, 30)
#grouping controls
self.tabsControls[self.hButtonReceive.objectName()] = [self.hInputWalletAddress, self.hLabelWalletAddress, self.hButtonWalletCopy, self.QrAddress]
#Settings TAB
self.hCheckboxTrayCloseBk = self.GUICtrlCreateBox('rgba(255, 255, 255, 15%)', 215, 15, 25, 25)
self.hCheckboxTrayClose = self.GUICtrlCreateCheckBox('', 215, 15)
self.hCheckboxTrayCloseText = self.GUICtrlCreateLabel('Hide to tray instead of closing', 245, 20, 0, 0, 0, 0, '13px')
self.hCheckboxNotsBk = self.GUICtrlCreateBox('rgba(255, 255, 255, 15%)', 215, 45, 25, 25)
self.hCheckboxNots = self.GUICtrlCreateCheckBox('', 215, 45)
if 'wallet' in config:
if int(config['wallet']['trayclose']):
self.hCheckboxTrayClose.setCheckState(2)
if int(config['wallet']['disablenotifications']):
self.hCheckboxNots.setCheckState(2)
self.hCheckboxNotsText = self.GUICtrlCreateLabel('Disable notifications', 245, 50, 0, 0, 0, 0, '13px')
self.hLabelNode = self.GUICtrlCreateLabel('Network connection', 215, 155, 0, 0, 0, 0, '13px')
self.hLabelSelInfo = self.GUICtrlCreateLabel('Changes requiring restart', 215, 205, 130, 20, 0, '#b53b3b')
self.hLabelSelInfo.hide()
self.hDropDownNode = self.GUICtrlCreateDropDown(self, 215, 175, 180, 30, ['Run local node', 'Use public node #1', 'Use public node #2', 'Use custom node'], self.SelectNode)
self.hLabelUrl = self.GUICtrlCreateLabel('Custom node address', 450, 160)
self.hLabelUrl.hide()
self.hInputUrl = self.GUICtrlCreateInput('http://', 450, 175, 180, 30)
self.hInputUrl.hide()
self.hLabelUrlPort = self.GUICtrlCreateLabel('Custom node port', 450, 210)
self.hLabelUrlPort.hide()
self.hInputUrlPort = self.GUICtrlCreateInput('', 450, 225, 75, 30)
self.hInputUrlPort.setValidator(QIntValidator(1, 65535))
self.hInputUrlPort.hide()
self.hLabelKeys = self.GUICtrlCreateLabel('Wallet keys and seed', 215, 75, 0, 0, '13px')
self.hButtonKeys = self.GUICtrlCreateButton('Show', 215, 95, 50, 30)
#Keys controls
self.hInputSpend = self.GUICtrlCreateInput('', 215, 30, 250, 30)
self.hInputSpend.setReadOnly(True)
self.hInputView = self.GUICtrlCreateInput('', 215, 80, 250, 30)
self.hInputView.setReadOnly(True)
self.hInputSeed = self.GUICtrlCreateInput('', 215, 130, 250, 30)
self.hInputSeed.setReadOnly(True)
self.hLabelSpend = self.GUICtrlCreateLabel("Private spend key", 215, 15)
self.hLabelView = self.GUICtrlCreateLabel("Private view key", 215, 65)
self.hLabelSeed = self.GUICtrlCreateLabel("Mnemonic seed", 215, 115)
self.hButtonBack = self.GUICtrlCreateButton("Back", 215, 170, 50, 30)
self.tabsControls['keys'] = [self.hInputSpend, self.hInputView, self.hInputSeed,
self.hLabelSpend, self.hLabelView, self.hLabelSeed, self.hButtonBack]
for ctrl in self.tabsControls['keys']:
ctrl.hide()
#grouping controls
self.tabsControls[self.hButtonSettings.objectName()] = [self.hLabelKeys, self.hButtonKeys, self.hDropDownNode, self.hCheckboxNots, self.hCheckboxNotsBk, self.hCheckboxNotsText,
self.hCheckboxTrayClose,
self.hCheckboxTrayCloseBk, self.hCheckboxTrayCloseText, self.hLabelNode]
#Transactions TAB
self.hTableTransactions = QTableWidget(0, 3, self)
self.hTableTransactions.move(215, 15)
self.hTableTransactions.setFixedSize(570, 205)
self.hTableTransactions.verticalHeader().hide()
self.hTableTransactions.setHorizontalScrollBarPolicy(Qt.ScrollBarAlwaysOff)
self.hTableTransactions.setHorizontalHeaderLabels(['Date', 'Tx hash', 'Amount'])
self.hTableTransactions.horizontalHeader().setSectionResizeMode(QHeaderView.Fixed)
self.hTableTransactions.horizontalHeader().resizeSection(0, 160)
self.hTableTransactions.horizontalHeader().resizeSection(1, 230)
self.hTableTransactions.horizontalHeader().resizeSection(2, 163)
self.tabsControls[self.hButtonHistory.objectName()] = [self.hTableTransactions]
#About TAB
self.hLabelAbout = self.GUICtrlCreateLabel('''Morelo GUI Wallet v''' + version.version + '''
Author: MrKris7100
Special thanks to njamnjam, MadHater, EMPEROR and other people from Morelo Network team.
This program is not official part of Morelo Network.
This program uses 3rd party applications: morelod and morelo-wallet-rpc from Morelo Network.
If you enjoy the program you can support me by donating some MRL using button below.''', 215, 15, 0, 0, 0, 0, '11px')
self.hButtonDonate = self.GUICtrlCreateButton('Donate', 215, 150, 75, 30)
#Init config controls
self.hLabelNodeType = self.GUICtrlCreateLabel('Network connection type', 250, 205, 0, 0, '13px')
self.hLabelPath = self.GUICtrlCreateLabel('Wallet working directory', 250, 150)
self.hInputPath = self.GUICtrlCreateInput(config['wallet']['workdir'].replace('"', ''), 250, 170, 200, 30)
self.hInputPath.setReadOnly(True)
self.hButtonBrowse = self.GUICtrlCreateButton('Browse', 455, 170, 60, 30)
self.hButtonOk = self.GUICtrlCreateButton('Ok', 520, 170, 30, 30)
self.tabsControls['initconfig'] = [self.hButtonOk, self.hLabelNodeType, self.hLabelPath, self.hInputPath, self.hButtonBrowse,
self.hDropDownNode]
self.tabsControls[self.hButtonAbout.objectName()] = [self.hLabelAbout, self.hButtonDonate]
#hiding controls
for ctrl in self.tabsControls[self.hButtonAbout.objectName()]:
ctrl.hide()
for ctrl in self.tabsControls[self.hButtonReceive.objectName()]:
ctrl.hide()
for ctrl in self.tabsControls[self.hButtonSettings.objectName()]:
ctrl.hide()
for ctrl in self.tabsControls[self.hButtonHistory.objectName()]:
ctrl.hide()
for ctrl in self.tabsControls['initconfig']:
ctrl.hide()
#checking connection type in config
if config['wallet']['connection'] == 'local':
self.hDropDownNode.hLabelSelection.setText('Run local node')
elif config['wallet']['connection'] == 'ext1':
self.hDropDownNode.hLabelSelection.setText('Use public node #1')
elif config['wallet']['connection'] == 'ext2':
self.hDropDownNode.hLabelSelection.setText('Use public node #2')
elif config['wallet']['connection'] == 'custom':
self.hDropDownNode.hLabelSelection.setText('Use custom node')
url = config['wallet']['url'].split(':')
self.hInputUrl.setText(url[0] + ':' + url[1])
self.hInputUrlPort.setText(url[2])
# Create tray menu
self.tray_menu = QMenu()
self.tray_show = QAction("Show")
self.tray_show.triggered.connect(self.tray_event)
self.tray_exit = QAction("Exit")
self.tray_exit.triggered.connect(self.tray_exit_proc)
self.tray_menu.addAction(self.tray_show)
self.tray_menu.addAction(self.tray_exit)
#Create tray icon
self.tray_icon = QSystemTrayIcon()
#add menu to tray
self.tray_icon.setContextMenu(self.tray_menu)
self.tray_icon.activated.connect(self.tray_event)
#Set window and tray icon
self.tray_icon.setIcon(QIcon("./morelo.ico"))
self.setWindowIcon(QIcon("./morelo.ico"))
#hiding left panel
for ctrl in self.tabsControls['leftpanel']:
ctrl.hide()
for ctrl in self.tabsControls[self.hButtonSend.objectName()]:
ctrl.hide()
self.tray_icon.show()
self.show()
#Wallet initialization (background thread)
thread = Worker(self.NetworkThread)
self.threadpool.start(thread)
def GetWalletKeys(self):
try:
response = requests.post('http://127.0.0.1:38420/json_rpc',data='{"jsonrpc":"2.0","id":"0","method":"query_key","params":{"key_type":"view_key"}}', headers={'Content-Type':'application/json'})
response = json.loads(response.text)
self.wallet_keys['view'] = response['result']['key']
response = requests.post('http://127.0.0.1:38420/json_rpc',data='{"jsonrpc":"2.0","id":"0","method":"query_key","params":{"key_type":"spend_key"}}', headers={'Content-Type':'application/json'})
response = json.loads(response.text)
self.wallet_keys['spend'] = response['result']['key']
response = requests.post('http://127.0.0.1:38420/json_rpc',data='{"jsonrpc":"2.0","id":"0","method":"query_key","params":{"key_type":"mnemonic"}}', headers={'Content-Type':'application/json'})
response = json.loads(response.text)
self.wallet_keys['seed'] = response['result']['key']
except:
print("ERROR: Can't read wallet keys")
def GetNodeInfo(self):
response = False
try:
response = requests.post(daemon_url + '/json_rpc', data='{"method" : "sync_info", "id" : "0", "jsonrpc" : "2.0"}', headers={'Content-Type':'application/json'})
response2 = requests.post(daemon_url + '/json_rpc', data='{"jsonrpc":"2.0","id":"0","method":"get_connections"}', headers={'Content-Type':'application/json'})
response3 = requests.post(daemon_url + '/json_rpc', data='{"jsonrpc":"2.0","id":"0","method":"get_info"}', headers={'Content-Type':'application/json'})
except:
pass
if response and response2 and response3:
#some shitty mixing responses json
response.json = json.loads(response.text)
response.json['result']['difficulty'] = 0
response2 = json.loads(response2.text)
response3 = json.loads(response3.text)
target_height = 0
if 'connections' in response2['result']:
for conn in response2['result']['connections']:
if conn['height'] > target_height:
target_height = conn['height']
response.json['result']['target_height'] = target_height
if response3: response.json['result']['difficulty'] = response3['result']['difficulty']
return response
def WaitForDaemon(self):
timeout = TimerInit()
while TimerDiff(timeout) < 15000:
nodeInfo = self.GetNodeInfo()
if nodeInfo and 'result' in nodeInfo.json:
return True
sleep(0.5)
return False
#detecting hover event on create / open / restore wallet buttons and modify "tooltip" with right text
def eventFilter(self, obj, event):
type = event.type()
if obj.isEnabled():
if type == 129:
if obj == self.hButtonCreate:
self.hLabelTip.setText('Create new wallet')
elif obj == self.hButtonOpen:
self.hLabelTip.setText('Open existing wallet')
elif obj == self.hButtonRestore:
self.hLabelTip.setText('Restore wallet from seed')
if type == 128 and (obj == self.hButtonCreate or obj == self.hButtonOpen or obj == self.hButtonRestore):
self.hLabelTip.setText('What you want to do?')
return 0
def tray_exit_proc(self):
self.exit_from_tray = True
self.close()
def tray_event(self, reason):
if reason == QSystemTrayIcon.DoubleClick or reason == QWidgetAction.Trigger:
self.show()
self.setWindowState(Qt.WindowNoState)
def UpdateWalletAddress(self):
self.hInputWalletAddress.setText(self.wallet_address)
def UpdateQrCode(self):
buf = io.BytesIO()
qr = qrcode.QRCode(version=1, box_size=5, border=1)
qr.add_data(self.wallet_address)
qr.make(True)#self.wallet_address)
img = qr.make_image(fill_color="black", back_color="white")
img.save(buf, "PNG")
qt_pixmap = QPixmap()
qt_pixmap.loadFromData(buf.getvalue(), "PNG")
self.QrAddress.setPixmap(qt_pixmap)
class GUICtrlCreateDropDown():
def __init__(self, parent, posX, posY, sizeX, sizeY, items, parser):
super().__init__()
self.expanded = False
self.items = items
self.sizeX = sizeX
self.sizeY = sizeY
self.hLabelSelection = parent.GUICtrlCreateLabel(str(items[0]), posX, posY, sizeX - sizeY, sizeY, 'rgba(255, 255, 255, 15%);text-align: left;padding-left: 3px', 0, '14px', 'bold')
self.hButtonSelect = parent.GUICtrlCreateButton('▼', posX + sizeX - sizeY, posY, sizeY, sizeY)
self.hButtonSelect.clicked.connect(self.toggle)
for item in range(len(self.items)):
self.items[item] = parent.GUICtrlCreateButton(str(self.items[item]), posX, posY + sizeY + (sizeY * item), sizeX, sizeY, 'rgba(255, 255, 255, 15%);text-align: left;padding-left: 7px')
self.items[item].hide()
self.items[item].clicked.connect(parser)
self.items[item].clicked.connect(lambda *args, item=item: self.select(items[item].text()))
def move(self, posX, posY):
self.hLabelSelection.move(posX, posY)
self.hButtonSelect.move(posX + self.sizeX - self.sizeY, posY)
for item in range(len(self.items)):
self.items[item].move(posX, posY + self.sizeY + (self.sizeY * item))
def select(self, item):
self.hLabelSelection.setText(item)
self.toggle()
def toggle(self):
if self.expanded:
for item in self.items:
item.hide()
GUICtrlSetBkColor(self.hButtonSelect, 'rgba(255, 255, 255, 15%)')
GUICtrlSetColor(self.hButtonSelect, 'rgb(230, 140, 0)')
self.hButtonSelect.setText('▼')
else:
for item in self.items:
item.show()
GUICtrlSetBkColor(self.hButtonSelect, 'rgba(230, 140, 0, 50%)')
GUICtrlSetColor(self.hButtonSelect, 'white')
self.hButtonSelect.setText('▲')
self.expanded = not self.expanded
def hide(self):
for item in self.items:
item.hide()
self.hButtonSelect.hide()
self.hLabelSelection.hide()
self.expanded = True
self.toggle()
def show(self):
self.hButtonSelect.show()
self.hLabelSelection.show()
#custom button creating function
def GUICtrlCreateButton(self, text, left, top, width = 0, height = 0, background = 0, color = 0, fontsize = 0, fontweight = 0):
button = QPushButton(text, self)
self.ctrlCount += 1
button.setObjectName(str(self.ctrlCount))
if width: button.setFixedWidth(width)
if height: button.setFixedHeight(height)
button.move(left, top)
button.type = 'QPushButton'
button.myfontsize = fontsize if fontsize else '14px'
button.myfontweight = fontweight if fontweight else 'bold'
button.mybackgroundcolor = background if background else 'rgba(255, 255, 255, 15%)'
button.mycolor = color if color else 'rgb(230, 140, 0)'
button.myborder = 'none'
button.myhoverbackgroundcolor = 'rgba(230, 140, 0, 50%)'
button.myhovercolor = 'white'
GUICtrlUpdateStyle(button)
button.clicked.connect(self.button_proc)
return button
#custom checkbox creating function
def GUICtrlCreateCheckBox(self, text, left, top):
checkbox = QCheckBox(text, self)
self.ctrlCount += 1
checkbox.setObjectName(str(self.ctrlCount))
checkbox.move(left, top)
checkbox.type = 'QCheckBox'
checkbox.toggled.connect(self.checkbox_proc)
return checkbox
#creating rectangles using labels
def GUICtrlCreateBox(self, color, left, top, width, height):
box = QLabel(self)
box.move(left, top)
box.setFixedSize(width, height)
box.setStyleSheet('background-color: ' + color)
box.setAlignment(Qt.AlignHCenter)
box.setAlignment(Qt.AlignVCenter)
return box
#custom label creating function
def GUICtrlCreateLabel(self, text, left, top, width = 0, height = 0, background = 0, color = 0, fontsize = 0, fontweight = 0):
label = QLabel(text, self)
self.ctrlCount += 1
label.setObjectName(str(self.ctrlCount))
if width: label.setFixedWidth(width)
if height: label.setFixedHeight(height)
label.move(left, top)
label.type = 'QLabel'
label.mywidth = str(width) if width else 'initial'
label.myheight = str(height) if height else 'initial'
label.myfontsize = fontsize if fontsize else '10px'
label.myfontweight = fontweight if fontweight else 'bold'
label.mybackgroundcolor = background if background else 'transparent'
label.mycolor = color if color else 'rgb(230, 140, 0)'
label.myborder = 'none'
GUICtrlUpdateStyle(label)
return label
#custom input creating function
def GUICtrlCreateInput(self, text, left, top, width, height, background = 0, color = 0, fontsize = 0, fontweight = 0):
input = QLineEdit(self)
self.ctrlCount += 1
input.setObjectName(str(self.ctrlCount))
input.move(left, top)
input.type = 'QLineEdit'
input.setFixedSize(width, height)
input.myfontsize = fontisze if fontsize else '14px'
input.myfontweight = fontweight if fontweight else 'bold'
input.mybackgroundcolor = background if background else 'rgba(255, 255, 255, 15%)'
input.mycolor = color if color else 'rgb(230, 140, 0)'
input.myborder = 'none'
GUICtrlUpdateStyle(input)
input.setText(text)
input.textChanged.connect(self.input_proc)
input.editingFinished.connect(self.input_proc_end)
return input
#network status update function (visual)
def XiNetworkSetState(self, iState, iPercent = 0):
if iState != self.XiNetworkState:
self.XiNetworkState = iState
if self.XiNetworkState == 0:
print('INFO: Network disconnected')
GUICtrlSetColor(self.hLabelNetworkStatus, '#fc7c7c')
self.hLabelNetworkStatus.setText("Disconnected")
elif self.XiNetworkState == 1:
GUICtrlSetColor(self.hLabelNetworkStatus, '#f7ff91')
self.hLabelNetworkStatus.setText("Syncing (" + '%.2f' % iPercent + "%)")
elif self.XiNetworkState == 2:
print('INFO: Network synced')
GUICtrlSetColor(self.hLabelNetworkStatus, 'rgb(26, 188, 156)')
self.hLabelNetworkStatus.setText("Synced")
elif iState == 1:
self.hLabelNetworkStatus.setText("Syncing (" + '%.2f' % iPercent + "%)")
#node type selection
def SelectNode(self):
obj = self.sender()
lastSetting = config['wallet']['connection']
if obj == self.hDropDownNode.items[0]:
config['wallet']['connection'] = 'local'
config['wallet']['url'] = 'http://127.0.0.1:38422'
elif obj == self.hDropDownNode.items[1]:
config['wallet']['connection'] = 'ext1'
config['wallet']['url'] = 'http://'
elif obj == self.hDropDownNode.items[2]:
config['wallet']['connection'] = 'ext2'
config['wallet']['url'] = 'http://'
elif obj == self.hDropDownNode.items[3]:
config['wallet']['connection'] = 'custom'
if lastSetting != config['wallet']['connection']:
if config['wallet']['connection'] == 'custom':
for ctrl in [self.hLabelUrl, self.hInputUrl, self.hLabelUrlPort, self.hInputUrlPort]:
ctrl.show()
else:
for ctrl in [self.hLabelUrl, self.hInputUrl, self.hLabelUrlPort, self.hInputUrlPort]:
ctrl.hide()
#buttons event processing function
def button_proc(self):
obj = self.sender()
if obj != self.activeTab:
#Switching TABS
if obj in self.navButtons:
if config['wallet']['connection'] == 'custom':
if obj == self.hButtonSettings:
for ctrl in [self.hLabelUrl, self.hInputUrl, self.hLabelUrlPort, self.hInputUrlPort]:
ctrl.show()
else:
for ctrl in [self.hLabelUrl, self.hInputUrl, self.hLabelUrlPort, self.hInputUrlPort]:
ctrl.hide()
GUICtrlSetBkColor(self.activeTab, 'rgba(255, 255, 255, 15%)')
GUICtrlSetColor(self.activeTab, 'rgb(230, 140, 0)')
for ctrl in self.tabsControls[self.activeTab.objectName()]:
ctrl.hide()
GUICtrlSetBkColor(obj, 'rgba(230, 140, 0, 50%)')
GUICtrlSetColor(obj, 'white')
for ctrl in self.tabsControls[obj.objectName()]:
ctrl.show()
self.activeTab = obj
else:
#Initial config ok button
if obj == self.hButtonOk:
self.pipe = 'config'
#Show keys button
elif obj == self.hButtonKeys:
for ctrl in self.tabsControls[self.hButtonSettings.objectName()]:
ctrl.hide()
for ctrl in self.tabsControls['keys']:
ctrl.show()
#Keys back button
elif obj == self.hButtonBack:
for ctrl in self.tabsControls[self.hButtonSettings.objectName()]:
ctrl.show()
for ctrl in self.tabsControls['keys']:
ctrl.hide()
#initial config browse button
elif obj == self.hButtonBrowse:
self.hDropDownNode.hButtonSelect.setEnabled(False)
self.hButtonBrowse.setEnabled(False)
self.hButtonOk.setEnabled(False)
tkroot = Tk()
tkroot.withdraw()
file_path = filedialog.askdirectory(title='Select directory')
tkroot.destroy()
print(file_path)
if file_path and pathlib.Path(file_path).exists():
self.hInputPath.setText(file_path)
config['wallet']['workdir'] = '"' + file_path + '"'
self.hDropDownNode.hButtonSelect.setEnabled(True)
self.hButtonBrowse.setEnabled(True)
self.hButtonOk.setEnabled(True)
#logout button
elif obj == self.hButtonLogout:
print("INFO: Log Out")
for ctrl in self.tabsControls['leftpanel']:
ctrl.hide()
for ctrl in self.tabsControls[self.activeTab.objectName()]:
ctrl.hide()
self.hButtonCreate.show()
self.hButtonOpen.show()
self.hButtonRestore.show()
self.hLabelTip.show()
self.hLabelLogo.show()
self.hButtonLogout.hide()
self.pipe = 'logout'
try:
requests.post('http://127.0.0.1:38420/json_rpc', data='{"method" : "stop_wallet", "id" : "", "jsonrpc" : "2.0"}', headers={'Content-Type':'application/json'})
except:
pass
#submit password (On wallet opening)
elif obj == self.hButtonPass:
self.hLabelInit.show()
self.hLabelPass.hide()
self.hInputPass.hide()
self.hButtonPass.hide()
self.pwd = self.hInputPass.text()
if self.pwd == '': self.pwd = -1
self.pipe = 'postpassword'
elif obj == self.hButtonRestore:
self.hButtonCreate.hide()
self.hButtonOpen.hide()
self.hButtonRestore.hide()
self.hLabelTip.hide()
self.hLabelInit.hide()
self.hLabelMnemonic.show()
self.hInputMnemonic.show()
self.hButtonMnemonic.show()
#submit password (On wallet creation)
elif obj == self.hButtonPassSet:
self.pwd = self.hInputPass.text()
self.hButtonCreate.hide()
self.hButtonOpen.hide()
self.hButtonRestore.hide()
self.hLabelTip.hide()
self.pipe = 'newwallet'
#Donate button
elif obj == self.hButtonDonate:
self.hInputAddress.setText(donate_address)
self.hInputPaymentID.setText('DONATE')
self.hButtonSend.click()
#Wallet open button
elif obj == self.hButtonOpen: