Skip to content
Snippets Groups Projects
Commit 97c7ef0c authored by Fabian Heinrich's avatar Fabian Heinrich
Browse files

Program should exit better now. Catches KeyboardInterrupt in pygame_gui.py and quits properly

parent 103df462
No related branches found
No related tags found
1 merge request!15Resolve "Better exiting the programm and all threads"
Pipeline #42223 passed
import colorsys import colorsys
import math import math
import sys
import numpy as np import numpy as np
import numpy.typing as npt import numpy.typing as npt
...@@ -401,15 +402,21 @@ class PyGameGUI: ...@@ -401,15 +402,21 @@ class PyGameGUI:
# Game loop # Game loop
running = True running = True
while running: while running:
for event in pygame.event.get(): try:
if event.type == pygame.QUIT: for event in pygame.event.get():
running = False if event.type == pygame.QUIT:
if event.type in [pygame.KEYDOWN, pygame.KEYUP]: running = False
self.handle_key_event(event) if event.type in [pygame.KEYDOWN, pygame.KEYUP]:
self.handle_key_event(event)
self.handle_keys()
clock.tick(self.FPS) self.handle_keys()
state = self.simulator.get_state() clock.tick(self.FPS)
self.draw(state) state = self.simulator.get_state()
self.draw(state)
except KeyboardInterrupt:
pygame.quit()
self.simulator.stop()
sys.exit()
pygame.quit() pygame.quit()
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment