signal handling for controlled exit
This commit is contained in:
parent
f86cca398c
commit
a46cf22eb1
12
gametest.py
12
gametest.py
@ -1,7 +1,7 @@
|
||||
#!/usr/bin/env python
|
||||
#coding=utf-8
|
||||
|
||||
import pygame, sys, time, os, RPi.GPIO as GPIO
|
||||
import pygame, signal, sys, time, os, RPi.GPIO as GPIO
|
||||
from pygame.locals import *
|
||||
|
||||
#GPIO
|
||||
@ -35,6 +35,10 @@ mainFontColor = redColor
|
||||
#fonts
|
||||
font = pygame.font.Font('freesansbold.ttf', 90)
|
||||
|
||||
def signal_handler(sig, frame):
|
||||
print('Programm exiting')
|
||||
exit_application()
|
||||
|
||||
def toggle_fullscreen():
|
||||
screen = pygame.display.get_surface()
|
||||
tmp = screen.convert()
|
||||
@ -79,12 +83,16 @@ def handle_events():
|
||||
|
||||
def exit_application():
|
||||
pygame.quit()
|
||||
GPIO.cleanup()
|
||||
sys.exit()
|
||||
return
|
||||
|
||||
def shutdown_raspberry():
|
||||
os.system("sudo shutdown -h now")
|
||||
return
|
||||
|
||||
#signal handing for controlled exit via ctrl+c
|
||||
signal.signal(signal.SIGINT, signal_handler)
|
||||
|
||||
|
||||
pygame.mouse.set_visible(False) # hide mouse
|
||||
@ -94,6 +102,8 @@ screen = pygame.display.set_mode((screenSizeX, screenSizeY), pygame.FULLSCREEN)
|
||||
|
||||
#screen = toggle_fullscreen()
|
||||
|
||||
|
||||
|
||||
while True: # main loop
|
||||
#global label storage
|
||||
time_surface = 0
|
||||
|
Loading…
Reference in New Issue
Block a user