Skip to content

Commit

Permalink
[BUG] Pygame features not working (hedyorg#4039)
Browse files Browse the repository at this point in the history
* Fix Pygame prefix

* [pre-commit.ci] auto fixes from pre-commit.com hooks

for more information, see https://pre-commit.ci

---------

Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
Co-authored-by: mergify[bot] <37929162+mergify[bot]@users.noreply.github.com>
  • Loading branch information
3 people authored Feb 16, 2023
1 parent 475ace6 commit 981ea4b
Show file tree
Hide file tree
Showing 5 changed files with 42 additions and 21 deletions.
17 changes: 11 additions & 6 deletions prefixes/pygame.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,17 @@
# coding=utf8

import os
import pygame

os.environ["SDL_VIDEODRIVER"] = "dummy" # No real image drivers exist, set to dummy for testing
os.environ["SDL_AUDIODRIVER"] = "disk" # No real audio drivers exist, set to disk for testing
import pygame # noqa F401
import buttons # noqa F401

pygame.init()
canvas = pygame.display.set_mode((711, 300))
canvas.fill(pygame.Color(247, 250, 252, 255))
pygame_end = True # Set to True so that we don't get stuck in a loop during testing'

pygame_end = False
button_list = []


def create_button(name):
if name not in button_list:
button_list.append(name)
buttons.add(name)
16 changes: 10 additions & 6 deletions static/js/appbundle.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions static/js/appbundle.js.map

Large diffs are not rendered by default.

16 changes: 10 additions & 6 deletions static/js/pythonPrefixes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,16 +30,20 @@ t.showturtle()
export const pygame_prefix =
`# coding=utf8
import os
import pygame
os.environ["SDL_VIDEODRIVER"] = "dummy" # No real image drivers exist, set to dummy for testing
os.environ["SDL_AUDIODRIVER"] = "disk" # No real audio drivers exist, set to disk for testing
import pygame # noqa F401
import buttons # noqa F401
pygame.init()
canvas = pygame.display.set_mode((711, 300))
canvas.fill(pygame.Color(247, 250, 252, 255))
pygame_end = True # Set to True so that we don't get stuck in a loop during testing'
pygame_end = False
button_list = []
def create_button(name):
if name not in button_list:
button_list.append(name)
buttons.add(name)
`;

export const normal_prefix =
Expand Down
10 changes: 9 additions & 1 deletion tests/Tester.py
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,15 @@ def run_code(parse_result):
if parse_result.has_turtle:
code += utils.TURTLE_PREFIX_CODE
if parse_result.has_pygame:
code += utils.PYGAME_PREFIX_CODE
pygame_test_prefix = (
'import os\n'
'os.environ["SDL_VIDEODRIVER"] = "dummy" # No real image drivers exist, set to dummy for testing\n'
'os.environ["SDL_AUDIODRIVER"] = "disk" # No real audio drivers exist, set to disk for testing\n'
) + utils.PYGAME_PREFIX_CODE + (
"pygame_end = True # Set to True so that we don't get stuck in a loop during testing\n"
)

code += pygame_test_prefix

code += parse_result.code
# remove sleep comments to make program execution less slow
Expand Down

0 comments on commit 981ea4b

Please sign in to comment.