This commit is contained in:
leo
2023-12-31 16:11:21 +08:00
commit 8fd4948ee4
14 changed files with 315 additions and 0 deletions

43
main.py Normal file
View File

@@ -0,0 +1,43 @@
import os
import streamlit as st
from app.core import settings
def select_file():
...
def new_file():
new_file_name = st.session_state.new_file
if not new_file_name.endswith('.py'):
new_file_name = f'{new_file_name}.py'
with open(os.path.join(settings.BASE_DIR, 'pages', new_file_name), 'w') as f:
f.write('''
#!/usr/bin/env python3
# -*- coding:utf-8 -*-
import streamlit as st
st.write('Hello World!')
''')
with st.sidebar:
pages = os.listdir(os.path.join(settings.BASE_DIR, 'pages'))
pages = [{
'filename': page,
'filepath': os.path.join(settings.BASE_DIR, 'pages', page)
} for page in pages if page.endswith('.py') and page != '__init__.py']
option = st.selectbox(
'How would you like to be contacted?',
pages,
index=0,
format_func=lambda x: x['filename'],
on_change=select_file,
key='page_file'
)
st.write('You selected:', option)
st.text_input('新建文件', on_change=new_file, key='new_file')