Skip to content

Running Pygame in Mu on MacOS opens the pygame window in the background #1170

Open
@cturland

Description

@cturland

If you are reporting a bug, we would like to know:

  • What you were trying to do,
    Run very basic pygame project on MacOS

  • What steps you took to make this happen,
    Installed Mu and started a new Python 3 project

  • What you expected to happen,
    A window should have opened with a red square in the top corner

  • What actually happened,
    A blank window opened

  • Why this difference is problematic (it may not be a bug!),
    The code runs differently on Windows machines, which displays the output correctly

  • Technical details like the version of Mu you're using, your OS version and
    other aspects of the context in which Mu was running.
    1.0.3 MU
    Multiple versions of MacOS (problem was identified whilst using it in a classroom with a bring your own device environment). All Mac users had the same issue

Log and screenshot of code we were trying to run

Log is from my Windows version which is working (sadly didn't get a log from a student machine before they left)
image

2020-12-09 08:50:13,124 - root:112(run) INFO: 

-----------------

Starting Mu 1.0.3
2020-12-09 08:50:13,126 - root:113(run) INFO: uname_result(system='Windows', node='R90Y7SX4-CARTUR', release='10', version='10.0.18362', machine='AMD64', processor='Intel64 Family 6 Model 142 Stepping 12, GenuineIntel')
2020-12-09 08:50:13,127 - root:114(run) INFO: Python path: ['C:\\Program Files\\Mu\\pkgs', 'C:\\Program Files\\Mu\\Python\\python36.zip', 'C:\\Program Files\\Mu\\Python', 'C:\\Program Files\\Mu\\pkgs', 'C:\\Users\\cturland\\AppData\\Roaming\\Python\\Python36\\site-packages', 'C:\\Program Files\\Mu\\pkgs\\IPython\\extensions']
2020-12-09 08:50:13,127 - root:115(run) INFO: Language code: en_GB
2020-12-09 08:50:13,312 - mu.logic:543(__init__) INFO: Setting up editor.
2020-12-09 08:50:13,312 - mu.logic:562(__init__) INFO: Settings path: C:\Users\cturland\AppData\Local\python\mu\settings.json
2020-12-09 08:50:13,313 - mu.logic:563(__init__) INFO: Session path: C:\Users\cturland\AppData\Local\python\mu\session.json
2020-12-09 08:50:13,313 - mu.logic:564(__init__) INFO: Log directory: C:\Users\cturland\AppData\Local\python\mu\Logs
2020-12-09 08:50:13,313 - mu.logic:565(__init__) INFO: Data directory: C:\Users\cturland\AppData\Local\python\mu
2020-12-09 08:50:13,339 - mu.logic:578(setup) INFO: Available modes: python, adafruit, microbit, debugger, pygamezero
2020-12-09 08:50:13,934 - mu.logic:1150(change_mode) INFO: Workspace directory: C:\Users\cturland\mu_code
2020-12-09 08:50:13,934 - mu.logic:627(restore_session) INFO: Restoring session from: C:\Users\cturland\AppData\Local\python\mu\session.json
2020-12-09 08:50:13,934 - mu.logic:628(restore_session) DEBUG: {'theme': 'day', 'mode': 'python', 'paths': ['C:\\Users\\cturland\\mu_code\\test.py', 'C:\\Users\\cturland\\mu_code\\resize.py', 'C:\\Users\\cturland\\mu_code\\bg.py'], 'envars': [], 'minify': False, 'microbit_runtime': '', 'zoom_level': 2}
2020-12-09 08:50:13,934 - mu.logic:715(_load) INFO: Loading script from: C:\Users\cturland\mu_code\resize.py
2020-12-09 08:50:13,935 - mu.logic:274(read_and_decode) DEBUG: Trying to decode with utf-8
2020-12-09 08:50:13,935 - mu.logic:277(read_and_decode) INFO: Decoded with utf-8
2020-12-09 08:50:13,936 - mu.logic:290(read_and_decode) DEBUG: Detected newline '\n'
2020-12-09 08:50:13,936 - mu.logic:789(_load) DEBUG: #This is needed to give us access to the resize method
import pygame

#You have to keep an original copy to resize
alien_original = Actor('alien')

#This will be used as the resized actor
alien = Actor('alien')

#Set the starting size variables
alien_height = 500
alien_width = 500

#Doesn't work as we are using 1.2
alien.opacity = 1.0

def draw():
    screen.fill((128, 0, 128))
    alien.draw()

def update():
    #Get access to variables set outside the function
    global alien_width, alien_height

    #Reduce the size by 1 each loop
    alien_width -= 1
    alien_height -= 1
    #Scale a new image
    alien._surf = pygame.transform.scale(alien_original._surf, (alien_width, alien_height))
    #Don't think this is needed..., but not confident :)
    alien._update_pos()
2020-12-09 08:50:13,987 - mu.logic:715(_load) INFO: Loading script from: C:\Users\cturland\mu_code\bg.py
2020-12-09 08:50:13,988 - mu.logic:274(read_and_decode) DEBUG: Trying to decode with utf-8
2020-12-09 08:50:13,989 - mu.logic:277(read_and_decode) INFO: Decoded with utf-8
2020-12-09 08:50:13,989 - mu.logic:290(read_and_decode) DEBUG: Detected newline '\n'
2020-12-09 08:50:13,989 - mu.logic:789(_load) DEBUG: import os
import sys
import ctypes

def is_running_as_admin():
    try:
        return ctypes.windll.shell32/IsUserAnAdmin()
    except:
        return False

def execute():
    if not is_running_as_admin():
        print("Not admin")
    else:
        print("Is admin")

if __name__ == '__main__':
    execute()
2020-12-09 08:50:14,007 - mu.logic:715(_load) INFO: Loading script from: C:\Users\cturland\mu_code\test.py
2020-12-09 08:50:14,008 - mu.logic:274(read_and_decode) DEBUG: Trying to decode with utf-8
2020-12-09 08:50:14,008 - mu.logic:277(read_and_decode) INFO: Decoded with utf-8
2020-12-09 08:50:14,008 - mu.logic:290(read_and_decode) DEBUG: Detected newline '\n'
2020-12-09 08:50:14,008 - mu.logic:789(_load) DEBUG: from microbit import *
import random

answers = [
    "It is certain",
    "It is decidedly so",
    "Without a doubt",
    "Yes, definitely",
    "You may rely on it",
    "As I see it, yes",
    "Most likely",
    "Outlook good",
    "Yes",
    "Signs point to yes",
    "Reply hazy try again",
    "Ask again later",
    "Better not tell you now",
    "Cannot predict now",
    "Concentrate and ask again",
    "Don't count on it",
    "My reply is no",
    "My sources say no",
    "Outlook not so good",
    "Very doubtful",
]

while True:
    display.show("8")
    if accelerometer.was_gesture("shake"):
        display.clear()
        sleep(1000)
        display.scroll(random.choice(answers))
2020-12-09 08:50:14,031 - mu.logic:649(restore_session) INFO: Loaded files.
2020-12-09 08:50:14,031 - mu.logic:653(restore_session) INFO: User defined environment variables: []
2020-12-09 08:50:14,031 - mu.logic:657(restore_session) INFO: Minify scripts on micro:bit? False
2020-12-09 08:50:14,055 - mu.logic:1150(change_mode) INFO: Workspace directory: C:\Users\cturland\mu_code
2020-12-09 09:09:47,741 - mu.logic:702(new) INFO: Added a new tab.
2020-12-09 09:10:11,940 - mu.logic:1107(select_mode) INFO: Showing available modes: ['python', 'adafruit', 'microbit', 'debugger', 'pygamezero']
2020-12-09 09:10:24,245 - mu.logic:811(get_dialog_directory) INFO: Using path for file dialog: C:\Users\cturland\mu_code
2020-12-09 09:10:31,823 - mu.interface.main:263(get_save_path) DEBUG: Getting save path: C:/Users/cturland/mu_code/pygameTest
2020-12-09 09:10:31,823 - mu.logic:905(check_for_shadow_module) INFO: Checking path "C:/Users/cturland/mu_code/pygameTest" for shadow module.
2020-12-09 09:10:31,823 - mu.logic:871(save_tab_to_file) INFO: Saving script to: C:/Users/cturland/mu_code/pygameTest.py
2020-12-09 09:10:31,823 - mu.logic:872(save_tab_to_file) DEBUG: import pygame
2020-12-09 09:10:31,837 - mu.interface.panes:651(start_process) INFO: Running script: c:\users\cturland\mu_code\pygametest.py
2020-12-09 09:10:31,837 - mu.interface.panes:653(start_process) INFO: Running with interactive mode.
2020-12-09 09:10:31,837 - mu.interface.panes:656(start_process) INFO: Command args: []
2020-12-09 09:10:31,839 - mu.interface.panes:683(start_process) INFO: Python paths set via C:\Users\cturland\AppData\Roaming\Python\Python36\site-packages\mu.pth
2020-12-09 09:10:31,839 - mu.interface.panes:714(start_process) INFO: Working directory: C:/Users/cturland/mu_code
2020-12-09 09:10:31,839 - mu.interface.panes:719(start_process) INFO: Python path: ['C:\\Program Files\\Mu\\pkgs', 'C:\\Program Files\\Mu\\Python\\python36.zip', 'C:\\Program Files\\Mu\\Python', 'C:\\Program Files\\Mu\\pkgs', 'C:\\Users\\cturland\\AppData\\Roaming\\Python\\Python36\\site-packages', 'C:\\Program Files\\Mu\\pkgs\\IPython\\extensions']
2020-12-09 09:43:05,715 - mu.modes.python3:202(stop_script) DEBUG: Stopping script.
2020-12-09 09:43:06,083 - mu.logic:871(save_tab_to_file) INFO: Saving script to: C:/Users/cturland/mu_code/pygameTest.py
2020-12-09 09:43:06,083 - mu.logic:872(save_tab_to_file) DEBUG: import pygame



pygame.init()



screen = pygame.display.set_mode((640, 480))



red = (255,0,0)

white = (255,255,255)



while True:

  screen.fill(white)

  pygame.draw.rect(screen, red, (0, 0, 100, 100), 0)

  pygame.display.update()
2020-12-09 09:43:06,101 - mu.interface.panes:651(start_process) INFO: Running script: c:\users\cturland\mu_code\pygametest.py
2020-12-09 09:43:06,101 - mu.interface.panes:653(start_process) INFO: Running with interactive mode.
2020-12-09 09:43:06,101 - mu.interface.panes:656(start_process) INFO: Command args: []
2020-12-09 09:43:06,102 - mu.interface.panes:683(start_process) INFO: Python paths set via C:\Users\cturland\AppData\Roaming\Python\Python36\site-packages\mu.pth
2020-12-09 09:43:06,102 - mu.interface.panes:714(start_process) INFO: Working directory: C:/Users/cturland/mu_code
2020-12-09 09:43:06,102 - mu.interface.panes:719(start_process) INFO: Python path: ['C:\\Program Files\\Mu\\pkgs', 'C:\\Program Files\\Mu\\Python\\python36.zip', 'C:\\Program Files\\Mu\\Python', 'C:\\Program Files\\Mu\\pkgs', 'C:\\Users\\cturland\\AppData\\Roaming\\Python\\Python36\\site-packages', 'C:\\Program Files\\Mu\\pkgs\\IPython\\extensions']
2020-12-09 09:43:13,921 - mu.modes.python3:202(stop_script) DEBUG: Stopping script.
2020-12-09 09:43:18,212 - mu.logic:871(save_tab_to_file) INFO: Saving script to: C:/Users/cturland/mu_code/pygameTest.py
2020-12-09 09:43:18,212 - mu.logic:872(save_tab_to_file) DEBUG: import pygame



pygame.init()



screen = pygame.display.set_mode((640, 480))



red = (255,0,0)

white = (255,255,255)





screen.fill(white)

pygame.draw.rect(screen, red, (0, 0, 100, 100), 0)

pygame.display.update()
2020-12-09 09:43:18,227 - mu.interface.panes:651(start_process) INFO: Running script: c:\users\cturland\mu_code\pygametest.py
2020-12-09 09:43:18,227 - mu.interface.panes:653(start_process) INFO: Running with interactive mode.
2020-12-09 09:43:18,228 - mu.interface.panes:656(start_process) INFO: Command args: []
2020-12-09 09:43:18,228 - mu.interface.panes:683(start_process) INFO: Python paths set via C:\Users\cturland\AppData\Roaming\Python\Python36\site-packages\mu.pth
2020-12-09 09:43:18,228 - mu.interface.panes:714(start_process) INFO: Working directory: C:/Users/cturland/mu_code
2020-12-09 09:43:18,228 - mu.interface.panes:719(start_process) INFO: Python path: ['C:\\Program Files\\Mu\\pkgs', 'C:\\Program Files\\Mu\\Python\\python36.zip', 'C:\\Program Files\\Mu\\Python', 'C:\\Program Files\\Mu\\pkgs', 'C:\\Users\\cturland\\AppData\\Roaming\\Python\\Python36\\site-packages', 'C:\\Program Files\\Mu\\pkgs\\IPython\\extensions']
2020-12-09 09:43:29,279 - mu.logic:871(save_tab_to_file) INFO: Saving script to: C:/Users/cturland/mu_code/pygameTest.py
2020-12-09 09:43:29,279 - mu.logic:872(save_tab_to_file) DEBUG: import pygame



pygame.init()



screen = pygame.display.set_mode((640, 480))



red = (255,0,0)

white = (255,255,255)



screen.fill(white)

pygame.draw.rect(screen, red, (0, 0, 100, 100), 0)

pygame.display.update()
2020-12-09 09:43:29,295 - mu.logic:1178(autosave) INFO: Autosave detected and saved changes in C:/Users/cturland/mu_code/pygameTest.py.
2020-12-09 09:43:37,083 - mu.modes.python3:202(stop_script) DEBUG: Stopping script.
2020-12-09 09:43:37,544 - mu.interface.panes:651(start_process) INFO: Running script: c:\users\cturland\mu_code\pygametest.py
2020-12-09 09:43:37,544 - mu.interface.panes:653(start_process) INFO: Running with interactive mode.
2020-12-09 09:43:37,545 - mu.interface.panes:656(start_process) INFO: Command args: []
2020-12-09 09:43:37,545 - mu.interface.panes:683(start_process) INFO: Python paths set via C:\Users\cturland\AppData\Roaming\Python\Python36\site-packages\mu.pth
2020-12-09 09:43:37,546 - mu.interface.panes:714(start_process) INFO: Working directory: C:/Users/cturland/mu_code
2020-12-09 09:43:37,546 - mu.interface.panes:719(start_process) INFO: Python path: ['C:\\Program Files\\Mu\\pkgs', 'C:\\Program Files\\Mu\\Python\\python36.zip', 'C:\\Program Files\\Mu\\Python', 'C:\\Program Files\\Mu\\pkgs', 'C:\\Users\\cturland\\AppData\\Roaming\\Python\\Python36\\site-packages', 'C:\\Program Files\\Mu\\pkgs\\IPython\\extensions']
2020-12-09 10:24:09,775 - mu.modes.python3:202(stop_script) DEBUG: Stopping script.
2020-12-09 10:24:10,196 - mu.interface.panes:651(start_process) INFO: Running script: c:\users\cturland\mu_code\pygametest.py
2020-12-09 10:24:10,196 - mu.interface.panes:653(start_process) INFO: Running with interactive mode.
2020-12-09 10:24:10,196 - mu.interface.panes:656(start_process) INFO: Command args: []
2020-12-09 10:24:10,196 - mu.interface.panes:683(start_process) INFO: Python paths set via C:\Users\cturland\AppData\Roaming\Python\Python36\site-packages\mu.pth
2020-12-09 10:24:10,197 - mu.interface.panes:714(start_process) INFO: Working directory: C:/Users/cturland/mu_code
2020-12-09 10:24:10,197 - mu.interface.panes:719(start_process) INFO: Python path: ['C:\\Program Files\\Mu\\pkgs', 'C:\\Program Files\\Mu\\Python\\python36.zip', 'C:\\Program Files\\Mu\\Python', 'C:\\Program Files\\Mu\\pkgs', 'C:\\Users\\cturland\\AppData\\Roaming\\Python\\Python36\\site-packages', 'C:\\Program Files\\Mu\\pkgs\\IPython\\extensions']
2020-12-09 10:24:13,030 - mu.modes.python3:202(stop_script) DEBUG: Stopping script.
2020-12-09 10:29:30,207 - mu.logic:1077(show_admin) INFO: Showing logs from C:\Users\cturland\AppData\Local\python\mu\Logs\mu.log

Thank you for contributing to Mu! :-)

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions