-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpage_template.py
More file actions
100 lines (74 loc) · 2.62 KB
/
page_template.py
File metadata and controls
100 lines (74 loc) · 2.62 KB
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
from code_template import CodeTemplate
from page_base import BasePage
from util_template import *
from util_web import *
from ss import ss
class Template(BasePage):
CurrentTemplate: CodeTemplate = None
def __init__(self):
super().__init__()
self.templates = []
self.cmds = []
self.source = None
self.c1 = None
self.c0 = None
def initData(self):
self.templates = [x for x in os.listdir(TemplateFolder) if x.endswith('.py')]
self.source = currentSourceFile()
self.cmds = [
['edit', editCurrentTemplate],
# ['add', self.add],
# ['clone', self.clone],
# ['remove', self.remove],
]
def initUi(self):
with st.sidebar:
st.button('Home', on_click=toHomePage)
st.title(colorText('orange', 'Template list'))
selected = st.radio(
"template list",
self.templates,
label_visibility='collapsed',
format_func=lambda x: ss(x).green()
)
if len(selected) > 0:
setSessionState(TemplateKey, selected)
self.showTemplateFile()
if st.button(f'make {currentSourceFile()}', type='primary', use_container_width=True):
t = Template.CurrentTemplate
if t is None:
st.warning('No template selected')
else:
if t.checkArgs():
cs = st.columns(2)
cs[0].button('OK', type='primary', on_click=self.generate)
cs[1].button('Cancel', type='primary')
cs = st.columns(2)
for n, (name, f) in enumerate(self.cmds):
if cs[n % 2].button(name):
f()
t = Template.CurrentTemplate = currentTemplate()
if t is not None:
t.showArgs()
self.c0, self.c1 = st.columns([6, 4])
self.showSource()
t.showTemplate(self.c0)
def showTemplateFile(self):
c = self.container
c.subheader(f'{ss("arguments").orange().bold()} {blank(1)} {ss(currentSourceFile()).green().bold()}')
@log
def clone(self):
pass
@log
def remove(self):
pass
def showSource(self):
c1 = self.c1
c1.write(f'### {ss("template").orange()} {blank(1)} {ss(currentSourceFile()).green()}')
c1.code(currentSource())
def add(self):
pass
def generate(self):
print('generate generate generate')
t = Template.CurrentTemplate
t.generateCode()