Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow system plugins to customize stroke display #1658

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

lynn
Copy link
Contributor

@lynn lynn commented Feb 5, 2024

Summary of changes

System definitions/plugins can now define a function display, which is used to render outlines in the UI (suggestions, lookup, dictionary view, etc).

For example, if I look up Lynn instead of seeing the suggestion 4R*EU7B I might want to see #HR*EUPB or even #L*IN. When adding or editing outlines, the underlying syntax is still used, so that this is a purely cosmetic change.

Here is an example of a system plugin that defines display to restore letters from digits, as may please users of Lapwing theory, which uses # for proper nouns.

# english_stenotype_no_digits.py

from plover.system.english_stenotype import *

UNDIGIT_TABLE = str.maketrans('1234506789', 'STPHAOFPLT')

def display_stroke(stroke):
    undigit = stroke.translate(UNDIGIT_TABLE)
    return stroke if stroke == undigit else '#' + undigit

def display(strokes):
    return '/'.join(map(display_stroke, strokes))

Note

This example shows that this isn't quite the right abstraction: English Stenotype and English Stenotype (display lowercase) are not really two different steno systems. But tying the display function to the system keeps things architecturally simple. This way, display functions can be distributed as system plugins (instead of having to invent some new plugin type just for this niche feature), and power users can just edit the display definition in their english_stenotype.py if they so desire.

Pull Request Checklist

  • Changes have tests
  • News fragment added in news.d. See documentation for details

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant