#!/usr/bin/env python3 import ctypes from ctypes import CFUNCTYPE, POINTER libcgui = None def on_evt(ptr, evt_str): global libcgui evt_str = ctypes.string_at(evt_str).decode("utf-8") if evt_str == "KeyPress,q": libcgui.set_rep_exit_flag(ptr, True) print("on_event(?, ", evt_str, ")") if __name__ == '__main__': print("Inside python...") print("Opening libcgui...") libcgui = ctypes.CDLL('./target/release/libcgui.so') #win_ptr = POINTER(ctypes.c_void_p)( ctypes.c_void_p(libcgui.alloc_win()) ) libcgui.alloc_win.argtypes = [] libcgui.alloc_win.restype = ctypes.c_void_p win_ptr = libcgui.alloc_win() print("win_ptr = ", win_ptr) print("Adding function callback...") c_wrapp_for_func = CFUNCTYPE(None, POINTER(ctypes.c_void_p), POINTER(ctypes.c_char)) on_event_cfunc = c_wrapp_for_func(on_evt) print("Adding...") libcgui.add_callback(ctypes.cast(win_ptr, ctypes.c_void_p), on_event_cfunc) print("Running main loop...") #libcgui.call_callbacks(ctypes.cast(win_ptr, ctypes.c_void_p), ctypes.c_char_p( "Some Event Mess".encode('utf-8') )) libcgui.event_loop(ctypes.cast(win_ptr, ctypes.c_void_p)) print("Deallocating...") libcgui.dealloc_win(ctypes.cast(win_ptr, ctypes.c_void_p))