bkntr / napari-brainways

Brainways UI plugin for napari
GNU General Public License v3.0
6 stars 0 forks source link

Attribute error at 'Atlas Registration' when pressing up and down keys #28

Open iezqrom opened 2 weeks ago

iezqrom commented 2 weeks ago

On the 'Atlas Registration' screen, I get the following error when pressing up and down keys:

--------------------------------------------------------------------------
AttributeError                            Traceback (most recent call last)
File ~/.local/lib/python3.10/site-packages/vispy/app/backends/_qt.py:555, in QtBaseCanvasBackend.keyPressEvent(self=<vispy.app.backends._qt.CanvasBackendDesktop object>, ev=<PyQt5.QtGui.QKeyEvent object>)
    554 def keyPressEvent(self, ev):
--> 555     self._keyEvent(self._vispy_canvas.events.key_press, ev)
        self._vispy_canvas.events.key_press = <vispy.util.event.EventEmitter object at 0x7b5a687c3850>
        ev = <PyQt5.QtGui.QKeyEvent object at 0x7b5a2f53e7a0>
        self = <vispy.app.backends._qt.CanvasBackendDesktop object at 0x7b5a687c65f0>
        self._vispy_canvas.events = <vispy.util.event.EmitterGroup object at 0x7b5a687c3820>
        self._vispy_canvas = <NapariSceneCanvas (PyQt5) at 0x7b5a687c1930>

File ~/.local/lib/python3.10/site-packages/vispy/app/backends/_qt.py:647, in QtBaseCanvasBackend._keyEvent(self=<vispy.app.backends._qt.CanvasBackendDesktop object>, func=<vispy.util.event.EventEmitter object>, ev=<PyQt5.QtGui.QKeyEvent object>)
    645     key = None
    646 mod = self._modifiers(ev)
--> 647 func(native=ev, key=key, text=str(ev.text()), modifiers=mod)
        key = <Key 'Up'>
        mod = ()
        ev = <PyQt5.QtGui.QKeyEvent object at 0x7b5a2f53e7a0>
        func = <vispy.util.event.EventEmitter object at 0x7b5a687c3850>

File ~/.local/lib/python3.10/site-packages/vispy/util/event.py:453, in EventEmitter.__call__(self=<vispy.util.event.EventEmitter object>, *args=(), **kwargs={'key': <Key 'Up'>, 'modifiers': (), 'native': <PyQt5.QtGui.QKeyEvent object>, 'text': ''})
    450 if self._emitting > 1:
    451     raise RuntimeError('EventEmitter loop detected!')
--> 453 self._invoke_callback(cb, event)
        event = <KeyEvent blocked=False handled=False key=<Key 'Up'> modifiers=() native=<PyQt5.QtGui.QKeyEvent object at 0x7b5a2f53e7a0> source=None sources=[] text= type=key_press>
        self = <vispy.util.event.EventEmitter object at 0x7b5a687c3850>
        cb = <bound method KeymapHandler.on_key_press of <napari.utils.key_bindings.KeymapHandler object at 0x7b5a687b5420>>
    454 if event.blocked:
    455     break

