The child object of a layer class does not inherit its key bindings.
This bug happens because of the changes in PR #1528.
Steps to reproduce the behavior:
import napari
from skimage import data
class MyPoints(napari.layers.Points):
def random_function():
return 42
with napari.gui_qt():
viewer = napari.view_image(data.astronaut())
points = MyPoints()
viewer.add_layer(points)
I expected the default key bindings to work normally.
napari: 0.3.7.dev12+ge468550.d20200806
Platform: Darwin-18.7.0-x86_64-i386-64bit
Python: 3.7.8 | packaged by conda-forge | (default, Jul 31 2020, 02:37:09) [Clang 10.0.1 ]
Qt: 5.14.2
PySide2: 5.14.2.3
NumPy: 1.19.1
SciPy: 1.5.2
Dask: 2.22.0
VisPy: 0.6.4
GL version: 2.1 ATI-2.11.22
MAX_TEXTURE_SIZE: 16384
Plugins:
- napari_plugin_engine: 0.1.7
- svg: 0.1.3
I'm not entirely sure if this is expected or not.
However, if the key binding inheritance is not expected, it should not show "hold
Hi @JoOkuma, so sorry for taking so long to get back to you on this one. I'm running into this problem again myself actually too. Different context, but same issue. I'm not sure if @jni or @kne42 have any ideas on this one
Looking back at the code, this was intended functionality https://github.com/napari/napari/blob/bc3298bb047b00d65133d5e4cf969b62aa65def1/napari/utils/key_bindings.py#L313-L315
IIRC, I originally had it toss out inherited keybindings I think maybe because some of the overwriting might get confusing.
I realize now that this is probably undesirable functionality. To fix this, you would need to traverse down the MRO for parent here, adding in each class_keybindings where present: https://github.com/napari/napari/blob/bc3298bb047b00d65133d5e4cf969b62aa65def1/napari/utils/key_bindings.py#L361-L363
You would do this instead of simply copying over the inherited keybindings since it wouldn't be updated properly when the superclass has its keybindings updated.
Most helpful comment
Looking back at the code, this was intended functionality https://github.com/napari/napari/blob/bc3298bb047b00d65133d5e4cf969b62aa65def1/napari/utils/key_bindings.py#L313-L315
IIRC, I originally had it toss out inherited keybindings I think maybe because some of the overwriting might get confusing.
I realize now that this is probably undesirable functionality. To fix this, you would need to traverse down the MRO for
parenthere, adding in eachclass_keybindingswhere present: https://github.com/napari/napari/blob/bc3298bb047b00d65133d5e4cf969b62aa65def1/napari/utils/key_bindings.py#L361-L363You would do this instead of simply copying over the inherited keybindings since it wouldn't be updated properly when the superclass has its keybindings updated.