Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
P
PizzaPalace
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Container registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
GitLab community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
TheJoeCoder
PizzaPalace
Commits
b59b24a0
Verified
Commit
b59b24a0
authored
2 years ago
by
TheJoeCoder
Browse files
Options
Downloads
Patches
Plain Diff
[Frontend] Add logging, connection, tabs
parent
b6147d25
No related branches found
No related tags found
No related merge requests found
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
client/pizza_palace.py
+91
-24
91 additions, 24 deletions
client/pizza_palace.py
with
91 additions
and
24 deletions
client/pizza_palace.py
+
91
−
24
View file @
b59b24a0
import
json
,
requests
import
json
,
requests
,
logging
from
tkinter
import
messagebox
,
ttk
from
tkinter
import
*
## Init
root
=
Tk
()
logging
.
basicConfig
(
level
=
logging
.
INFO
)
logger
=
logging
.
getLogger
(
__name__
)
logger
.
setLevel
(
logging
.
DEBUG
)
## Global Variables
connect_url
=
StringVar
()
cart_id
=
""
cart_key
=
""
## Subroutines
def
get_endpoint
(
endpoint
):
return
connect_url
.
get
()
+
endpoint
def
submit
(
*
args
):
messagebox
.
showinfo
(
"
Not implemented
"
,
"
Not just yet...
"
)
# Create frame
def
create_tab
(
title
,
padding
=
"
3 3 12 12
"
,
sticky
=
(
N
,
W
,
E
,
S
)):
frame
=
ttk
.
Frame
(
tab_control
,
padding
=
padding
)
frame
.
grid
(
column
=
0
,
row
=
0
,
sticky
=
sticky
)
frame
.
columnconfigure
(
0
,
weight
=
1
)
frame
.
rowconfigure
(
0
,
weight
=
1
)
tab_control
.
add
(
frame
,
text
=
title
)
return
frame
# Configure grid for frame
def
configure_grid
(
frame
):
for
child
in
connect_frame
.
winfo_children
():
child
.
grid_configure
(
padx
=
5
,
pady
=
5
)
# General connect fail function
# Used when the server is unreachable or returns a non-200 response
# both in the initial connection attempt and in other screens
# where a server request is made
def
connect_fail
():
logger
.
error
(
"
Connection Failed
"
)
connect_status_label
.
configure
(
text
=
"
Connection failed
"
)
tab_control
.
select
(
connect_frame
)
messagebox
.
showerror
(
"
Connection failed
"
,
"
Could not connect to server
"
)
# Connection success fail function
# Used when the server is reachable and all is ok
# in the initial connection attempt
def
connect_success
():
logger
.
info
(
"
Successfully connected to
"
+
connect_url
.
get
())
connect_status_label
.
configure
(
text
=
"
Connected
"
)
tab_control
.
select
(
order_frame
)
messagebox
.
showinfo
(
"
OK!
"
,
"
Successfully connected
"
)
# Connect function for the connect tab
def
connect
(
*
args
):
logger
.
info
(
"
Attempting to connect to
"
+
connect_url
.
get
())
try
:
res
=
requests
.
get
(
get_endpoint
(
"
/
"
))
if
res
.
status_code
==
200
:
res
=
requests
.
get
(
get_endpoint
(
"
/
status
"
))
if
(
res
.
status_code
==
200
)
:
# Success
# TODO check for valid JSON response, possibly change to /status endpoint
messagebox
.
showinfo
(
"
OK!
"
,
"
Successfully connected
"
)
connect_status_label
.
configure
(
text
=
"
Connected
"
)
# TODO focus on other tab
logger
.
debug
(
"
Got 200 response from server
"
)
try
:
res_json
=
json
.
loads
(
res
.
text
)
if
(
res_json
[
"
status
"
]
==
200
and
res_json
[
"
message
"
]
==
"
ok
"
):
connect_success
()
return
else
:
# Failure
# TODO failure message
pass
logger
.
debug
(
"
Response from server did not contain OK
"
)
connect_fail
()
return
except
:
logger
.
debug
(
"
Could not parse JSON response from server
"
)
logger
.
debug
(
res
.
text
)
connect_fail
()
return
else
:
logger
.
debug
(
"
Got non-200 response from server
"
)
connect_fail
()
return
except
:
# Failure
# TODO failure message
connect_fail
()
return
# Create new session
def
new_session
(
*
arg
):
pass
# Refresh order screen items
def
refresh_items
(
*
args
):
# TODO get /pizzas from server
pass
## Main program code
# Window setup
root
.
title
(
"
Pizza Palace
"
)
tab_control
=
ttk
.
Notebook
(
root
)
connect_frame
=
ttk
.
Frame
(
tab_control
,
padding
=
"
3 3 12 12
"
)
connect_frame
.
grid
(
column
=
0
,
row
=
0
,
sticky
=
(
N
,
W
,
E
,
S
))
connect_frame
.
columnconfigure
(
0
,
weight
=
1
)
connect_frame
.
rowconfigure
(
0
,
weight
=
1
)
# Connect tab
connect_frame
=
create_tab
(
"
Connect
"
)
connect_url_label
=
ttk
.
Label
(
connect_frame
,
text
=
"
Server URL:
"
)
connect_url_field
=
ttk
.
Entry
(
connect_frame
,
width
=
20
,
textvariable
=
connect_url
)
...
...
@@ -54,15 +112,24 @@ connect_status_label.grid(column=1, row=2, sticky=(W, E))
connect_submit_button
=
ttk
.
Button
(
connect_frame
,
text
=
"
Go!
"
,
command
=
connect
)
connect_submit_button
.
grid
(
column
=
1
,
row
=
3
,
sticky
=
(
W
,
E
))
for
child
in
connect_frame
.
winfo_children
():
child
.
grid_configure
(
padx
=
5
,
pady
=
5
)
configure_grid
(
connect_frame
)
connect_submit_button
.
focus
()
connect_frame
.
bind
(
"
<Return>
"
,
submit
)
connect_frame
.
bind
(
"
<Return>
"
,
connect
)
# Order tab
order_frame
=
create_tab
(
"
Order
"
)
# TODO order list
# Cart tab
cart_frame
=
create_tab
(
"
Cart
"
)
# Confirm tab
confirm_frame
=
create_tab
(
"
Confirm
"
)
# TODO other tabs
tab_control
.
add
(
connect_frame
,
text
=
"
Connect
"
)
# Pack
tab_control
.
pack
(
expand
=
1
,
fill
=
"
both
"
)
# Main window loop
root
.
mainloop
()
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment