-
Notifications
You must be signed in to change notification settings - Fork 0
/
vr_request_gui.py
107 lines (86 loc) · 2.78 KB
/
vr_request_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
'''
neacee 03-26-2019
user create mesh request for VR project
simple gui
'''
import json
import requests
# import getpass
from datetime import datetime
from time import gmtime, strftime, sleep
import time
import tkinter as tk
#-----------------------------------------------------------------------------------------
def add_body_to_list():
#-- get bodyID from entry, add to list --
body = bodyID.get()
request_list.append(body)
print(body)
return(request_list)
def get_request_data():
#-- request_id = userame.epoch --
if len(request_list) < 1:
return(request_list)
else:
now_time = datetime.now().strftime('%Y-%m-%d_%H%M%S')
epoch = timestamp_to_epoch(now_time)
username = user.get()
if username == "username":
print("Username Required!!")
return(username)
else:
request_id = username+"_"+str(epoch)
print("Your VR body request list:")
print(request_list)
project = {
"requestID": request_id,
"user": username,
"time" : epoch,
"timestamp" : now_time,
"body_list" : request_list
}
VR_project_request = {request_id: project}
send_request(request_id, project)
def send_request(request_id, VR_project_request):
# print(request_id)
print("Your VR project request list: ")
print(VR_project_request)
#-- close gui opon request submit --
#win.quit()
# #-- write request to api --
converted_to_json = json.dumps(VR_project_request)
print(converted_to_json)
url_to_write_to = "http://127.0.0.1:8000/request/"
requests.post(url_to_write_to, json=json.loads(converted_to_json))
#-- convert timestamp to epoch for id --
def timestamp_to_epoch(timestamp):
timestamp_format = '%Y-%m-%d %H:%M:%S'
epoch = int(time.mktime(time.strptime(timestamp, timestamp_format)))
return epoch
#------------------------------------------------------------------------------------
if __name__ == '__main__':
request_list = []
#-- Create instance --
win = tk.Tk()
#-- add title--
win.title("VR Mesh Project Request")
#-- Add text box Entry form --
tk.Label(win, text="Username").grid(column=0, row=0)
user = tk.StringVar(value="username")
user_entered = tk.Entry(win, width=0, textvariable=user)
user_entered.grid(column=0, row=1, columnspan=1)
#-- Add text box Entry form --
tk.Label(win, text="Add BodyID To List").grid(column=2, row=0)
bodyID = tk.IntVar(value="bodyID")
bodyID_entered = tk.Entry(win, width=20, textvariable=bodyID)
bodyID_entered.grid(column=2, row=1, columnspan=1)
btn = tk.Button(text = 'Add to List', command = add_body_to_list)
btn.grid(column=2, row=6)
#-- adding a button --
action = tk.Button(win, text="Submit Request", command=get_request_data)
action.grid(column=0, row=6)
#-- adding a button --
action = tk.Button(win, text="Quit", command=win.quit)
action.grid(column=1, row=8)
#-- start gui --
win.mainloop()