TIL

Today I Learned. 知ったこと、学んだことを書いていく

keybindingに渡されるeventという引数は何者!? - Python

keybindingのメソッドに渡されるeventという引数は何者?

prompt_toolkit.key_binding.key_processor.KeyPressEventというやつ

https://github.com/prompt-toolkit/python-prompt-toolkit/blob/master/prompt_toolkit/key_binding/key_processor.py#L412

  • data
  • key_processor
  • app: The current Application object.
  • current_buffer: The current buffer.
  • arg
  • arg_present
  • append_to_arg_count
  • cli
@kb.add('a')
def _(event):
    event.app.xxxxx

みたいにevent.appしておけばどうにかなる説

Application オブジェクトに全部格納してるから、それ見ればなんとかなるしょみたいな

ちょっと脱線

Applicaiton.current_bufferlayout.current_bufferらしい?

https://github.com/prompt-toolkit/python-prompt-toolkit/blob/master/prompt_toolkit/application/application.py#L306

    @property
    def current_buffer(self):
        """
        The currently focused :class:`~.Buffer`.

        (This returns a dummy :class:`.Buffer` when none of the actual buffers
        has the focus. In this case, it's really not practical to check for
        `None` values or catch exceptions every time.)
        """
        return self.layout.current_buffer or Buffer(name='dummy-buffer')  # Dummy buffer.

あれか、起動する時にapp = Application(layout=xxxx)ってやったときのやつが取得できるってことか!!

また、特定のウィンドウにフォーカスがあうかどうかとかはhas_focusを使う