netgen/python/__main__.py

52 lines
1.1 KiB
Python
Raw Normal View History

2022-02-11 22:39:48 +05:00
import imp, threading, sys
2021-10-27 19:50:07 +05:00
def _py_handler(f):
with open(f) as pyfile:
imp.load_module('__main__', pyfile, f, (".py", "r", imp.PY_SOURCE))
def _geo_handler(f):
from netgen.csg import CSGeometry
print("load", f)
geo = CSGeometry(f)
geo.Draw()
def _step_handler(f):
from netgen.occ import OCCGeometry
print("load", f)
geo = OCCGeometry(f)
geo.Draw()
def _stl_handler(f):
from netgen.stl import STLGeometry
print("load", f)
geo = STLGeometry(f)
geo.Draw()
_file_handler = {}
_file_handler['.py'] = _py_handler
_file_handler['.geo'] = _geo_handler
_file_handler['.step'] = _step_handler
_file_handler['.stl'] = _stl_handler
2021-10-27 19:50:07 +05:00
def handle_arguments():
2022-02-11 22:39:48 +05:00
import __main__
import os.path
2021-10-27 19:50:07 +05:00
argv = sys.argv
if len(argv)>1:
_, ext = os.path.splitext(argv[1])
if ext in _file_handler:
_file_handler[ext](argv[1])
2021-10-27 19:50:07 +05:00
def main():
import netgen
# Use Redraw without event handling
netgen.Redraw = netgen._Redraw
2021-10-27 19:50:07 +05:00
from .gui import win
th = threading.Thread(target=handle_arguments)
th.start()
win.tk.mainloop()
if __name__ == "__main__":
sys.exit(main())