@@ -43,26 +43,32 @@ def binpython_releases_ver():
4343
4444def binpython_build_importlibs ():
4545 print (importlibs )
46+ #get system info(windows or linux ...)
4647import platform
4748sys = platform .system ()
48-
49+ #if system is windows, then enable setwindowtitle() function
4950if sys == "Windows" :
5051 def setwindowtitle (titlename ):
5152 import ctypes
5253 ctypes .windll .kernel32 .SetConsoleTitleW (titlename )
54+ #print binpython all configure function
5355def binpythonallconf ():
5456 print ("ver: " + ver + " buildversion: " + buildversion + " libs_warning settings:" + libs_warning + " releases full version: " + releases_ver + " custom library that has been build: " + importlibs )
57+ #if system is windows, show default window title
5558if sys == "Windows" :
5659 import ctypes
5760 ctypes .windll .kernel32 .SetConsoleTitleW ("BINPython " + ver )
61+ #binpython self import function
5862def self_import (name ):
5963 __import__ (name )
6064try :
6165 self_import (importlibs )
66+ #get libswarning
6267except ImportError :
6368 if libs_warning == "1" :
6469 print ("Warning: Custom import library %s does not exist, please check the source code library configuration and rebuild" % importlibs )
6570 print ("" )
71+ #run python files option(-f)
6672def optreadfile ():
6773 import sys
6874 getfile = sys .argv [1 ]
@@ -181,6 +187,7 @@ def binpython_shell():
181187
182188
183189#def
190+ #helpinfo base
184191helpinfobase = """
185192Usage: binpython [OPTIONS]
186193
@@ -193,10 +200,12 @@ def binpython_shell():
193200-g --gui View GUI About and build info
194201-i --idle Open BINPython IDLE Code Editor
195202"""
203+ #helpinfo plus
196204helpinfoplus = """
197205-p --plus Open BINPython IDE Plus Code Editor(beta) with http web server
198206-e --example Run various code examples through BINPython
199207"""
208+ #base + plus, print full help
200209def outputfullhelp ():
201210 try :
202211 f = open ("binpython_config/help.txt" ,encoding = "utf-8" )
@@ -206,20 +215,27 @@ def outputfullhelp():
206215 if buildversion == "plus" :
207216 print ("Additional options for the plus version" )
208217 print (helpinfoplus )
218+ #set about info
209219about = "BINPython " + ver + "-" + releases_ver + " By:XINGYUJIE[https://github.com/xingyujie/binpython] AGPL-3.0 LICENSE Release"
210220#getopt
211221try :
222+ #set options
212223 opts ,args = getopt .getopt (sys .argv [1 :],'-h-f:-s:-g-i-p-e-v' ,['help' ,'file=' ,'server=' ,'gui' ,'idle' ,'plus' ,'example' ,'version' ])
224+ #set getopt error prompt
213225except getopt .GetoptError as err :
214226 print ("Please check help:" )
215227 print ("The parameters you use do not exist or are not entered completely, please check help!!!!" )
228+ #then show full help(outputfullhelp())
216229 outputfullhelp ()
217230 sys .exit ()
231+ #get every option and run
218232for opt_name ,opt_value in opts :
219233 if opt_name in ('-h' ,'--help' ):
234+ #-h show full help function
220235 outputfullhelp ()
221236 sys .exit ()
222237 if opt_name in ('-v' ,'--version' ):
238+ #-v show version(read custom config)
223239 try :
224240 f = open ("binpython_config/version.py" ,encoding = "utf-8" )
225241 exec (f .read ())
@@ -229,11 +245,13 @@ def outputfullhelp():
229245 print ("Python " + platform .python_version ())
230246 sys .exit ()
231247 if opt_name in ('-f' ,'--file' ):
248+ #-f runfile(or no option)
232249 file = opt_value
233250 f = open (file ,encoding = "utf-8" )
234251 exec (f .read ())
235252 sys .exit ()
236253 if opt_name in ('-s' ,'--server' ):
254+ #-s set simple http server(support html or files transfer)
237255 server_port = opt_value
238256 exec ("""
239257PORT = """ + server_port + """
@@ -245,6 +263,7 @@ def outputfullhelp():
245263 httpd.serve_forever()
246264""" )
247265 if opt_name in ('-g' ,'--gui' ):
266+ #-g gui show gui about info(based on tkinter)
248267 from tkinter import *
249268 root = Tk ()
250269 root .title ("Welcome to BINPython" )
@@ -264,6 +283,7 @@ def show():
264283 os .system ('cls' if os .name == 'nt' else 'clear' )
265284 print ("<<<<<<<<<<START>>>>>>>>>>" )
266285 exec (e1 .get (1.0 , END ))
286+ #tkinter ide Simulation environment
267287 if opt_name in ('-i' ,'--idle' ):
268288 import tkinter as tk
269289 from tkinter import *
@@ -282,6 +302,7 @@ def show():
282302 tk .Button (master , text = "EXIT" , width = 10 , command = master .quit ).grid (row = 3 , column = 1 , sticky = "e" , padx = 10 , pady = 5 )
283303 master .mainloop ()
284304 sys .exit ()
305+ #-p binpython ideplus
285306 if opt_name in ('-p' ,'--plus' ):
286307 import pywebio .input
287308 from pywebio .input import *
@@ -298,12 +319,14 @@ def show():
298319Welcome to BINPython IDEPlus!
299320The service starts on port 22948 (http), the program will automatically open the browser, if not, please manually open http://localhost:22948 in the browser
300321""" )
322+ #open browser
301323 webbrowser .open ("http://localhost:22940" )
302324 #IDE Plus main
303325 def line ():
304326 put_text ('_______________________' ,
305327 sep = ' '
306328 )
329+ #set bootstrap ui(bar)
307330 def head ():
308331 set_env (title = "BINPython IDE Plus" , auto_scroll_bottom = True )
309332 put_html ("""
@@ -375,6 +398,7 @@ def welcomecard():
375398 </p>
376399</div>
377400""" )
401+ #index ui
378402 def index ():
379403 head ()
380404 welcomecard ()
@@ -392,6 +416,7 @@ def idehead():
392416 )
393417 line ()
394418 toast ("BINPython IDE Plus is a beta version. May be removed or changed in the future" )
419+ #ideplus
395420 def ideplus ():
396421 plushead ()
397422 idehead ()
@@ -409,6 +434,7 @@ def ideplus():
409434 f .write (res .encode ("utf-8" ))
410435 toast ("Successfully saved" )
411436 put_success ("The save is successful, and the code is saved to binpython file path" + " \n The file name is " + '"' + savecodefilename + '"' )
437+ #view code
412438 def viewcode ():
413439 plushead ()
414440 viewcode_code = pywebio .input .input ("Please input file path:" )
@@ -417,6 +443,7 @@ def viewcode():
417443 if __name__ == '__main__' :
418444 start_server ([index , ideplus , aboutideplus , viewcode ], debug = True , port = 22940 )
419445 pywebio .session .hold ()
446+ #binpython examples
420447 if opt_name in ('-e' ,'--example' ):
421448 print ("Welcome to BINPython example" )
422449 print ("""
@@ -431,6 +458,7 @@ def viewcode():
431458
432459 """ )
433460 examplenum = input ("Please enter the option you want to enter(like 1):" )
461+ #turtle
434462 if examplenum == "1" :
435463 def exampleturtle ():
436464 import turtle
@@ -445,6 +473,7 @@ def exampleturtle():
445473 turtle .done ()
446474 exampleturtle ()
447475 sys .exit ()
476+ #tkinter
448477 if examplenum == "2" :
449478 def exampletkinter ():
450479 import tkinter as tk
@@ -455,6 +484,7 @@ def exampletkinter():
455484 app .mainloop ()
456485 exampletkinter ()
457486 sys .exit ()
487+ #tornado
458488 if examplenum == "3" :
459489 def exampletornado ():
460490 import asyncio
@@ -476,6 +506,7 @@ async def main():
476506 print ("Server Started listen on port:8080(http://ip:8080)" )
477507 exampletornado ()
478508 sys .exit ()
509+ #pywebio
479510 if examplenum == "4" :
480511 import pywebio .input
481512 from pywebio .input import *
@@ -492,17 +523,20 @@ def main():
492523 pywebio .session .hold ()
493524 examplepywebio ()
494525 sys .exit ()
526+ #helloworld
495527 if examplenum == "5" :
496528 setwindowtitle ("Hi, Welcome to BINPython" )
497529 name = input ("hi...What's your name:" )
498530 print ("hi," + name )
499531 sys .exit ()
532+ #requests
500533 if examplenum == "6" :
501534 import requests
502535 def examplerequests ():
503536 print (requests .get ("http://google.com" ))
504537 examplerequests ()
505538 sys .exit ()
539+ #binpython function
506540 if examplenum == "7" :
507541 print ("BINPython() function example" )
508542 import time
@@ -517,12 +551,14 @@ def examplerequests():
517551 binpython_shell ()
518552 sys .exit ()
519553#go main shell
554+ #custom welcome script
520555try :
521556 f = open ("binpython_config/welcome.py" ,encoding = "utf-8" )
522557 exec (f .read ())
523558 print ("Powered by: BINPython[https://github.com/xingyujie/binpython] AGPL 3.0" )
524559except :
525560 binpython_welcome_text ()
561+ #debug mode show many info
526562try :
527563 f = open ("binpython_debug" ,encoding = "utf-8" )
528564 print ("Debug mode:on" )
@@ -545,7 +581,7 @@ def TestPlatform():
545581 TestPlatform ()
546582except :
547583 pass
548-
584+ #binpython custom function plugin
549585#plugin start
550586plugin_name = ''
551587def binpython_plugin_name (key ):
@@ -587,4 +623,5 @@ def binpython_plugin_loadmain(key):
587623 exec (startupcode .read ())
588624except :
589625 binpython_shell ()
626+ #go shell
590627binpython_shell ()
0 commit comments