Skip to content

Commit 2b03154

Browse files
Added GUI
Tkinter GUI added
1 parent ff5bed1 commit 2b03154

File tree

1 file changed

+32
-21
lines changed

1 file changed

+32
-21
lines changed

gui.py

Lines changed: 32 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -12,18 +12,20 @@
1212
import tkinter
1313
import websocket
1414
import json
15-
import sys, os, logging
15+
import sys, os
1616
from websocket import create_connection
17+
import ssl
18+
import websocket
1719
from tkinter import *
1820
import tkinter.simpledialog as simpledialog
1921
import tkinter.messagebox as messagebox
2022
from tkinter import ttk
2123
root=Tk()
24+
root.withdraw()
2225

2326
root.minsize(width=600, height=300)
2427
root.wm_iconbitmap('logo.ico')
2528
root.title('XRB Lite Wallet')
26-
root.withdraw()
2729
def root_destroy():
2830
root.destroy()
2931

@@ -44,7 +46,6 @@ def address_to_clipboard(self=1):
4446
raw_in_xrb = 1000000000000000000000000000000.0
4547
choices = u'Send,Account History,Display QR Code,,Configure PoW,Configure Rep,Configure Server,,Refresh,Quit'.split(',')
4648
running_pow_gen = False
47-
logging.basicConfig(filename="sample.log", level=logging.INFO)
4849
class StringDialog(simpledialog._QueryString):
4950
def body(self, master):
5051
super().body(master)
@@ -289,7 +290,6 @@ def send_xrb(dest_address, final_balance):
289290
ws.send(data)
290291

291292
block_reply = ws.recv()
292-
logging.info(block_reply)
293293
#print(block_reply)
294294
return block_reply
295295

@@ -330,15 +330,13 @@ def receive_xrb():
330330
ws.send(data)
331331

332332
block_reply = ws.recv()
333-
logging.info(block_reply)
334333
save_config('balance', str(get_balance(account)))
335334
#print(block_reply)
336335
else:
337336
if parser.get('wallet', 'cached_pow') == '' and parser.get('wallet', 'open') == '1':
338337
previous = get_previous()
339338
work = get_pow(previous, 'cache')
340339
save_config('cached_pow', work)
341-
logging.info("Cached PoW Block")
342340
time.sleep(50)
343341

344342
def open_xrb():
@@ -378,7 +376,6 @@ def open_xrb():
378376
ws.send(data)
379377

380378
block_reply = ws.recv()
381-
logging.info(block_reply)
382379

383380
save_config('open', '1')
384381
#print(block_reply)
@@ -408,7 +405,6 @@ def change_xrb():
408405
ws.send(data)
409406

410407
block_reply = ws.recv()
411-
logging.info(block_reply)
412408
#print(block_reply)
413409

414410
def item_chosen(choice):
@@ -417,7 +413,7 @@ def item_chosen(choice):
417413
global saved_balance
418414
save_config('balance', str(get_balance(account)))
419415
saved_balance = str(get_balance(account))
420-
balance_text.set(('Balance: {} Mxrb').format(int(saved_balance)))
416+
balance_text.set(('Balance: {} Mxrb').format(int(float(saved_balance))))
421417
root.update_idletasks()
422418

423419
elif choice == 'Send':
@@ -498,6 +494,9 @@ def item_chosen(choice):
498494
master = tkinter.Frame(top)
499495
master.pack()
500496
tree = ttk.Treeview(master, columns=['Transaction Type','Account','Amount'])
497+
tree.heading('Transaction Type', text='Transaction Type')
498+
tree.heading('Account', text='Account')
499+
tree.heading('Amount', text='Amount')
501500
tree.pack()
502501
else:
503502
account_block_count = rx_data['block_count']
@@ -594,8 +593,14 @@ def process_send(final_address, final_balance):
594593
messagebox.showerror('Failed', 'Transaction Failed')
595594
top.destroy()
596595

