forked from ndyer/pygame-dvd
52 lines
1.5 KiB
Python
52 lines
1.5 KiB
Python
import pygame
|
|
import subprocess
|
|
import steam_saver.surfaces as surfaces
|
|
|
|
# Global variables
|
|
FPS = 90
|
|
VALID_SURFACES = [
|
|
'steam_screen'
|
|
]
|
|
|
|
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')))
|
|
|
|
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()
|
|
|
|
screen_size = get_screen_resolution()
|
|
|
|
if windowed_mode:
|
|
window = pygame.display.set_mode(screen_size)
|
|
else:
|
|
window = pygame.display.set_mode(screen_size, pygame.FULLSCREEN)
|
|
|
|
# Starts the program with the surface 'steam_screen' as the default
|
|
surface = getattr(globals()['surfaces'], 'steam_screen').Surface(screen_size)
|
|
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!')
|
|
surface = getattr(globals()['surfaces'], next_surface).Surface(screen_size)
|
|
|
|
pygame.display.flip()
|
|
pygame.quit()
|