Add basic components support
This commit is contained in:
parent
27d7ffe4bf
commit
fd67663868
0
pulsar/components/__horizontal_indicator.py
Normal file
0
pulsar/components/__horizontal_indicator.py
Normal file
BIN
pulsar/components/__pycache__/marking_lines.cpython-312.pyc
Normal file
BIN
pulsar/components/__pycache__/marking_lines.cpython-312.pyc
Normal file
Binary file not shown.
21
pulsar/components/marking_lines.py
Normal file
21
pulsar/components/marking_lines.py
Normal file
@ -0,0 +1,21 @@
|
||||
import vgl
|
||||
|
||||
|
||||
name = "Marking Lines"
|
||||
|
||||
def main(window):
|
||||
frame = vgl.Frame().attach(window_object=window, poscale=(0,0), clone_name="Marking Line")
|
||||
lines = list()
|
||||
for i in range(0, 24):
|
||||
lines.append(vgl.elements.Line(ends=[(0, i/24), (1, i/24)], color="green").attach(frame_object=frame))
|
||||
for i in range(0, 32):
|
||||
lines.append(vgl.elements.Line(ends=[(i/32, 0), (i/32, 1)], color="green").attach(frame_object=frame))
|
||||
# We monitor events like this.
|
||||
@window.observerize
|
||||
def observer(info):
|
||||
if info["delta"] == "key":
|
||||
print(info)
|
||||
# We make changes like this.
|
||||
for i in lines:
|
||||
i.set_color('#' + str((info['cursor']['position'][0] + info['cursor']['position'][1]*100 + info['cursor']['position'][0]*10000) % 999999).zfill(6))
|
||||
observer()
|
@ -1,46 +0,0 @@
|
||||
import vgl
|
||||
import time
|
||||
|
||||
window = vgl.Window(title="Pulsar", size=(1024, 768))
|
||||
|
||||
def horizontal_indicator():
|
||||
global window
|
||||
frame = vgl.Frame().attach(window_object=window, poscale=(0, 0), clone_name="Horizontal Indicator")
|
||||
vgl.elements.Line(ends=[(0.4, 0.5), (0.6, 0.5)], color="green").attach(frame_object=frame)
|
||||
pass
|
||||
|
||||
@window.observerize
|
||||
def observer(info):
|
||||
if info["delta"] == "key":
|
||||
print(info)
|
||||
pass
|
||||
|
||||
def marking_lines():
|
||||
global window
|
||||
frame = vgl.Frame().attach(window_object=window, poscale=(0,0), clone_name="Marking Line")
|
||||
for i in range(0, 24):
|
||||
vgl.elements.Line(ends=[(0, i/24), (1, i/24)], color="green").attach(frame_object=frame)
|
||||
for i in range(0, 32):
|
||||
vgl.elements.Line(ends=[(i/32, 0), (i/32, 1)], color="green").attach(frame_object=frame)
|
||||
|
||||
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 caused & captured")
|
||||
|
||||
if __name__ == '__main__':
|
||||
print("Welcome to AiraPulsar Client")
|
||||
window.start()
|
||||
horizontal_indicator()
|
||||
marking_lines()
|
||||
observer()
|
||||
console()
|
||||
input("任意键以退出")
|
||||
window.kill()
|
||||
exit()
|
@ -1,29 +1,30 @@
|
||||
import vgl
|
||||
import time
|
||||
import colorama
|
||||
import os
|
||||
import importlib.util
|
||||
|
||||
window = vgl.Window(title="Pulsar", size=(1024, 768))
|
||||
|
||||
def horizontal_indicator():
|
||||
global window
|
||||
frame = vgl.Frame().attach(window_object=window, poscale=(0, 0), clone_name="Horizontal Indicator")
|
||||
vgl.elements.Line(ends=[(0.4, 0.5), (0.6, 0.5)], color="green").attach(frame_object=frame)
|
||||
pass
|
||||
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)
|
||||
|
||||
def marking_lines():
|
||||
global window
|
||||
frame = vgl.Frame().attach(window_object=window, poscale=(0,0), clone_name="Marking Line")
|
||||
lines = list()
|
||||
for i in range(0, 24):
|
||||
lines.append(vgl.elements.Line(ends=[(0, i/24), (1, i/24)], color="green").attach(frame_object=frame))
|
||||
for i in range(0, 32):
|
||||
lines.append(vgl.elements.Line(ends=[(i/32, 0), (i/32, 1)], color="green").attach(frame_object=frame))
|
||||
@window.observerize
|
||||
def observer(info):
|
||||
if info["delta"] == "key":
|
||||
print(info)
|
||||
for i in lines:
|
||||
i.set_color('#' + str((info['cursor']['position'][0] + info['cursor']['position'][1]*100 + info['cursor']['position'][0]*10000) % 999999).zfill(6))
|
||||
observer()
|
||||
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")
|
||||
@ -37,11 +38,11 @@ def console():
|
||||
print("An error occured & captured")
|
||||
|
||||
if __name__ == '__main__':
|
||||
os.chdir(os.path.dirname(os.path.abspath(__file__)))
|
||||
print("Welcome to AiraPulsar Client")
|
||||
window.start()
|
||||
horizontal_indicator()
|
||||
marking_lines()
|
||||
loader()
|
||||
console()
|
||||
input("任意键以退出")
|
||||
print("Quitting")
|
||||
window.kill()
|
||||
exit()
|
22
pulsar/tester.py
Normal file
22
pulsar/tester.py
Normal file
@ -0,0 +1,22 @@
|
||||
import os
|
||||
import importlib.util
|
||||
|
||||
def run_components():
|
||||
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)
|
||||
|
||||
spec = importlib.util.spec_from_file_location(module_name, module_path)
|
||||
module = importlib.util.module_from_spec(spec)
|
||||
spec.loader.exec_module(module)
|
||||
|
||||
if hasattr(module, "main") and callable(module.main):
|
||||
print(f"正在调用 {module_name}.main()")
|
||||
module.main()
|
||||
else:
|
||||
print(f"{module_name}.py 中没有找到 main 函数或 main 不是可调用对象。")
|
||||
|
||||
if __name__ == "__main__":
|
||||
run_components()
|
Binary file not shown.
Binary file not shown.
Binary file not shown.
Loading…
x
Reference in New Issue
Block a user