Coder Social home page Coder Social logo

sdl2hl's Introduction

This project is no longer maintained.

sdl2hl

sdl2hl is a Python package providing a friendly, Pythonic wrapper around the SDL2 library. sdl2hl calls SDL2 using Kevin Howell's sdl2-cffi package (which can be found here: https://github.com/kahowell/sdl2-cffi). sdl2hl maintains sdl2-cffi's advantages of using cffi and being zlib licensed, while providing an API that hides the gruesome details of the FFI layer from the user.

Goals

The goals of sdl2hl are:

  • Provide a straightforward, Pythonic API on top of the functionality provided by SDL2.
  • Provide good documentation, independent of the SDL2 documentation.
  • Cover as much of the SDL2 API as possible, excluding elements of the API that do not provide value to a program written in Python (e.g. thread management and shared object loading).

An explicit anti-goal of sdl2hl is providing any significant functionality beyond that which is provided by SDL2. sdl2hl may be a reasonable foundation of a larger game library, but it will not become one itself.

Versioning

sdl2hl versioning follows the semver 2.0 standard. Once sdl2hl hits 1.0, every effort will be made to prevent backwards incompatible changes. If a backwards incompatible change absolutely cannot be avoided, sdl2hl's major version will be incremented. However, since sdl2hl has not hit 1.0, for now there may be breaking changes at any time. Sorry.

License

sdl2hl is licensed under the same zlib license as SDL2 and sdl2-cffi. More details can be found in the LICENSE.txt file that (should) be found in this distribution.

Contributions

Contributions are welcome! If you encounter a bug or have a request or suggestion please open an issue on github at https://github.com/jdoda/sdl2hl/issues . If you want to submit a patch, please open a github pull request at https://github.com/jdoda/sdl2hl/pulls .

Example

import sys

import sdl2hl


BACKGROUND_COLOR = (0,0,0,255)
AVATAR_COLOR = (255,0,0,255)


sdl2hl.init()
window = sdl2hl.Window()
renderer = sdl2hl.Renderer(window)
avatar = sdl2hl.Rect(w=64, h=64)

while True:
    for event in sdl2hl.events.poll():
        if event.type == sdl2hl.QUIT:
            sdl2hl.quit()
            sys.exit()
        elif event.type == sdl2hl.EventType.keydown and event.keycode == sdl2hl.KeyCode.left:
            avatar.x -= 1
        elif event.type == sdl2hl.EventType.keydown and event.keycode == sdl2hl.KeyCode.right:
            avatar.x += 1
        elif event.type == sdl2hl.EventType.keydown and event.keycode == sdl2hl.KeyCode.up:
            avatar.y -= 1
        elif event.type == sdl2hl.EventType.keydown and event.keycode == sdl2hl.KeyCode.down:
            avatar.y += 1

    renderer.draw_color = BACKGROUND_COLOR
    renderer.clear()
    renderer.draw_color = AVATAR_COLOR
    renderer.fill_rect(avatar)

    renderer.present()

sdl2hl's People

Contributors

daniel-- avatar jdoda avatar

Watchers

 avatar

Forkers

daniel--

sdl2hl's Issues

Better error messages if sdl-image, sdl-mixer are not available.

On trying to run pip install sdl2hl without some of the needed libraries, the error message could be clearer.

Ideally this would behave like pycairo2, and tell me something like

$ apt get install libsdl2-mixer-dev libsdl2-ttf-dev

Example message:

pip install sdl2hl                                                         stu@computer  5903  18:45:10 
Collecting sdl2hl
  Using cached https://files.pythonhosted.org/packages/cb/14/5583e3077565807d2893d1d94097b9ffd63c8009c8d1c4b3f9649f828933/sdl2hl-0.2.1-py2.py3-none-any.whl
Collecting enum34>=1.0.0 (from sdl2hl)
  Using cached https://files.pythonhosted.org/packages/af/42/cb9355df32c69b553e72a2e28daee25d1611d2c0d9c272aa1d34204205b2/enum34-1.1.6-py3-none-any.whl
