| 1 | """ |
| 2 | This file imports glfw and converts constant and function names to the style |
| 3 | of the GLFW C API, adding GLFW_ and glfw prefixes and using CamelCase for |
| 4 | function names. |
| 5 | |
| 6 | This file is only needed to be run when adding functions to the wrapper. |
| 7 | """ |
| 8 | |
| 9 | from collections import OrderedDict |
| 10 | import glfw |
| 11 | |
| 12 | constant_names = OrderedDict() |
| 13 | function_names = OrderedDict() |
| 14 | constant_type = int |
| 15 | function_type = type(glfw.init) |
| 16 | for pythonic_name in sorted(dir(glfw)): |
| 17 | if pythonic_name.startswith('_'): |
| 18 | continue |
| 19 | obj = getattr(glfw, pythonic_name) |
| 20 | if isinstance(obj, function_type): |
| 21 | if pythonic_name == 'get_joystick_guid': |
| 22 | cstyle_name = 'glfwGetJoystickGUID' |
| 23 | else: |
| 24 | cstyle_name = 'glfw' + ''.join(word.title() for word in pythonic_name.split('_')) |
| 25 | function_names[pythonic_name] = cstyle_name |
| 26 | elif isinstance(obj, constant_type): |
| 27 | cstyle_name = 'GLFW_' + pythonic_name |
| 28 | constant_names[pythonic_name] = cstyle_name |
| 29 | print('""" Automatically generated C-style module for pyGLFW """') |
| 30 | print('from . import (') |
| 31 | for pythonic_name, cstyle_name in constant_names.items(): |
| 32 | print(' {} as {},'.format(pythonic_name, cstyle_name)) |
| 33 | for pythonic_name, cstyle_name in function_names.items(): |
| 34 | print(' {} as {},'.format(pythonic_name, cstyle_name)) |
| 35 | print(')') |