You've already forked AiraPulsar
"锚定点" 功能更新
This commit is contained in:
@@ -1,22 +1,48 @@
|
||||
import vgl
|
||||
import colorama
|
||||
import os
|
||||
import importlib.util
|
||||
|
||||
def run_components():
|
||||
window = vgl.Window(title="Pulsar", size=(1024, 768))
|
||||
|
||||
def loader():
|
||||
components_dir = "components"
|
||||
for filename in os.listdir(components_dir):
|
||||
if filename.endswith(".py") and filename != "__init__.py":
|
||||
module_name = filename[:-3] # 去掉 .py 后缀
|
||||
module_path = os.path.join(components_dir, filename)
|
||||
for i in os.listdir(components_dir):
|
||||
if i.endswith(".py") and (not i.startswith("__")):
|
||||
module_name = i[:-3]
|
||||
module_path = os.path.join(components_dir, i)
|
||||
|
||||
spec = importlib.util.spec_from_file_location(module_name, module_path)
|
||||
module = importlib.util.module_from_spec(spec)
|
||||
spec.loader.exec_module(module)
|
||||
try:
|
||||
if hasattr(module, "main") and callable(module.main):
|
||||
print(f"[ .... ] Starting {module.name} module")
|
||||
try:
|
||||
module.main(window=window)
|
||||
print(f"[{colorama.Fore.GREEN} OK {colorama.Style.RESET_ALL}] Started {module.name} module")
|
||||
except Exception as e:
|
||||
print(f"[{colorama.Fore.RED}FAILED{colorama.Style.RESET_ALL}] Failed to start {module_name} module: {e}")
|
||||
except:
|
||||
print(f"Unsupported module: {module_name}.py")
|
||||
|
||||
if hasattr(module, "main") and callable(module.main):
|
||||
print(f"正在调用 {module_name}.main()")
|
||||
module.main()
|
||||
else:
|
||||
print(f"{module_name}.py 中没有找到 main 函数或 main 不是可调用对象。")
|
||||
def console():
|
||||
print("You've entered Pulsar's command console, an embbedded Python interpreter for debugging & testing")
|
||||
while True:
|
||||
try:
|
||||
i = input(">>> ")
|
||||
if i == "q":
|
||||
return
|
||||
exec(i)
|
||||
except:
|
||||
print("An error occured & captured")
|
||||
|
||||
if __name__ == "__main__":
|
||||
run_components()
|
||||
if __name__ == '__main__':
|
||||
os.chdir(os.path.dirname(os.path.abspath(__file__)))
|
||||
print("Tester")
|
||||
window.start()
|
||||
loader()
|
||||
console()
|
||||
print("Quitting")
|
||||
window.kill()
|
||||
exit()
|
||||
Reference in New Issue
Block a user