Collecting sdl2-cffi>=1.0.0 (from sdl2hl)
  Using cached https://files.pythonhosted.org/packages/95/c2/8ed310c0537b3aa275df099eaf37bd6427df36dde8a8285f364ee28184db/sdl2-cffi-1.0.6.tar.gz
    ERROR: Complete output from command python setup.py egg_info:
    ERROR: warning: no previously-included files found matching 'setup.pyc'
    warning: no previously-included files matching 'yacctab.*' found under directory 'tests'
    warning: no previously-included files matching 'lextab.*' found under directory 'tests'
    warning: no previously-included files matching 'yacctab.*' found under directory 'examples'
    warning: no previously-included files matching 'lextab.*' found under directory 'examples'
    zip_safe flag not set; analyzing archive contents...
    pycparser.ply.__pycache__.lex.cpython-36: module references __file__
    pycparser.ply.__pycache__.lex.cpython-36: module MAY be using inspect.getsourcefile
    pycparser.ply.__pycache__.yacc.cpython-36: module references __file__
    pycparser.ply.__pycache__.yacc.cpython-36: module MAY be using inspect.getsourcefile
    pycparser.ply.__pycache__.yacc.cpython-36: module MAY be using inspect.stack
    pycparser.ply.__pycache__.ygen.cpython-36: module references __file__
    
    Installed /tmp/pip-install-24d81nss/sdl2-cffi/.eggs/pycparser-2.19-py3.6.egg
    Searching for cffi>=1.0.0
    Reading https://pypi.org/simple/cffi/
    Downloading https://files.pythonhosted.org/packages/5f/bf/6aa1925384c23ffeb579e97a5569eb9abce41b6310b329352b8252cee1c3/cffi-1.12.3-cp36-cp36m-manylinux1_x86_64.whl#sha256=59b4dc008f98fc6ee2bb4fd7fc786a8d70000d058c2bbe2698275bc53a8d3fa7
    Best match: cffi 1.12.3
    Processing cffi-1.12.3-cp36-cp36m-manylinux1_x86_64.whl
    Installing cffi-1.12.3-cp36-cp36m-manylinux1_x86_64.whl to /tmp/pip-install-24d81nss/sdl2-cffi/.eggs
    writing requirements to /tmp/pip-install-24d81nss/sdl2-cffi/.eggs/cffi-1.12.3-py3.6-linux-x86_64.egg/EGG-INFO/requires.txt
    
    Installed /tmp/pip-install-24d81nss/sdl2-cffi/.eggs/cffi-1.12.3-py3.6-linux-x86_64.egg
    cpp: error: /usr/include/SDL2/SDL_ttf.h: No such file or directory
    cpp: warning: ‘-x c’ after last input file has no effect
    cpp: fatal error: no input files
    compilation terminated.
    Traceback (most recent call last):
      File "<string>", line 1, in <module>
      File "/tmp/pip-install-24d81nss/sdl2-cffi/setup.py", line 49, in <module>
        install_requires=['cffi>=1.0.0']
      File "/home/stu/.virtualenvs/shoebot-scenegraph-poc/lib/python3.6/site-packages/setuptools/__init__.py", line 145, in setup
        return distutils.core.setup(**attrs)
      File "/usr/lib/python3.6/distutils/core.py", line 108, in setup
        _setup_distribution = dist = klass(attrs)
      File "/home/stu/.virtualenvs/shoebot-scenegraph-poc/lib/python3.6/site-packages/setuptools/dist.py", line 444, in __init__
        k: v for k, v in attrs.items()
      File "/usr/lib/python3.6/distutils/dist.py", line 281, in __init__
        self.finalize_options()
      File "/home/stu/.virtualenvs/shoebot-scenegraph-poc/lib/python3.6/site-packages/setuptools/dist.py", line 732, in finalize_options
        ep.load()(self, ep.name, value)
      File "/tmp/pip-install-24d81nss/sdl2-cffi/.eggs/cffi-1.12.3-py3.6-linux-x86_64.egg/cffi/setuptools_ext.py", line 217, in cffi_modules
        add_cffi_module(dist, cffi_module)
      File "/tmp/pip-install-24d81nss/sdl2-cffi/.eggs/cffi-1.12.3-py3.6-linux-x86_64.egg/cffi/setuptools_ext.py", line 49, in add_cffi_module
        execfile(build_file_name, mod_vars)
      File "/tmp/pip-install-24d81nss/sdl2-cffi/.eggs/cffi-1.12.3-py3.6-linux-x86_64.egg/cffi/setuptools_ext.py", line 25, in execfile
        exec(code, glob, glob)
      File "sdl2/_cffi.py", line 238, in <module>
        ast = pycparser.parse_file(os.sep.join([include_dir, header]), **pycparser_args)
      File "/tmp/pip-install-24d81nss/sdl2-cffi/.eggs/pycparser-2.19-py3.6.egg/pycparser/__init__.py", line 83, in parse_file
        text = preprocess_file(filename, cpp_path, cpp_args)
      File "/tmp/pip-install-24d81nss/sdl2-cffi/.eggs/pycparser-2.19-py3.6.egg/pycparser/__init__.py", line 42, in preprocess_file
        text = check_output(path_list, universal_newlines=True)
      File "/usr/lib/python3.6/subprocess.py", line 356, in check_output
        **kwargs).stdout
      File "/usr/lib/python3.6/subprocess.py", line 438, in run
        output=stdout, stderr=stderr)
    subprocess.CalledProcessError: Command '['cpp', '-D__attribute__(x)=', '-D__inline=', '-D__restrict=', '-D__extension__=', '-D__GNUC_VA_LIST=', '-D__gnuc_va_list=void*', '-D__inline__=', '-D__forceinline=', '-D__volatile__=', '-D__MINGW_NOTHROW=', '-D__nothrow__=', '-DCRTIMP=', '-DSDL_FORCE_INLINE=', '-DDOXYGEN_SHOULD_IGNORE_THIS=', '-D_PROCESS_H_=', '-U__GNUC__', '-Ui386', '-U__i386__', '-U__MINGW32__', '/usr/include/SDL2/SDL_ttf.h']' returned non-zero exit status 1.
    ----------------------------------------
