-
Notifications
You must be signed in to change notification settings - Fork 3
/
gui.py
161 lines (143 loc) · 5.27 KB
/
gui.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
import src.scrapMetaData as scrapMetaData
import src.parameters as parameters
import src.functions as functions
import subprocess
import PySimpleGUI as sg
import random
# Wallet Addr
wallet_addr = ''
with open('main_user/main_base.addr', 'r') as file:
wallet_addr = file.read()[:-1]
sg.theme('Black')
# Screen Layout
layout = [
[sg.Text('Chat: ' + parameters.createChatHash())],
[sg.Text('Channel: ' + parameters.createChannelHash())],
[
sg.Text('Wallet Address:')],
[
sg.Input(wallet_addr,text_color = 'black', background_color='white', readonly=True, size=(106,1))
],
[sg.Button("QUIT"), sg.Button("REFRESH")],
[
sg.Button("Wallet QR Code"),
sg.Button("Return ADA", key='-RETURN-'),
sg.Text("Return ADA", key='-RETURNTEXT-', visible=False),
sg.Button('Confirm', key='-RCONFIRM-', visible=False),
sg.Button('Cancel', key='-RCANCEL-', visible=False)
],
[sg.Image(filename='', key='-QRCODE-', visible=False)],
[sg.Text('Click Refresh',size=(96,48), key='-OUTPUT-', background_color='black')],
[
sg.Text("Username:"),
sg.Input(key='-USER-', size=(16,1)),
sg.Text("Lovelace:"),
sg.Text("", key='-ADA-', size=(10,1)),
sg.Text("Fee:"),
sg.Text("", key='-FEE-', size=(10,1)),
sg.Text("Change:"),
sg.Text("", key='-CHANGE-', size=(10,1)),
],
[
sg.Multiline(key='-IN-', size=(64,12)),
sg.Button('Send', key='-SEND-', visible=True),
sg.Button('Confirm', key='-CONFIRM-', visible=False),
sg.Button('Cancel', key='-CANCEL-', visible=False),
]
]
# Create the window
window = sg.Window("dChat", layout)
# Create an event loop
while True:
event, values = window.read(timeout=10000)
# QUIT button
if event == "QUIT" or event == sg.WIN_CLOSED:
break
# QR Code
if event == "Wallet QR Code":
if window['-QRCODE-'].visible is True:
window['-QRCODE-'].hide_row()
window['-QRCODE-'].update(filename='', visible=False)
else:
window['-QRCODE-'].unhide_row()
window['-QRCODE-'].update(filename='./main_user/main_qrcode.png',visible=True)
# Send a new message
if event == "-SEND-":
# Username and message
username, message = parameters.formatData(values)
if message != '':
parameters.create(username, message)
function = [
'bash',
'self_trx_fee.sh'
]
output = subprocess.check_output(function)
balance = functions.getBalance(wallet_addr)
window['-CONFIRM-'].update(visible=True)
window['-CANCEL-'].update(visible=True)
window['-SEND-'].update(visible=False)
change = balance - int(output.decode('utf-8'))
window['-CHANGE-'].update(change)
window['-FEE-'].update(str(output.decode('utf-8')))
# Confirm button
if event == "-CONFIRM-":
function = [
'bash',
'self_trx_submit.sh'
]
output = subprocess.check_output(function)
window['-OUTPUT-'].update("Sending Message to the Network. Please Click REFRESH")
window['-SEND-'].update(visible=True)
window['-CONFIRM-'].update(visible=False)
window['-CANCEL-'].update(visible=False)
window['-IN-'].update('')
window['-FEE-'].update('')
window['-CHANGE-'].update('')
# Cancel Button
if event == "-CANCEL-":
window['-SEND-'].update(visible=True)
window['-CONFIRM-'].update(visible=False)
window['-CANCEL-'].update(visible=False)
window['-IN-'].update('')
window['-FEE-'].update('')
window['-CHANGE-'].update('')
# Update the chat window
if event == "REFRESH":
balance = functions.getBalance(wallet_addr)
window['-ADA-'].update(balance)
window['-OUTPUT-'].update("Loading Chat Messages...")
data, price = scrapMetaData.get_last_transaction()
print(price)
text = "\n" + str(price) + "\n"
for message in data:
for msg in message:
if int(msg) == 3:
text += '\n' + message[msg] +'\n'
if int(msg) > 3:
text += message[msg] +'\n'
window['-OUTPUT-'].update(text)
# Return All ADA to return address
if event == "-RETURN-":
window['-RETURNTEXT-'].update(visible=True)
window['-RCONFIRM-'].update(visible=True)
window['-RCANCEL-'].update(visible=True)
window['-RETURN-'].update(visible=False)
if event == "-RCONFIRM-":
window['-RCONFIRM-'].update(visible=False)
window['-RCANCEL-'].update(visible=False)
window['-RETURNTEXT-'].update(visible=False)
window['-RETURN-'].update(visible=True)
function = [
'bash',
'return_trx.sh'
]
output = subprocess.check_output(function)
window['-OUTPUT-'].update("Returning All Funds. Please Click REFRESH.")
#
if event == '-RCANCEL-':
window['-RCONFIRM-'].update(visible=False)
window['-RCANCEL-'].update(visible=False)
window['-RETURNTEXT-'].update(visible=False)
window['-RETURN-'].update(visible=True)
# Close
window.close()