48 lines
1.6 KiB
Python
48 lines
1.6 KiB
Python
import vgl
|
|
import colorama
|
|
import os
|
|
import importlib.util
|
|
|
|
window = vgl.Window(title="Pulsar", size=(1024, 768))
|
|
|
|
def loader():
|
|
components_dir = "components"
|
|
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")
|
|
|
|
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__':
|
|
os.chdir(os.path.dirname(os.path.abspath(__file__)))
|
|
print("Tester")
|
|
window.start()
|
|
loader()
|
|
console()
|
|
print("Quitting")
|
|
window.kill()
|
|
exit() |