1212if not Demo_mode :
1313 import translators as ts
1414import importlib
15+ from streamlit_ace import st_ace
16+ #from streamlit_extras.jupyterlite import jupyterlite
1517
16- version = "1.41"
18+
19+ version = "1.50"
1720
1821st .set_page_config (
1922 page_title = "Parrot OCE" ,
@@ -171,8 +174,14 @@ def translat(text):
171174
172175col1 , col2 = st .columns ([0.7 ,0.3 ])
173176with col1 :
174- codes = st .text_area (":material/code: Python代码块" ,height = 400 ,value = '''print("hello POCE!")
175- print("I love python3.10!")''' )
177+ codes = st_ace (language = 'python' ,theme = 'chaos' ,height = 500 , font_size = col2 .number_input ("字体大小" , 16 , 24 , 16 ),auto_update = True ,value = '''texts = ["hello POCE!", "I love python3.10!"]
178+ for i in texts:
179+ print(i)''' )
180+ #jupyterlite(600, 1600)
181+
182+ # Display editor's content as you type
183+ #st.text_area(":material/code: Python代码块",height=400,value='''print("hello POCE!")
184+ #print("I love python3.10!")''')
176185 st .download_button (
177186 label = ":material/download: 下载代码块" ,
178187 data = codes ,
@@ -184,69 +193,67 @@ def translat(text):
184193 #with st.container(border=True):
185194 option = st .radio (
186195 ":material/memory: 运行器" ,
187- ("POCE内置" , "Eval" , "WT远程执行 " ),
196+ ("POCE内置" , "Eval" , "Jupyterlite(未实现) " ),
188197 captions = [
189198 "用于处理复杂代码" ,
190199 "适用于数学及字符串运算" ,
191- "在远程WT服务器上执行 " ,
200+ "使用Jupyterlite沙盒运行(等待实现中) " ,
192201 ],
193202 )
194- if option == "WT远程执行" :
195- WT_address = st .text_input ("WT服务器地址" )
196- WT_password = st .text_input ("WT服务器密钥" )
197- elif option == "Eval" :
203+ if option == "Eval" :
198204 snf = st .toggle ("结果采用科学计数法" )
199- if st .button (":material/build: 运行" ,use_container_width = True ):
200- with st .spinner ("运行代码中..." ):
201- code = codes
202- result = "没有可用结果输出"
203- allowth = True
204- sp = True
205- found_usp = []
206- for i in Unsupported :
207- if not 'R' in i :
208- if f"import { i } " in code :
209- sp = False
210- found_usp .append (i )
211- else :
212- if i .replace ("R" ,"" ) in code :
213- sp = False
214- found_usp .append (i .replace ("R" ,"" ))
215- if sp :
216- if option == "POCE内置" :
217- captured_output = StringIO ()
218- original_stdout = sys .stdout
219- sys .stdout = captured_output
220- code_to_execute = codes
221- try :
222- exec (code_to_execute , globals ())
223- result_vars = locals ()
224- except Exception as e :
225- result = f"运行错误: { str (e )} "
226- else :
227- output = captured_output .getvalue ().strip ()
228- result = output or result_vars .get ('result' , None )
229- finally :
230- sys .stdout = original_stdout
231- if result == "没有可用结果输出" :
232- allowth = False
233- vote (result ,allowta = allowth ,allowdown = allowth )
234- elif option == "Eval" :
235- try :
236- if type (eval (code )) == bool :
237- if eval (code ) == True :
238- vote (":material/check: 成立" ,types = 'bool' ,colors = 'green' ,allowta = False ,allowdown = False )
239- elif eval (code ) == False :
240- vote (":material/close: 不成立" ,types = 'bool' ,colors = 'red' ,allowta = False ,allowdown = False )
205+ if not option == "Jupyterlite" :
206+ if st .button (":material/build: 运行" ,use_container_width = True ):
207+ with st .spinner ("运行代码中..." ):
208+ code = codes
209+ result = "没有可用结果输出"
210+ allowth = True
211+ sp = True
212+ found_usp = []
213+ for i in Unsupported :
214+ if not 'R' in i :
215+ if f"import { i } " in code :
216+ sp = False
217+ found_usp .append (i )
218+ else :
219+ if i .replace ("R" ,"" ) in code :
220+ sp = False
221+ found_usp .append (i .replace ("R" ,"" ))
222+ if sp :
223+ if option == "POCE内置" :
224+ captured_output = StringIO ()
225+ original_stdout = sys .stdout
226+ sys .stdout = captured_output
227+ code_to_execute = codes
228+ try :
229+ exec (code_to_execute , globals ())
230+ result_vars = locals ()
231+ except Exception as e :
232+ result = f"运行错误: { str (e )} "
241233 else :
242- if snf :
243- vote (format_to_scientific (eval (code )),allowta = True )
234+ output = captured_output .getvalue ().strip ()
235+ result = output or result_vars .get ('result' , None )
236+ finally :
237+ sys .stdout = original_stdout
238+ if result == "没有可用结果输出" :
239+ allowth = False
240+ vote (result ,allowta = allowth ,allowdown = allowth )
241+ elif option == "Eval" :
242+ try :
243+ if type (eval (code )) == bool :
244+ if eval (code ) == True :
245+ vote (":material/check: 成立" ,types = 'bool' ,colors = 'green' ,allowta = False ,allowdown = False )
246+ elif eval (code ) == False :
247+ vote (":material/close: 不成立" ,types = 'bool' ,colors = 'red' ,allowta = False ,allowdown = False )
244248 else :
245- vote (eval (code ),allowta = True )
246- except :
247- errors (f'''请检查您的eval函数代码块语法,如想运行复杂代码,请使用POCE内置运行器''' )
248- else :
249- errors (f'''代码块中出现了POCE不支持的库或方法!{ found_usp } ''' )
249+ if snf :
250+ vote (format_to_scientific (eval (code )),allowta = True )
251+ else :
252+ vote (eval (code ),allowta = True )
253+ except :
254+ errors (f'''请检查您的eval函数代码块语法,如想运行复杂代码,请使用POCE内置运行器''' )
255+ else :
256+ errors (f'''代码块中出现了POCE不支持的库或方法!{ found_usp } ''' )
250257
251258with st .sidebar :
252259 st .title ("模块操作面板" )
@@ -326,4 +333,4 @@ def translat(text):
326333 st .caption (f"搜索结果 (共{ len (methods )} 个)" )
327334 st .json (methods )
328335 except :
329- st .error ("模块导入失败" )
336+ st .error ("模块导入失败" )
0 commit comments