Source

yuureinohebi / gsut.py

Full commit
#/usr/bin/env python3
"""Ghostscript utilities toolkit, like GLut, but better!"""
import libgs
import gsu

def std_stream_handler(f):
    return libgs.c_stdstream_t(f)

class GhostScriptInterpreter(object):
    def __init__(self):
        gs = libgs.gsapi_new_instance()
        libgs.gsapi_init_with_args(gs, ['gs'])
        libgs.gsapi_set_stdio(gs, self._stdin_handler, self._stdout_handler,
                self._stderr_handler)
        self._instance = gs

    @std_stream_handler
    def _stdout_handler(caller_handle, buf, length):
        print(caller_handle, buf, length)
        return 0

    _stdin_handler = _stdout_handler
    _stderr_handler = _stdout_handler

def main():
    gsi = GhostScriptInterpreter()

if __name__ == '__main__':
    main()