Skip to content

Commit

Permalink
Added pygame support
Browse files Browse the repository at this point in the history
  • Loading branch information
nadi726 committed Mar 8, 2023
1 parent 1d46451 commit e2d4a70
Show file tree
Hide file tree
Showing 4 changed files with 46 additions and 1 deletion.
2 changes: 1 addition & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -38,5 +38,5 @@ jobs:
strategy:
fail-fast: false
matrix:
framework: [ "toga", "pyside2", "pyside6", "ppb" ]
framework: [ "toga", "pyside2", "pyside6", "ppb", "pygame" ]
runner-os: [ "macos-latest", "ubuntu-latest", "windows-latest" ]
1 change: 1 addition & 0 deletions cookiecutter.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
"PySide2",
"PySide6",
"PursuedPyBear",
"Pygame",
"None"
],
"test_framework": [
Expand Down
2 changes: 2 additions & 0 deletions {{ cookiecutter.app_name }}/pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@ requires = [
"pyside6~=6.2",
{%- elif cookiecutter.gui_framework == "PursuedPyBear" %}
"ppb~=1.1",
{%- elif cookiecutter.gui_framework == "Pygame" %}
"pygame>=2.1"
{%- endif %}
]
test_requires = [
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,48 @@ def main():
starting_scene={{ cookiecutter.class_name }},
title=metadata['Formal-Name'],
)
{%- elif cookiecutter.gui_framework == 'Pygame' %}
import pygame
import sys

try:
from importlib import metadata as importlib_metadata
except ImportError:
# Backwards compatibility - importlib.metadata was added in Python 3.8
import importlib_metadata


SCREEN_WIDTH, SCREEN_HEIGHT = 800, 600
WHITE = (255, 255, 255)
FPS = 60


def main():
# Find the name of the module that was used to start the app
app_module = sys.modules["__main__"].__package__
# Retrieve the app's metadata
metadata = importlib_metadata.metadata(app_module)

pygame.init()
pygame.display.set_caption(metadata["Formal-Name"])

screen = pygame.display.set_mode((SCREEN_WIDTH, SCREEN_HEIGHT))
clock = pygame.time.Clock()

running = True
while running:
for event in pygame.event.get():
if event.type == pygame.QUIT:
running = False
break

screen.fill(WHITE)
pygame.display.flip()

clock.tick(FPS)

pygame.quit()
sys.exit()
{% else -%}
def main():
# This should start and launch your app!
Expand Down

0 comments on commit e2d4a70

Please sign in to comment.