File ~/.local/lib/python3.10/site-packages/vispy/util/event.py:471, in EventEmitter._invoke_callback(self=<vispy.util.event.EventEmitter object>, cb=<bound method KeymapHandler.on_key_press of <napari.utils.key_bindings.KeymapHandler object>>, event=<KeyEvent blocked=False handled=False key=<Key '...7a0> source=None sources=[] text= type=key_press>)
    469     cb(event)
    470 except Exception:
--> 471     _handle_exception(self.ignore_callback_errors,
        self = <vispy.util.event.EventEmitter object at 0x7b5a687c3850>
        cb = <bound method KeymapHandler.on_key_press of <napari.utils.key_bindings.KeymapHandler object at 0x7b5a687b5420>>
        event = <KeyEvent blocked=False handled=False key=<Key 'Up'> modifiers=() native=<PyQt5.QtGui.QKeyEvent object at 0x7b5a2f53e7a0> source=None sources=[] text= type=key_press>
        (cb, event) = (<bound method KeymapHandler.on_key_press of <napari.utils.key_bindings.KeymapHandler object at 0x7b5a687b5420>>, <KeyEvent blocked=False handled=False key=<Key 'Up'> modifiers=() native=<PyQt5.QtGui.QKeyEvent object at 0x7b5a2f53e7a0> source=None sources=[] text= type=key_press>)
    472                       self.print_callback_errors,
    473                       self, cb_event=(cb, event))

File ~/.local/lib/python3.10/site-packages/vispy/util/event.py:469, in EventEmitter._invoke_callback(self=<vispy.util.event.EventEmitter object>, cb=<bound method KeymapHandler.on_key_press of <napari.utils.key_bindings.KeymapHandler object>>, event=<KeyEvent blocked=False handled=False key=<Key '...7a0> source=None sources=[] text= type=key_press>)
    467 def _invoke_callback(self, cb, event):
    468     try:
--> 469         cb(event)
        cb = <bound method KeymapHandler.on_key_press of <napari.utils.key_bindings.KeymapHandler object at 0x7b5a687b5420>>
        event = <KeyEvent blocked=False handled=False key=<Key 'Up'> modifiers=() native=<PyQt5.QtGui.QKeyEvent object at 0x7b5a2f53e7a0> source=None sources=[] text= type=key_press>
    470     except Exception:
    471         _handle_exception(self.ignore_callback_errors,
    472                           self.print_callback_errors,
    473                           self, cb_event=(cb, event))

File ~/miniconda3/envs/microscoping/lib/python3.10/site-packages/napari/utils/key_bindings.py:515, in KeymapHandler.on_key_press(self=<napari.utils.key_bindings.KeymapHandler object>, event=<KeyEvent blocked=False handled=False key=<Key '...7a0> source=None sources=[] text= type=key_press>)
    505 if (
    506     event.native is not None
    507     and event.native.isAutoRepeat()
   (...)
    511     # unless the combo being held down is one of the autorepeatables or
    512     # one of the navigation keys (helps with scrolling).
    513     return
--> 515 self.press_key(kb)
        kb = <KeyBinding at 0x7b59b81f5f60: Up>
        self = <napari.utils.key_bindings.KeymapHandler object at 0x7b5a687b5420>

File ~/miniconda3/envs/microscoping/lib/python3.10/site-packages/napari/utils/key_bindings.py:437, in KeymapHandler.press_key(self=<napari.utils.key_bindings.KeymapHandler object>, key_bind=<KeyBinding at 0x7b59b81f5f60: Up>)
    428 if not callable(func):
    429     raise TypeError(
    430         trans._(
    431             'expected {func} to be callable',
   (...)
    434         )
    435     )
--> 437 generator_or_callback = func()
        func = <bound method Affine2DController.keybind_modify_params.<locals>._func of Viewer(camera=Camera(center=(0.0, 77.9968944099379, 232.16785714285714), zoom=2.3759573061606174, angles=(0.0, 0.0, 90.0), perspective=0.0, mouse_pan=True, mouse_zoom=True), cursor=Cursor(position=(272.0239562803102, 462.39085997503184), scaled=True, style=<CursorStyle.STANDARD: 'standard'>, size=1.0), dims=Dims(ndim=2, ndisplay=2, order=(0, 1), axis_labels=('0', '1'), rollable=(True, True), range=(RangeTuple(start=-1.5031055900621118, stop=157.49689440993788, step=0.2204968944099379), RangeTuple(start=11.157142857142857, stop=453.56832298136646, step=0.2204968944099379)), margin_left=(0.0, 0.0), margin_right=(0.0, 0.0), point=(153.06521739130434, 254.6642857142857), last_used=0), grid=GridCanvas(stride=1, shape=(-1, -1), enabled=False), layers=[<Image layer 'Input' at 0x7b5a668cf880>, <Image layer 'Mask' at 0x7b59e9ff5090>, <Image layer 'Atlas Slice' at 0x7b5a2edf9630>], help='use <2> for transform', status={'layer_name': 'Atlas Slice', 'layer_base': 'Atlas Slice', 'source_type': '', 'plugin': '', 'coordinates': ' [272 462]'}, tooltip=Tooltip(visible=False, text=''), theme='dark', title='JPCM_07653 - /home/iezquer/Documents/data_server/wetness/wetness_brainwide_immuno_cfos/data/raw/JPCM_07653_240802/slide_2/Process_906.vsi [Scene #0]', mouse_over_canvas=True, mouse_move_callbacks=[], mouse_drag_callbacks=[], mouse_double_click_callbacks=[], mouse_wheel_callbacks=[<function dims_scroll at 0x7b5a6a62a200>], _persisted_mouse_event={}, _mouse_drag_gen={}, _mouse_wheel_gen={}, _keymap={<KeyBinding at 0x7b5a66ce0f40: PageDown>: <bound method BrainwaysUI.next_step of <napari_brainways.brainways_ui.BrainwaysUI object at 0x7b5a64311000>>, <KeyBinding at 0x7b5a66ce0d30: PageUp>: <bound method BrainwaysUI.prev_step of <napari_brainways.brainways_ui.BrainwaysUI object at 0x7b5a64311000>>, <KeyBinding at 0x7b5a66ce0fa0: N>: <bound method BrainwaysUI.next_image of <napari_brainways.brainways_ui.BrainwaysUI object at 0x7b5a64311000>>, <KeyBinding at 0x7b5a66ce1060: B>: <bound method BrainwaysUI.prev_image of <napari_brainways.brainways_ui.BrainwaysUI object at 0x7b5a64311000>>, <KeyBinding at 0x7b5a66ce10f0: Shift+N>: <bound method BrainwaysUI.next_subject of <napari_brainways.brainways_ui.BrainwaysUI object at 0x7b5a64311000>>, <KeyBinding at 0x7b5a66ce1180: Shift+B>: <bound method BrainwaysUI.prev_subject of <napari_brainways.brainways_ui.BrainwaysUI object at 0x7b5a64311000>>, <KeyBinding at 0x7b5a66ce1210: Home>: <function BrainwaysUI._register_keybinds.<locals>.<lambda> at 0x7b5a5c2da320>, <KeyBinding at 0x7b5a66ce12a0: End>: <function BrainwaysUI._register_keybinds.<locals>.<lambda> at 0x7b5a5c2da560>, <KeyBinding at 0x7b5a5db3ead0: Ctrl+Z>: <bound method TpsController.previous_params of <napari_brainways.controllers.tps_controller.TpsController object at 0x7b5a643189a0>>, <KeyBinding at 0x7b5a5db3c280: Ctrl+Y>: <bound method TpsController.next_params of <napari_brainways.controllers.tps_controller.TpsController object at 0x7b5a643189a0>>, <KeyBinding at 0x7b5a5db3d3f0: Ctrl+Shift+Z>: <bound method TpsController.next_params of <napari_brainways.controllers.tps_controller.TpsController object at 0x7b5a643189a0>>, <KeyBinding at 0x7b5a5db3cdf0: A>: <bound method TpsController.set_points_mode_add of <napari_brainways.controllers.tps_controller.TpsController object at 0x7b5a643189a0>>, <KeyBinding at 0x7b59cc0475b0: Up>: <function Affine2DController.keybind_modify_params.<locals>._func at 0x7b5a5e7e64d0>, <KeyBinding at 0x7b59cc044070: Down>: <function Affine2DController.keybind_modify_params.<locals>._func at 0x7b5a5e7e4dc0>, <KeyBinding at 0x7b59cc046b90: Shift+Up>: <function Affine2DController.keybind_modify_params.<locals>._func at 0x7b5a5e7e7c70>, <KeyBinding at 0x7b59cc047e20: Shift+Down>: <function Affine2DController.keybind_modify_params.<locals>._func at 0x7b5a5e7e5630>, <KeyBinding at 0x7b59cc0d6440: Left>: <function RegistrationController.get_keybind_fn.<locals>._fn at 0x7b5a5ddb3640>, <KeyBinding at 0x7b5a5ddce5c0: Right>: <function RegistrationController.get_keybind_fn.<locals>._fn at 0x7b5a2ce639a0>, <KeyBinding at 0x7b5a668cdae0: Shift+Left>: <function RegistrationController.get_keybind_fn.<locals>._fn at 0x7b5a2ce61fc0>, <KeyBinding at 0x7b5a5d9d8730: Shift+Right>: <function RegistrationController.get_keybind_fn.<locals>._fn at 0x7b5a2ce61d80>, <KeyBinding at 0x7b5a5d9da830: Ctrl+Left>: <function RegistrationController.get_keybind_fn.<locals>._fn at 0x7b5a2ce60b80>, <KeyBinding at 0x7b5a5d9d8340: Ctrl+Right>: <function RegistrationController.get_keybind_fn.<locals>._fn at 0x7b59c1ff6b90>, <KeyBinding at 0x7b5a5d9d8e50: Ctrl+Down>: <function RegistrationController.get_keybind_fn.<locals>._fn at 0x7b59c1ff75b0>, <KeyBinding at 0x7b5a5d9d88b0: Ctrl+Up>: <function RegistrationController.get_keybind_fn.<locals>._fn at 0x7b59c1ff55a0>, <KeyBinding at 0x7b5a5dc30100: Alt+Left>: <function RegistrationController.get_keybind_fn.<locals>._fn at 0x7b59c1ff69e0>, <KeyBinding at 0x7b59cc047df0: Alt+Right>: <function RegistrationController.get_keybind_fn.<locals>._fn at 0x7b59c1ff7c70>, <KeyBinding at 0x7b59cc047a60: Alt+Up>: <function RegistrationController.get_keybind_fn.<locals>._fn at 0x7b59c1ff64d0>, <KeyBinding at 0x7b59cc047d30: Alt+Down>: <function RegistrationController.get_keybind_fn.<locals>._fn at 0x7b59c1ff7d00>, <KeyBinding at 0x7b59cc047b20: >: <bound method RegistrationController.show_help of <napari_brainways.controllers.registration_controller.RegistrationController object at 0x7b5a64318a00>>})>
    439 key = str(key_bind.parts[-1].key)
    441 if inspect.isgeneratorfunction(func):

File ~/miniconda3/envs/microscoping/lib/python3.10/site-packages/napari_brainways/controllers/affine_2d_controller.py:231, in Affine2DController.keybind_modify_params.<locals>._func(_=Viewer(camera=Camera(center=(0.0, 77.99689440993...gistrationController object at 0x7b5a64318a00>>}))
    229     kwargs["tx"] = self._params.affine.tx + tx
    230 if ty is not None:
--> 231     kwargs["ty"] = self._params.affine.ty + ty
        kwargs = {}
        ty = -1
        self._params = None
        self = <napari_brainways.controllers.affine_2d_controller.Affine2DController object at 0x7b5a643189d0>
    232 if sx is not None:
    233     kwargs["sx"] = self._params.affine.sx + sx

AttributeError: 'NoneType' object has no attribute 'affine'

It doesn't break the software, I think it's a small bug, according to the keyboard shortcut legend, up and down arrow keys shouldn't be attributed to any action.

iezqrom commented 2 weeks ago

The two comments above seem SPAM

bkntr commented 2 weeks ago

Thank you for reporting this issue, yes it seems like a bug that connects the Rigid Registration keys with the Atlas Registration module. Should be an easy fix, will update soon.