Skip to content

Enable parsing symbols and os-specific string representations of keys (besides modifiers) #214

@dalthviz

Description

@dalthviz

Give that a check and I think the work at #213 partialy captures the parse_platform logic at https://github.com/napari/napari/blob/main/napari/utils/interactions.py#L312 The missing thing I would say is also being able to parse symbols from non modifier keys like enter, arrows, backspace, delete, tab, space, etc. Could it be worthy to further extend the parsing capabilities to any symbol or representation that os_symbol and os_name can return? From a quick check, maybe extending the KEYCODE_FROM_LOWERCASE_STRING dictionary could be a way to achieve this? So something like:

KEYCODE_FROM_LOWERCASE_STRING: Dict[str, KeyCode] = {
    # two special cases for assigning os-specific strings to the meta key
    'win': KeyCode.Meta,
    'cmd': KeyCode.Meta,
    # special cases for symbols and other os-specific strings
    '↵': KeyCode.Enter,
    '→': KeyCode.RightArrow,
    ...
}

Originally posted by @dalthviz in #211 (comment)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions