1
0
forked from ndyer/pygame-dvd
steam-screensaver/steam_saver/main.py

52 lines
1.5 KiB
Python
Raw Normal View History

2023-02-28 09:50:34 -05:00
import pygame
2025-01-06 21:00:36 -05:00
import subprocess
import steam_saver.surfaces as surfaces
2023-02-28 09:50:34 -05:00
# Global variables
FPS = 60
VALID_SURFACES = [
'steam_screen'
2023-02-28 09:50:34 -05:00
]
2025-01-06 21:00:36 -05:00
def get_screen_resolution():
command_output = subprocess.check_output(['xrandr']).decode('utf-8')
for line in command_output.split('\n'):
if '*' in line:
return tuple(map(int, line.split()[0].split('x')))
2023-02-28 09:50:34 -05:00
def main(windowed_mode=False):
"""
Main scene manager to display the scenes of the application
:param windowed_mode: boolean to start the game in windowed mode
"""
pygame.init()
clock = pygame.time.Clock()
2025-01-06 21:00:36 -05:00
screen_size = get_screen_resolution()
2023-02-28 09:50:34 -05:00
if windowed_mode:
2025-01-06 21:00:36 -05:00
window = pygame.display.set_mode(screen_size)
2023-02-28 09:50:34 -05:00
else:
2025-01-06 21:00:36 -05:00
window = pygame.display.set_mode(screen_size, pygame.FULLSCREEN)
2023-02-28 09:50:34 -05:00
# Starts the program with the surface 'steam_screen' as the default
2025-01-06 21:00:36 -05:00
surface = getattr(globals()['surfaces'], 'steam_screen').Surface(screen_size)
2023-02-28 09:50:34 -05:00
running = True
while running:
clock.tick(FPS)
surface.update()
window.blit(surface, surface.get_rect())
if not surface.running:
if surface.quit:
break
# Switch the surface to a new surface
next_surface = surface.next_surface
if next_surface not in VALID_SURFACES:
raise Exception('Given surface is not a valid surface!')
2025-01-06 21:00:36 -05:00
surface = getattr(globals()['surfaces'], next_surface).Surface(screen_size)
2023-02-28 09:50:34 -05:00
pygame.display.flip()
pygame.quit()