diff --git a/pulsar/components/__horizontal_indicator.py b/pulsar/components/__horizontal_indicator.py index e69de29..ed7a86c 100644 --- a/pulsar/components/__horizontal_indicator.py +++ b/pulsar/components/__horizontal_indicator.py @@ -0,0 +1,24 @@ +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) + if info["delta"] == "click": + if info["click"]: + print(info["cursor"]["poscale"]) + # 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() diff --git a/pulsar/components/__pycache__/marker.cpython-312.pyc b/pulsar/components/__pycache__/marker.cpython-312.pyc new file mode 100644 index 0000000..408ec99 Binary files /dev/null and b/pulsar/components/__pycache__/marker.cpython-312.pyc differ diff --git a/pulsar/components/marking_lines.py b/pulsar/components/marker.py similarity index 87% rename from pulsar/components/marking_lines.py rename to pulsar/components/marker.py index c6be0d6..ed7a86c 100644 --- a/pulsar/components/marking_lines.py +++ b/pulsar/components/marker.py @@ -15,6 +15,9 @@ def main(window): def observer(info): if info["delta"] == "key": print(info) + if info["delta"] == "click": + if info["click"]: + print(info["cursor"]["poscale"]) # 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)) diff --git a/pulsar/t.py b/pulsar/t.py deleted file mode 100644 index 0eeb3db..0000000 --- a/pulsar/t.py +++ /dev/null @@ -1,86 +0,0 @@ -import pygame - -pygame.init() - -screen_width = 800 -screen_height = 600 -screen = pygame.display.set_mode((screen_width, screen_height)) -pygame.display.set_caption("Pygame All Events Example") - -font = pygame.font.Font(None, 30) -event_log = [] - -running = True -while running: - for event in pygame.event.get(): - event_log.insert(0, f"Event: {pygame.event.event_name(event.type)} - {event.__dict__}") - if len(event_log) > 10: # Keep only the last 10 events for display - event_log.pop() - - if event.type == pygame.QUIT: - running = False - elif event.type == pygame.KEYDOWN: - print(f"KEYDOWN: Key={pygame.key.name(event.key)}, Modifiers={event.mod}, Unicode='{event.unicode}', Scancode={event.scancode}") - elif event.type == pygame.KEYUP: - print(f"KEYUP: Key={pygame.key.name(event.key)}, Modifiers={event.mod}") - elif event.type == pygame.MOUSEMOTION: - print(f"MOUSEMOTION: Pos={event.pos}, Relative={event.rel}, Buttons={event.buttons}") - elif event.type == pygame.MOUSEBUTTONDOWN: - print(f"MOUSEBUTTONDOWN: Pos={event.pos}, Button={event.button}") - elif event.type == pygame.MOUSEBUTTONUP: - print(f"MOUSEBUTTONUP: Pos={event.pos}, Button={event.button}") - elif hasattr(pygame, 'MOUSEWHEEL') and event.type == pygame.MOUSEWHEEL: - print(f"MOUSEWHEEL:X={event.x}, Y={event.y}, Precise X={event.precise_x}, Precise Y={event.precise_y}, Flipped={event.flipped}") - elif event.type == pygame.ACTIVEEVENT: - print(f"ACTIVEEVENT: Gain={event.gain}, State={event.state}") - elif event.type == pygame.VIDEORESIZE: - print(f"VIDEORESIZE: Size=({event.w}, {event.h})") - screen = pygame.display.set_mode(event.size, pygame.RESIZABLE) - elif event.type == pygame.VIDEOEXPOSE: - print("VIDEOEXPOSE") - elif hasattr(pygame, 'WINDOWEVENT') and event.type == pygame.WINDOWEVENT: - print(f"WINDOWEVENT: Event={pygame.event.event_name(event.event)}, Data1={event.data1}, Data2={event.data2}") - elif pygame.joystick.get_count() > 0: - for i in range(pygame.joystick.get_count()): - joystick = pygame.joystick.Joystick(i) - joystick.init() - if event.type == pygame.JOYAXISMOTION and event.joy == joystick.get_id(): - print(f"JOYAXISMOTION (Joystick {joystick.get_id()}): Axis={event.axis}, Value={event.value}") - elif event.type == pygame.JOYBALLMOTION and event.joy == joystick.get_id(): - print(f"JOYBALLMOTION (Joystick {joystick.get_id()}): Ball={event.ball}, Relative={event.rel}") - elif event.type == pygame.JOYHATMOTION and event.joy == joystick.get_id(): - print(f"JOYHATMOTION (Joystick {joystick.get_id()}): Hat={event.hat}, Value={event.value}") - elif event.type == pygame.JOYBUTTONDOWN and event.joy == joystick.get_id(): - print(f"JOYBUTTONDOWN (Joystick {joystick.get_id()}): Button={event.button}") - elif event.type == pygame.JOYBUTTONUP and event.joy == joystick.get_id(): - print(f"JOYBUTTONUP (Joystick {joystick.get_id()}): Button={event.button}") - elif event.type >= pygame.USEREVENT: - print(f"USEREVENT: Type={event.type}, Data={event.__dict__}") - elif hasattr(pygame, 'TEXTINPUT') and event.type == pygame.TEXTINPUT: - print(f"TEXTINPUT: Text='{event.text}'") - elif hasattr(pygame, 'TEXTEDITING') and event.type == pygame.TEXTEDITING: - print(f"TEXTEDITING: Text='{event.text}', Start={event.start}, Length={event.length}") - elif hasattr(pygame, 'FINGERDOWN') and event.type == pygame.FINGERDOWN: - print(f"FINGERDOWN: Finger ID={event.finger_id}, Pos={event.pos}, Delta={event.delta}, Pressure={event.pressure}") - elif hasattr(pygame, 'FINGERUP') and event.type == pygame.FINGERUP: - print(f"FINGERUP: Finger ID={event.finger_id}, Pos={event.pos}, Delta={event.delta}, Pressure={event.pressure}") - elif hasattr(pygame, 'FINGERMOTION') and event.type == pygame.FINGERMOTION: - print(f"FINGERMOTION: Finger ID={event.finger_id}, Pos={event.pos}, Delta={event.delta}, Pressure={event.pressure}") - elif hasattr(pygame, 'AUDIODEVICEADDED') and event.type == pygame.AUDIODEVICEADDED: - print(f"AUDIODEVICEADDED: Which={event.which}, Is Capture={event.iscapture}") - elif hasattr(pygame, 'AUDIODEVICEREMOVED') and event.type == pygame.AUDIODEVICEREMOVED: - print(f"AUDIODEVICEREMOVED: Which={event.which}, Is Capture={event.iscapture}") - elif event.type == pygame.SYSWMEVENT: - print(f"SYSWMEVENT: Message={event.msg}, Data1={event.data1}, Data2={event.data2}") - - screen.fill((255, 255, 255)) # Fill the screen with white - - y_offset = 10 - for log_entry in event_log: - text_surface = font.render(log_entry, True, (0, 0, 0)) - screen.blit(text_surface, (10, y_offset)) - y_offset += 20 - - pygame.display.flip() - -pygame.quit() \ No newline at end of file diff --git a/pulsar/tester.py b/pulsar/tester.py index 0a93c8a..80b2812 100644 --- a/pulsar/tester.py +++ b/pulsar/tester.py @@ -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() \ No newline at end of file +if __name__ == '__main__': + os.chdir(os.path.dirname(os.path.abspath(__file__))) + print("Tester") + window.start() + loader() + console() + print("Quitting") + window.kill() + exit() \ No newline at end of file diff --git a/testfield/visual/1view.bmp b/testfield/visual/1view.bmp deleted file mode 100644 index f448031..0000000 Binary files a/testfield/visual/1view.bmp and /dev/null differ diff --git a/testfield/visual/view.bmp b/testfield/visual/view.bmp index dfeafb2..f448031 100644 Binary files a/testfield/visual/view.bmp and b/testfield/visual/view.bmp differ diff --git a/vgl/__pycache__/main.cpython-312.pyc b/vgl/__pycache__/main.cpython-312.pyc index c342b1f..bfc7b4d 100644 Binary files a/vgl/__pycache__/main.cpython-312.pyc and b/vgl/__pycache__/main.cpython-312.pyc differ diff --git a/vgl/main.py b/vgl/main.py index 7d803c6..59ce62b 100644 --- a/vgl/main.py +++ b/vgl/main.py @@ -90,9 +90,14 @@ class Aux(): class Anchor(object): """ "锚定点" 对象 + 镜像 + @: 矩阵乘法 + *: 中心/任意参照点缩放 + 中点/比例点 + """ - poscale = (0, 0) - fixed = 3 + poscale = (0, 0) # 位置 + fixed = 3 # 小数点后精度 def __init__(self, *args): if isinstance(args[0], tuple) or isinstance(args[0], Anchor): if isinstance(args[0], Anchor): @@ -106,6 +111,7 @@ class Anchor(object): def y(self): return self.poscale[1] def __add__(self, other): + "矩阵加法" if isinstance(other, tuple): return Anchor((self.poscale[0] + other[0], self.poscale[1] + other[1])) elif isinstance(other, Anchor): @@ -113,7 +119,7 @@ class Anchor(object): else: raise TypeError("不支持的加法操作数类型") def __mul__(self, other): - "向屏幕中心倍增/倍缩" + "中心倍增/倍缩" if isinstance(other, tuple): return Anchor((0.5 + other[0] * (self.poscale[0] - 0.5), 0.5 + other[1] * (self.poscale[1] - 0.5))) elif isinstance(other, (int, float)): @@ -221,7 +227,7 @@ class Window(object): "click": [], # 被按下的按钮 "focus": 1, # 或 0 "key": [], - "delta": [] # 变化的键值, 避免多次调用 + "delta": "" # 变化的键值, 避免多次调用 } """{ "cursor": {