minor VGL improvements

This commit is contained in:
2025-04-05 14:21:31 +08:00
parent bce75a1727
commit 890543e3c1
6 changed files with 185 additions and 8 deletions

View File

@@ -9,7 +9,6 @@ horizontal_indicator:
ends: [(0.4, 0.5), (0.6, 0.5)]
color: green
- type: line
status: static
args:
ends: [(0.4, 0.5), (0.6, 0.5)]
color: green

View File

@@ -3,23 +3,33 @@ import time
window = None
def horizontal_indicator():
global window
frame = vgl.Frame().attach(window, (0, 0), "Horizontal Indicator")
vgl.elements.Line(ends=[(0.4, 0.5), (0.6, 0.5)], color="green").attach(frame)
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 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:
exec(input(">>> "))
exec(input(prompt=">>> "))
except:
print("An error caused & captured")
if __name__ == '__main__':
print("Welcome to AiraPulsar Client")
window = vgl.Window(title="Pulsar", size=(1600, 800))
window = vgl.Window(title="Pulsar", size=(1024, 768))
window.start()
horizontal_indicator()
marking_lines()
#console()
time.sleep(3)
input("任意键以退出")
window.kill()
exit()

86
pulsar/t.py Normal file
View File

@@ -0,0 +1,86 @@
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()