597-
596+
class StringDialog(simpledialog._QueryString):
597+
def body(self, master):
598+
super().body(master)
599+
self.iconbitmap('logo.ico')
598600

601+
def ask_string(title, prompt, **kargs):
602+
d = StringDialog(title, prompt, **kargs)
603+
return d.result
599604

600605
def read_encrypted(password, filename, string=True):
601606
with open(filename, 'rb') as input:
@@ -614,13 +619,18 @@ def write_encrypted(password, filename, plaintext):
614619
parser = SafeConfigParser()
615620
config_files = parser.read('config.ini')
616621

622+
617623
while True:
618-
password = simpledialog.askstring("Password", "Enter password:", show='*')
619-
password_confirm = simpledialog.askstring("Password", "Confirm password:", show='*')
624+
password = ask_string("Password", "Enter password:", show='*')
625+
password_confirm = ask_string("Password", "Confirm password:", show='*')
626+
if password == None or password == '':
627+
sys.exit()
620628
if password == password_confirm:
621629
break
630+
622631
messagebox.showerror('Error', 'Password Mismatch')
623632

633+
624634
if len(config_files) == 0:
625635
full_wallet_seed = hex(random.SystemRandom().getrandbits(256))
626636
wallet_seed = full_wallet_seed[2:].upper()
@@ -632,22 +642,22 @@ def write_encrypted(password, filename, plaintext):
632642
public_key = str(binascii.hexlify(pub_key), 'ascii')
633643

634644
account = account_xrb(str(public_key))
635-
keys = open('data.txt', 'w')
636-
keys.write(('Wallet Seed: {}\nPublic Key: {}\n Account Address: {}\n').format(wallet_seed, public_key, account))
637-
keys.write('\n Store the data in a safe place (for example on paper) and DELETE THIS FILE!')
638-
messagebox.showinfo('Info','Seed and Address written to "data.txt", store the data in a safe place and delete this file')
645+
with open('data.txt', 'w') as f:
646+
f.write(('Wallet Seed: {}\nPublic Key: {}\nAccount Address: {}\n').format(wallet_seed, public_key, account))
647+
f.write('\nStore the data in a safe place (for example on paper) and DELETE THIS FILE!')
648+
f.close()
649+
messagebox.showinfo('Info','Seed and Address written to "data.txt", ensure that you store your data in a safe place and delete this file.')
639650
parser.set('wallet', 'account', account)
640651
parser.set('wallet', 'index', '0')
641652
parser.set('wallet', 'representative', default_representative)
642-
parser.set('wallet', 'pow_source', 'internal')
653+
parser.set('wallet', 'pow_source', 'external')
643654
parser.set('wallet', 'server', 'wss://yapraiwallet.space')
644655
parser.set('wallet', 'cached_pow', '')
645656
parser.set('wallet', 'balance', '0')
646657
parser.set('wallet', 'open', '0')
647658

648659
parser.write(cfgfile)
649660
cfgfile.close()
650-
651661
index = 0
652662
seed = wallet_seed
653663
else:
@@ -668,16 +678,17 @@ def write_encrypted(password, filename, plaintext):
668678

669679
try:
670680
ws = create_connection(node_server)
671-
except:
672-
messagebox.showerror('Error', ' to connect to backend server\nTry again later or change the server in config.ini')
681+
except Exception as e:
682+
print (e)
683+
messagebox.showerror('Error', ' Failed to connect to backend server\nTry again later or change the server in config.ini')
673684
sys.exit()
674685

675686

676687
thread = threading.Thread(target=receive_xrb)
677688
thread.start()
678689
root.deiconify()
679690
balance_text = StringVar()
680-
balance_text.set(('Balance: {} Mxrb').format(int(saved_balance)))
691+
balance_text.set(('Balance: {} Mxrb').format(int(float(saved_balance))))
681692
l_title = Label(root, text="RetroXRBWallet")
682693
l_address = Text(root,height=1, width=65)
683694
l_address.insert(1.0, account)

0 commit comments

Comments
 (0)