Skip to content

Instantly share code, notes, and snippets.

@JamesHagerman
Last active July 18, 2018 09:16
Show Gist options
  • Select an option

  • Save JamesHagerman/6e91659f7981fb5a54d2870c4c741d4b to your computer and use it in GitHub Desktop.

Select an option

Save JamesHagerman/6e91659f7981fb5a54d2870c4c741d4b to your computer and use it in GitHub Desktop.
Adding a python script to the RetoPie EmulationStation GUI

RetroPiePy Notes

Adding a GUI entry for your own scripts. I followed these directions: https://retropie.org.uk/docs/Add-a-New-System-in-EmulationStation/

Useful tools:

sudo apt-get install python-pip
pip install pysdl2

Copy es_systems.cfg OUT of /etc/ first (And remember to update it when you update retropie!):

sudo cp /etc/emulationstation/es_systems.cfg /opt/retropie/configs/all/emulationstation/es_systems.cfg.

Add something like this to es_systems.cfg

  <system>
    <name>Scripts</name>
    <fullname>Custom Scripts</fullname>
    <path>/home/pi/RetroPie/scripts</path>
    <extension>.sh .py</extension>
    <command>%ROM%</command>
    <platform/>
    <theme/>
  </system>

Then, any .sh or .py scripts in the /home/pi/RetroPie/scripts directory will be listed as "games" under the Scripts emulator entry in the GUI!

Here is a main.py that draws an sdl window (I put it in /home/pi/RetroPie/scripts/main.py). Use chmod +x main.py to make sure you can run it...

#!/usr/bin/python
# -*- coding: utf-8 -*-

from sdl2 import *

X = SDL_WINDOWPOS_UNDEFINED
Y = SDL_WINDOWPOS_UNDEFINED
W = 960
H = 540
FLAGS = SDL_WINDOW_SHOWN

# There are more pythonic ways of doing this, by using the sdl2.ext module.

def main():
    SDL_Init(SDL_INIT_VIDEO)

    win = SDL_CreateWindow(b"Hello World!", X, Y, W, H, FLAGS)
    ren = SDL_CreateRenderer(win, -1, SDL_RENDERER_ACCELERATED | SDL_RENDERER_PRESENTVSYNC)
    bmp = SDL_LoadBMP(b"../img/boxes.bmp")
    tex = SDL_CreateTextureFromSurface(ren, bmp)
    SDL_FreeSurface(bmp)

    for i in range(20):
        SDL_RenderClear(ren)
        SDL_RenderCopy(ren, tex, None, None)
        SDL_RenderPresent(ren)
        SDL_Delay(100)

    SDL_DestroyTexture(tex)
    SDL_DestroyRenderer(ren)
    SDL_DestroyWindow(win)
    SDL_Quit()

if __name__ == "__main__":
    main()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment