diff --git a/CMakeLists.txt b/CMakeLists.txt index 3329964..cac8cea 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -114,4 +114,12 @@ add_custom_command( POST_BUILD COMMAND ${CMAKE_COMMAND} -E copy_directory ${CPYTHON_STDLIB_DIR} $/lib +) + +# Copy the PyG2O library into the build/lib folder +add_custom_command( + TARGET ${PROJECT_NAME} + POST_BUILD + COMMAND ${CMAKE_COMMAND} + -E copy_directory ${CMAKE_SOURCE_DIR}/g2o $/lib/g2o ) \ No newline at end of file diff --git a/g2o/__init__.py b/g2o/__init__.py new file mode 100644 index 0000000..201129a --- /dev/null +++ b/g2o/__init__.py @@ -0,0 +1,5 @@ + +from g2o.events import addEvent +from g2o.events import callEvent +from g2o.events import event +from g2o.events import removeEventHandler \ No newline at end of file diff --git a/g2o/events.py b/g2o/events.py new file mode 100644 index 0000000..715e660 --- /dev/null +++ b/g2o/events.py @@ -0,0 +1,36 @@ + +eventList = {} + +def callEvent(name, **args): + if name in eventList: + for event in eventList[name]: + event['function'](**args) + +def addEvent(name): + if not name in eventList: + eventList[name] = [] + +def event(name, priority = 9999): + def inlineEvt(func): + if not name in eventList: + pass + + eventList[name].append({'function': func, 'priority': priority}) + eventList[name].sort(key = lambda x: x['priority']) + return func + return inlineEvt + +def removeEventHandler(name, func): + if not name in eventList: + pass + + for index, item in enumerate(eventList[name]): + if item['function'] == func: + del eventList[name][index] + +## registering all the events + +addEvent('onInit') +addEvent('onExit') +addEvent('onTick') +addEvent('onTime') \ No newline at end of file