wjakob / nanogui

Minimalistic GUI library for OpenGL
Other
4.66k stars 608 forks source link

Exposing derived widgets in Python #37

Closed mrzv closed 8 years ago

mrzv commented 8 years ago

Suppose I'm writing a library that has some new widgets, maybe some new screens in it. I can expose those to Python using pybind11 without a problem, but I cannot find a way to express that they derive from the respective nanogui classes. It seems the solution would be to expose instances like widget as the static variables of nanogui.so (and define them for all the classes). It would probably mean that the new libraries would have to link against the nanogui.so, which is not ideal, but not a deal-breaker either.

I hope it makes sense what I'm after.

wjakob commented 8 years ago

Can't you import the base library using module::import and initialize the parent class_ via module::attr or so?

mrzv commented 8 years ago

Oh, interesting. That didn't occur to me. I'm going to try it now.

mrzv commented 8 years ago

Brilliant! It works.

A tangentially related bug. Calling py::module::import on a non-existent module (or the one not in your path) from PYBIND11_PLUGIN(...) results in a segfault. Probably an exception should be thrown.

wjakob commented 8 years ago

I committed a patch with proper error handling at module import time. Closing this ticket.