Skip to content

Commit

Permalink
Fix GUI webapp
Browse files Browse the repository at this point in the history
  • Loading branch information
protago90 committed Jan 21, 2022
1 parent b4df92e commit 767bef8
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 6 deletions.
2 changes: 1 addition & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,4 @@ EXPOSE 8501

ENTRYPOINT ["streamlit", "run"]

CMD ["streamlit.py"]
CMD ["streamgui.py"]
23 changes: 18 additions & 5 deletions streamlit.py → streamgui.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,13 @@
from PIL import Image
from typing import Callable, Optional
import streamlit as st
ses = st.session_state # streamlit's global session variable


AUTHOR = 'Michal Gruszczyński'
CONTACT = '[contact](https://www.linkedin.com/in/protago90/)'
SOURCE = '[source-code](https://github.com/protago90/tictactoe-ring)'
UNI = '[uni](https://www.math.uni.lodz.pl/)'

PLAYGROUND = 'PLAYGROUND'
TOURNAMENT = 'TOURNAMENT'
XSIGN, XLOGO, HFACE = 'X', '❌', '🙇'
Expand All @@ -16,8 +20,10 @@
END = 'The game is over with draw.'
VERSUS = '{} -vs- {}'
LINE = '---'
LINK = '🔗'
PLAY = '▶︎'
REP = '↻'
DOT = '•‌'
NULL = ''

LOGO = 'misc/logo.png'
Expand Down Expand Up @@ -67,7 +73,12 @@ def show_intro() -> None:
try:
welcome = Image.open(LOGO)
st.image(welcome)
except: pass
except: print('zonk')

def show_meta() -> None:
st.sidebar.write('---')
st.sidebar.write(f'by {AUTHOR}')
st.sidebar.write(f'{CONTACT} {DOT} {SOURCE} {DOT} {UNI}')

def show_plyrs_modes_ui() -> None:
plyrs = PLYRS if ses.mode == PLAYGROUND else BOTS
Expand Down Expand Up @@ -100,7 +111,7 @@ def show_vs() -> None:
if ses.mode == TOURNAMENT:
ses.bar = st.progress(0)
st.write(LINE)
c = st.columns((.98, .27, 1))
c = st.columns((.99, .28, 1))
c[1].write(VERSUS.format(
*(HFACE if _id == HumanUI.ID else BFACE for _id in (ses.x_plyr.ID, ses.o_plyr.ID))))

Expand Down Expand Up @@ -135,8 +146,7 @@ def show_readme_app() -> None:


st.set_page_config(page_title=XSIGN+OSIGN, page_icon=XLOGO, layout='centered')
show_intro()
if 'mode' not in ses: init_session(HumanUI.ID, BOT, mode=PLAYGROUND) # TODO: rethink session init
ses = st.session_state # streamlit's global session variable

APPS_REPO = {
PLAYGROUND: show_playground_app,
Expand All @@ -146,6 +156,9 @@ def show_readme_app() -> None:


if __name__ == "__main__":
show_intro()
if 'mode' not in ses: init_session(HumanUI.ID, BOT, mode=PLAYGROUND) # TODO: rethink session init
st.sidebar.title('Menu:')
app_name = st.sidebar.radio(NULL, list(APPS_REPO.keys()))
show_meta()
APPS_REPO.get(app_name)()

0 comments on commit 767bef8

Please sign in to comment.