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

example of ipywidgets interaction #38

Open
vianamp opened this issue Jun 26, 2019 · 2 comments
Open

example of ipywidgets interaction #38

vianamp opened this issue Jun 26, 2019 · 2 comments
Labels
enhancement jupyter long-term longer term tricky fix or enhancement

Comments

@vianamp
Copy link

vianamp commented Jun 26, 2019

Hey Marco.

I am trying to come up with a simple example where I use ipywidget to control an actor, but I had no success so far. Would you have any suggestion?

This is what my code looks like right now:

from vtkplotter import *
from ipywidgets import interact

vp = Plotter()
s = Sphere()
vp.add(s)
def f(x):
    s.pos(x,x,x)
interact(f, x=10)
vp.show()
@marcomusy
Copy link
Owner

Hi Matheus
loops and widgets from inside notebooks with the k3d backend are not yet functional.
It's on my to-do list, but i'll only able to implement it later next week.. for the moment the only option is to pop up a normal vtk rendering window, something like this:
(with additional limitation that one cannot interact smoothly with the rendered scene)

from vtkplotter import *
from ipywidgets import interact, Button

embedWindow(False)

vp = Plotter(axes=True, interactive=False)

vp += Cube()
s = Sphere()
vp += s

def f(x):
    s.pos(x,x,x)
    vp.show(resetcam=False)

def b(b):
    vp.close()

interact(f, x=10)
button = Button(description="close window")
button.on_click(b)   
display(button)

These examples also might help:
https://github.com/marcomusy/vtkplotter/blob/master/examples/basic/keypress.py
https://github.com/marcomusy/vtkplotter/blob/master/examples/basic/buttons.py
https://github.com/marcomusy/vtkplotter/blob/master/examples/basic/sliders.py
https://github.com/marcomusy/vtkplotter/blob/master/examples/basic/sliders3d.py

@vianamp
Copy link
Author

vianamp commented Jun 27, 2019

Thank you Marco. This worked fine for now.
vtkPlotter is already very nice, but the full integration with widgets will put vtkPlotter in another level definitely.

-m

@marcomusy marcomusy added the long-term longer term tricky fix or enhancement label Jul 10, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement jupyter long-term longer term tricky fix or enhancement
Projects
None yet
Development

No branches or pull requests

2 participants