ERROR: Command "python setup.py egg_info" failed with error code 1 in /tmp/pip-install-24d81nss/sdl2-cffi/

Trouble building on Ubuntu 18.10

pip install sdl2hl                                                   100 ↵  stu@computer  5909  18:50:06 
Collecting sdl2hl
  Using cached https://files.pythonhosted.org/packages/cb/14/5583e3077565807d2893d1d94097b9ffd63c8009c8d1c4b3f9649f828933/sdl2hl-0.2.1-py2.py3-none-any.whl
Collecting sdl2-cffi>=1.0.0 (from sdl2hl)
  Using cached https://files.pythonhosted.org/packages/95/c2/8ed310c0537b3aa275df099eaf37bd6427df36dde8a8285f364ee28184db/sdl2-cffi-1.0.6.tar.gz
Collecting enum34>=1.0.0 (from sdl2hl)
  Using cached https://files.pythonhosted.org/packages/af/42/cb9355df32c69b553e72a2e28daee25d1611d2c0d9c272aa1d34204205b2/enum34-1.1.6-py3-none-any.whl
Requirement already satisfied: cffi>=1.0.0 in /home/stu/.virtualenvs/shoebot-scenegraph-poc/lib/python3.6/site-packages (from sdl2-cffi>=1.0.0->sdl2hl) (1.12.3)
Requirement already satisfied: pycparser in /home/stu/.virtualenvs/shoebot-scenegraph-poc/lib/python3.6/site-packages (from cffi>=1.0.0->sdl2-cffi>=1.0.0->sdl2hl) (2.19)
Building wheels for collected packages: sdl2-cffi
  Building wheel for sdl2-cffi (setup.py) ... error
  ERROR: Complete output from command /home/stu/.virtualenvs/shoebot-scenegraph-poc/bin/python3 -u -c 'import setuptools, tokenize;__file__='"'"'/tmp/pip-install-3zm2ggf2/sdl2-cffi/setup.py'"'"';f=getattr(tokenize, '"'"'open'"'"', open)(__file__);code=f.read().replace('"'"'\r\n'"'"', '"'"'\n'"'"');f.close();exec(compile(code, __file__, '"'"'exec'"'"'))' bdist_wheel -d /tmp/pip-wheel-a9evprfv --python-tag cp36:
  ERROR: Processing 139 defines, 175 types, 792 functions
  running bdist_wheel
  running build
  running build_py
  creating build
  creating build/lib.linux-x86_64-3.6
  creating build/lib.linux-x86_64-3.6/sdl2
  copying sdl2/sdl2.py -> build/lib.linux-x86_64-3.6/sdl2
  copying sdl2/_cffi.py -> build/lib.linux-x86_64-3.6/sdl2
  copying sdl2/gl.py -> build/lib.linux-x86_64-3.6/sdl2
  copying sdl2/__init__.py -> build/lib.linux-x86_64-3.6/sdl2
  copying sdl2/gl_api.py -> build/lib.linux-x86_64-3.6/sdl2
  copying sdl2/gl.xml -> build/lib.linux-x86_64-3.6/sdl2
  running build_ext
  generating cffi module 'build/temp.linux-x86_64-3.6/sdl2._gl.c'
  creating build/temp.linux-x86_64-3.6
  generating cffi module 'build/temp.linux-x86_64-3.6/sdl2._sdl2.c'
  Traceback (most recent call last):
    File "<string>", line 1, in <module>
    File "/tmp/pip-install-3zm2ggf2/sdl2-cffi/setup.py", line 49, in <module>
      install_requires=['cffi>=1.0.0']
    File "/home/stu/.virtualenvs/shoebot-scenegraph-poc/lib/python3.6/site-packages/setuptools/__init__.py", line 145, in setup
      return distutils.core.setup(**attrs)
    File "/usr/lib/python3.6/distutils/core.py", line 148, in setup
      dist.run_commands()
    File "/usr/lib/python3.6/distutils/dist.py", line 955, in run_commands
      self.run_command(cmd)
    File "/usr/lib/python3.6/distutils/dist.py", line 974, in run_command
      cmd_obj.run()
    File "/home/stu/.virtualenvs/shoebot-scenegraph-poc/lib/python3.6/site-packages/wheel/bdist_wheel.py", line 192, in run
      self.run_command('build')
    File "/usr/lib/python3.6/distutils/cmd.py", line 313, in run_command
      self.distribution.run_command(command)
    File "/usr/lib/python3.6/distutils/dist.py", line 974, in run_command
      cmd_obj.run()
    File "/usr/lib/python3.6/distutils/command/build.py", line 135, in run
      self.run_command(cmd_name)
    File "/usr/lib/python3.6/distutils/cmd.py", line 313, in run_command
      self.distribution.run_command(command)
    File "/usr/lib/python3.6/distutils/dist.py", line 974, in run_command
      cmd_obj.run()
    File "/home/stu/.virtualenvs/shoebot-scenegraph-poc/lib/python3.6/site-packages/cffi/setuptools_ext.py", line 142, in run
      base_class.run(self)
    File "/home/stu/.virtualenvs/shoebot-scenegraph-poc/lib/python3.6/site-packages/cffi/setuptools_ext.py", line 141, in run
      ext.sources[0] = make_mod(self.build_temp, pre_run)
    File "/home/stu/.virtualenvs/shoebot-scenegraph-poc/lib/python3.6/site-packages/cffi/setuptools_ext.py", line 127, in make_mod
      updated = recompiler.make_c_source(ffi, module_name, source, c_file)
    File "/home/stu/.virtualenvs/shoebot-scenegraph-poc/lib/python3.6/site-packages/cffi/recompiler.py", line 1414, in make_c_source
      verbose)
    File "/home/stu/.virtualenvs/shoebot-scenegraph-poc/lib/python3.6/site-packages/cffi/recompiler.py", line 1391, in _make_c_or_py_source
      recompiler.write_source_to_f(f, preamble)
    File "/home/stu/.virtualenvs/shoebot-scenegraph-poc/lib/python3.6/site-packages/cffi/recompiler.py", line 273, in write_source_to_f
      self.write_c_source_to_f(f, preamble)
    File "/home/stu/.virtualenvs/shoebot-scenegraph-poc/lib/python3.6/site-packages/cffi/recompiler.py", line 341, in write_c_source_to_f
      self._generate("decl")
    File "/home/stu/.virtualenvs/shoebot-scenegraph-poc/lib/python3.6/site-packages/cffi/recompiler.py", line 224, in _generate
      method(tp, realname)
    File "/home/stu/.virtualenvs/shoebot-scenegraph-poc/lib/python3.6/site-packages/cffi/recompiler.py", line 1135, in _generate_cpy_macro_decl
      self._generate_cpy_const(True, name, check_value=check_value)
    File "/home/stu/.virtualenvs/shoebot-scenegraph-poc/lib/python3.6/site-packages/cffi/recompiler.py", line 1042, in _generate_cpy_const
      "duplicate declaration of %s '%s'" % (category, name))
  cffi.VerificationError: macro SDL_FALSE: duplicate declaration of const 'SDL_FALSE'
  ----------------------------------------
  ERROR: Failed building wheel for sdl2-cffi

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.