Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

pytype_mapping confusion #1049

Closed
ejmeitz opened this issue Aug 20, 2023 · 0 comments
Closed

pytype_mapping confusion #1049

ejmeitz opened this issue Aug 20, 2023 · 0 comments

Comments

@ejmeitz
Copy link

ejmeitz commented Aug 20, 2023

Hello,

I'm trying to use the pytype_mapping function to get automatic conversion from a PyObject type to one of my wrapper types in Julia. My code is below:

vis= pyimport("ovito.vis")

struct OpenGLRenderer <: Renderer
    o::PyObject

    function OpenGLRenderer(antialiasing_level)
        return new(vis.OpenGLRenderer(antialiasing_level = antialiasing_level))
    end
end

pytype_mapping(vis."OpenGLRenderer", OpenGLRenderer)

renderer = vis.OpenGLRenderer()

The typeof renderer is just PyObject still how do I make this automatically recognize as my Julia type? I'm a little confused as to what the correct pattern is supposed to be here. If I call pytype_query on renderer PyCall sees that renderer could be my OpenGLRenderer Julia type but that conversion is not happening automatically.

On the flip side, I also want the user to be able to construct their own OpenGLRenderer without having to call the python library. My constructor above works for that but it required me to manually add the antialiasing_level. Is the only way around this to use kwargs and args?

@ejmeitz ejmeitz closed this as completed Aug 28, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant