|
| 1 | +""" |
| 2 | + @header binpython.py |
| 3 | + @author xingyujie https://github.com/xingyujie |
| 4 | + @abstract BINPython main file |
| 5 | +""" |
| 6 | +#BINPython By:XINGYUJIE AGPL-V3.0 LICENSE Release |
| 7 | +#Please follow the LICENSE AGPL-V3 |
| 8 | +#ide plus version |
| 9 | +#################################### |
| 10 | +#build configure |
| 11 | + |
| 12 | +ver="0.20-releases" |
| 13 | + |
| 14 | +libs_warning="1" |
| 15 | +#1 is ture 0 is false. |
| 16 | +#Changing the value to 0 will close the prompt that the library does not exist |
| 17 | + |
| 18 | +releases_ver="offical-with-ideplus" |
| 19 | +importlibs="os" #Don't use "import xxx" |
| 20 | +#Imported library name, please use "importlibs="<library name>" instead of "import <library name>" |
| 21 | +#Please note: The "importlibs" function does not support loading functions (such as from xxxx import xxxx, if necessary, please write it in the following location. However, please note that this operation may have the risk of error reporting, please report issues or solve it yourself |
| 22 | +#xxxxxxxxxxxxxx |
| 23 | + |
| 24 | +#from xxxx import xxxx |
| 25 | +#xxxxxxxxxxxxxx |
| 26 | +#################################### |
| 27 | +import ctypes |
| 28 | +ctypes.windll.kernel32.SetConsoleTitleW("BINPython " + ver) |
| 29 | +def self_import(name): |
| 30 | + __import__(name) |
| 31 | +try: |
| 32 | + self_import(importlibs) |
| 33 | +except ImportError: |
| 34 | + if libs_warning == "1": |
| 35 | + print("Warning: Custom import library %s does not exist, please check the source code library configuration and rebuild" % importlibs) |
| 36 | + print("") |
| 37 | +try: |
| 38 | +#base import |
| 39 | + import getopt |
| 40 | + import sys |
| 41 | + import platform |
| 42 | + import os |
| 43 | +#fix for exit() |
| 44 | + from sys import exit |
| 45 | +#import for http_server |
| 46 | + import http.server |
| 47 | + import socketserver |
| 48 | +#except ImportError: |
| 49 | +except ImportError: |
| 50 | + print("Unable to use any library, the program does not work properly, please rebuild") |
| 51 | +#gui import |
| 52 | +try: |
| 53 | + import tkinter |
| 54 | + import tkinter as tk |
| 55 | + from tkinter import * |
| 56 | + import turtle |
| 57 | +#warning for gui |
| 58 | +except ImportError: |
| 59 | + if libs_warning == "1": |
| 60 | + print("Warning: Some GUI (graphical) libraries for BINPython do not exist, such as tkinter and turtle. Because they are not built when they are built. If you need to fix this warning, please complete the support libraries imported in the source code at build time (use pip or build it yourself), if your system does not support these libraries, you can remove or change this hint in the source code and rebuild") |
| 61 | + print("") |
| 62 | + |
| 63 | +#import math |
| 64 | +try: |
| 65 | + import fractions |
| 66 | + import cmath |
| 67 | +except ImportError: |
| 68 | + if libs_warning == "1": |
| 69 | + print("Warning: Some math or computation libraries for BINPython do not exist, such as fractions and cmath. Because they weren't built when they were built. If you need to fix this warning, please complete the support libraries imported in the source code when building (use pip or build it yourself), if your system does not support these libraries, you can remove or change this prompt in the source code and rebuild") |
| 70 | + print("") |
| 71 | +#rlcompleter |
| 72 | +#import for normal |
| 73 | +try: |
| 74 | + #str |
| 75 | + import rlcompleter |
| 76 | + import array |
| 77 | +except ImportError: |
| 78 | + if libs_warning == "1": |
| 79 | + print("Warning: Some libraries for functions, data types, etc. for BINPython do not exist, such as rlcomplter and array. Because they weren't built when they were built. If you need to fix this warning, please complete the support libraries imported in the source code when building (use pip or build it yourself), if your system does not support these libraries, you can remove or change this prompt in the source code and rebuild") |
| 80 | + print("") |
| 81 | +try: |
| 82 | + import filecmp |
| 83 | + import tempfile |
| 84 | +except ImportError: |
| 85 | + if libs_warning == "1": |
| 86 | + print("Warning: Some file manipulation libraries for BINPython do not exist, such as filecmp and tempfile. Because they weren't built when they were built. If you need to fix this warning, please complete the support libraries imported in the source code when building (use pip or build it yourself), if your system does not support these libraries, you can remove or change this prompt in the source code and rebuild") |
| 87 | + print("") |
| 88 | +#def |
| 89 | +def help(): |
| 90 | + print("[*] BINPython Help") |
| 91 | + print(""" |
| 92 | +-h --help View this help |
| 93 | +-f <filename> --file=<filename> Enter Python Filename and run (*.py) |
| 94 | +-s <port> --server=<port> Start a simple web server that supports html and file transfer (http.server) |
| 95 | +-v --version View BINPython Version |
| 96 | +-g --gui View GUI About and build info |
| 97 | +-i --idle Open BINPython IDLE Code Editor |
| 98 | +-p --plus Open BINPython IDE Plus Code Editor(beta) with http web server |
| 99 | +""") |
| 100 | +about = "BINPython " + ver + "-" + releases_ver + " By:XINGYUJIE[https://github.com/xingyujie/binpython] AGPL-3.0 LICENSE Release" |
| 101 | +#getopt |
| 102 | +try: |
| 103 | + opts,args = getopt.getopt(sys.argv[1:],'-h-f:-s:-g-i-p-v',['help','file=','server=','gui','idle','plus','version']) |
| 104 | +except: |
| 105 | + print("Please check help:") |
| 106 | + help() |
| 107 | + print("The parameters you use do not exist or are not entered completely, please check help! ! ! ! !") |
| 108 | +for opt_name,opt_value in opts: |
| 109 | + if opt_name in ('-h','--help'): |
| 110 | + help() |
| 111 | + sys.exit() |
| 112 | + if opt_name in ('-v','--version'): |
| 113 | + print("BINPython " + ver + "-" + releases_ver + " By:XINGYUJIE[https://github.com/xingyujie/binpython] AGPL-3.0 LICENSE Release") |
| 114 | + print("Python " + platform.python_version()) |
| 115 | + exit() |
| 116 | + if opt_name in ('-f','--file'): |
| 117 | + file = opt_value |
| 118 | + f = open(file,encoding = "utf-8") |
| 119 | + exec(f.read()) |
| 120 | + input("Please enter to continue") |
| 121 | + sys.exit() |
| 122 | + if opt_name in ('-s','--server'): |
| 123 | + server_port = opt_value |
| 124 | + print(""" |
| 125 | +PORT = """ + server_port + """ |
| 126 | +
|
| 127 | +Handler = http.server.SimpleHTTPRequestHandler |
| 128 | +
|
| 129 | +with socketserver.TCPServer(("", PORT), Handler) as httpd: |
| 130 | + print("serving at port", PORT) |
| 131 | + httpd.serve_forever() |
| 132 | +""") |
| 133 | + if opt_name in ('-g','--gui'): |
| 134 | + from tkinter import * |
| 135 | + root = Tk() |
| 136 | + root.title("Welcome to BINPython") |
| 137 | + root.geometry('600x300') |
| 138 | + text =Text(root, width=35, heigh=15) |
| 139 | + text.pack() |
| 140 | + text.insert("insert", "BINPython" + about) |
| 141 | + print(text.get("1.3", "1.end")) |
| 142 | + #### |
| 143 | + text=Label(root,text="Welcome to BINPython" + ver,bg="yellow",fg="red",font=('Times', 20, 'bold italic')) |
| 144 | + text.pack() |
| 145 | + button=Button(root,text="EXIT",command=root.quit) |
| 146 | + button.pack(side="bottom") |
| 147 | + root.mainloop() |
| 148 | + sys.exit() |
| 149 | + def show(): |
| 150 | + os.system('cls' if os.name == 'nt' else 'clear') |
| 151 | + print("<<<<<<<<<<START>>>>>>>>>>") |
| 152 | + exec(e1.get(1.0, END)) |
| 153 | + if opt_name in ('-i','--idle'): |
| 154 | + import tkinter as tk |
| 155 | + from tkinter import * |
| 156 | + import os |
| 157 | + master = tk.Tk() |
| 158 | + master.title("BINPython IDLE") |
| 159 | + |
| 160 | + |
| 161 | + tk.Label(master, text="Type Code", height=5).grid(row=0) |
| 162 | + |
| 163 | + e1 = Text(master, |
| 164 | + width=150, |
| 165 | + height=40,) |
| 166 | + |
| 167 | + e1.grid(row=0, column=1, padx=10, pady=5) |
| 168 | + tk.Button(master, text="Run", width=10, command=show).grid(row=3, column=0, sticky="w", padx=10, pady=5) |
| 169 | + tk.Button(master, text="EXIT", width=10, command=master.quit).grid(row=3, column=1, sticky="e", padx=10, pady=5) |
| 170 | + master.mainloop() |
| 171 | + if opt_name in ('-p','--plus'): |
| 172 | + serverport = input("Please enter server port(like 8080): ") |
| 173 | + import pywebio.input |
| 174 | + from pywebio.input import * |
| 175 | + from pywebio.output import * |
| 176 | + from pywebio import * |
| 177 | + from pywebio.session import * |
| 178 | + import sys |
| 179 | + import subprocess |
| 180 | + import os |
| 181 | + print("______________________________________") |
| 182 | + print("BINPython WEB IDE STARTED") |
| 183 | + #IDE Plus main |
| 184 | + def main(): |
| 185 | + set_env(title="BINPython IDE Plus", auto_scroll_bottom=True) |
| 186 | + put_html("<h1>BINPython IDE Plus</h1>") |
| 187 | + put_text('Welcome to BINPython IDE Plus, Please type code', |
| 188 | + sep=' ' |
| 189 | + ) |
| 190 | + toast("BINPython IDE Plus is a beta version. May be removed or changed in the future") |
| 191 | + put_text('_______________________', |
| 192 | + sep=' ' |
| 193 | + ) |
| 194 | + res = textarea('BINPython IDE Plus', rows=45, code={ |
| 195 | + 'mode': "python", |
| 196 | + 'theme': 'darcula' |
| 197 | + }) |
| 198 | + exec(res) |
| 199 | + toast("Run finished!") |
| 200 | + put_success("Finished, Please see BINPython Window or Terminal") |
| 201 | + put_text("Here is the code you wrote") |
| 202 | + put_code(res, language='python') |
| 203 | + savecodefilename = pywebio.input.input('Do you want to save the code you wrote to a file? Enter a filename and save it') |
| 204 | + f = open(savecodefilename, 'wb+') |
| 205 | + f.write(res.encode("utf-8")) |
| 206 | + toast("Successfully saved") |
| 207 | + put_success("The save is successful, and the code is saved to binpython file path" + " \nThe file name is " + '"' + savecodefilename + '"') |
| 208 | + if __name__ == '__main__': |
| 209 | + start_server(main, debug=True, host='0.0.0.0', port= serverport) |
| 210 | + pywebio.session.hold() |
| 211 | + |
| 212 | + |
| 213 | +#main BINPython |
| 214 | + |
| 215 | +print("BINPython " + ver + "-" + releases_ver + " (Python Version:" + platform.python_version() + ")By:XINGYUJIE https://github.com/xingyujie/binpython[Running on " + platform.platform() + " " + platform.version() + "]") |
| 216 | +print('Type "about", "help", "copyright", "credits" or "license" for more information.') |
| 217 | +try: |
| 218 | + while True: |
| 219 | + pycmd=input(">>> ") |
| 220 | + if pycmd in globals().keys(): |
| 221 | + print(globals()[pycmd]) |
| 222 | + continue |
| 223 | + elif pycmd == 'about': |
| 224 | + print("BINPython By:XINGYUJIE[https://github.com/xingyujie] AGPL-3.0 LICENSE Release") |
| 225 | + elif pycmd == 'help': |
| 226 | + print("Type help() for interactive help, or help(object) for help about object.") |
| 227 | + elif pycmd == 'copyright': |
| 228 | + print(""" |
| 229 | +Copyright (c) 2001-2022 Python Software Foundation and BINPython xingyujie(https://github.com/xingyujie/binpython). |
| 230 | +All Rights Reserved. |
| 231 | +
|
| 232 | +Copyright (c) 2000 BeOpen.com. |
| 233 | +All Rights Reserved. |
| 234 | +
|
| 235 | +Copyright (c) 1995-2001 Corporation for National Research Initiatives. |
| 236 | +All Rights Reserved. |
| 237 | +
|
| 238 | +Copyright (c) 1991-1995 Stichting Mathematisch Centrum, Amsterdam. |
| 239 | +All Rights Reserved. |
| 240 | +""") |
| 241 | + elif pycmd == 'credits': |
| 242 | + print(""" |
| 243 | +Thanks to CWI, CNRI, BeOpen.com, Zope Corporation and a cast of thousands |
| 244 | + for supporting Python development. See www.python.org for more information. |
| 245 | + """) |
| 246 | + elif pycmd == 'license': |
| 247 | + print("Type license() to see the full license text") |
| 248 | + try: |
| 249 | + exec(pycmd) |
| 250 | + except Exception as err: |
| 251 | + print(err) |
| 252 | +except KeyboardInterrupt: |
| 253 | + print("EXIT!") |
| 254 | + sys.exit() |
| 255 | + |
0 commit comments