holoviz / panel

Panel: The powerful data exploration & web app framework for Python
https://panel.holoviz.org
BSD 3-Clause "New" or "Revised" License
4.73k stars 516 forks source link

[vtk] keypress event bug #378

Closed banesullivan closed 5 years ago

banesullivan commented 5 years ago

When using panel's new VTK functionality in a Joptyer notebook, the panel listens to key events outside of its scope.

When writing new code in a different cell, buttons like v and s alter the scene - this is unexpected behavior. See example below using vtki which sends its renderer to panel's VTK code:

ezgif com-video-to-gif-3

xavArtley commented 5 years ago

I don't know if we can do something about it. However we sould document the key bindings somwhere.

banesullivan commented 5 years ago

we should document the key bindings somewhere.

I definitely agree that they should be documented - I only discovered v for vertex/point representation and s for surface by typing code slowly.

I don't know if we can do something about it.

I think this is a panel issue. If you display a VTKjs rendering via HTML this behavior is not experienced:


from IPython.core.display import display, HTML
display(HTML(
'''
<div style="position: relative; padding-bottom: 56.25%; height: 0; overflow: hidden; max-width: 100%; height: auto;">
        <iframe src="http://volcano.pvgeo.org" frameborder="0" allowfullscreen style="position: absolute; top: 0; left: 0; width: 100%; height: 100%;"></iframe>
    </div>
'''))

ezgif com-video-to-gif-5

panel is on top, HTML is bottom. Note that the HTML output is simply pointing to this url: http://volcano.pvgeo.org which has keyboard shortcuts when on the webpage but not in the notebook

banesullivan commented 5 years ago

The other thing to note is that this is causing a noticeable lag when typing s, v, w, or other keys that affect the panel scene.

If a notebook has more than a few VTK panel scenes, then adding new code with the letters v, s, or w will heavily lag the notebook (and be quite an annoyance). For example, typing examples.download_st_helens().warp_by_scalar().plot() took almost a minute after loading up 5 other scenes:

ezgif com-video-to-gif-6

xavArtley commented 5 years ago

key events are set by vtkjs interactor: https://github.com/Kitware/vtk-js/blob/cc48e943037e0ed980c5e370b0e716df3309a5b2/Sources/Rendering/Core/RenderWindowInteractor/index.js#L214-L222

They are attached to the document body so it's not a panel bug. What I can try to do is to add an option to activate or deactivate keybindings

xavArtley commented 5 years ago

Does something like this would be sufficient?

ezgif com-video-to-gif (7)

philippjfr commented 5 years ago

Yeah, I don't see a better solution either. The iframe example doesn't capture the keybindings because that's how iframe's work, anything embedded in a page will. If VTK had some concept of giving focus to the view window maybe we could make sure it only responds if the viewing window has been selected.

xavArtley commented 5 years ago

Actually I don't if the best is not just to remove all keybindings

banesullivan commented 5 years ago

I've installed panel from the master branch and this still isn't resolved. Am I missing something?

xavArtley commented 5 years ago

Did you recompiled extensions? pip install git+... will not recompile extensions. you need to run a python setup.py install or develop

xavArtley commented 5 years ago

@philippjfr shouldn't we subclass distutils.command.build.build in setup.py ? with something like :

class CustomBuildCommand(build):
    """Custom installation for build mode."""

    def run(self):
        try:
            from panel.compiler import build_custom_models
            print("Building custom models:")
            build_custom_models()
        except ImportError as e:
            print("Custom model compilation failed with: %s" % e)
        build.run(self)
philippjfr commented 5 years ago

@xavArtley You're probably right, I don't know enough about how distutils works to know for sure. Do the develop and install commands both call the build command, i.e. could it replace them?

banesullivan commented 5 years ago

@xavArtley, thanks for the tip! I had some build artifact lying around from a previous conda install after I cloned the repo that needed to be cleaned up - all good now!