Skip to content

Make it possible to ask user for multiple choices (Python) - #4143

Merged
ctrlcctrlv merged 5 commits into
fontforge:masterfrom
ctrlcctrlv:pyMultipleChoices
Feb 9, 2020
Merged

ctrlcctrlv merged 5 commits into
fontforge:masterfrom
ctrlcctrlv:pyMultipleChoices

Conversation

@ctrlcctrlv

Copy link
Copy Markdown
Member

Multiple of which can be selected.

This is needed for #703, which I'm implementing as a Python script.

This is the first of two new needed APIs. The second will add a new
function that works on fontforge.glyph objects, similar to build,
but will instead take a combining class type and place an anchor.

For easier testing, the script below may be used:

import fontforge

AnchorLocations = (
    ["Above", 0x100],
    ["Below", 0x200],
    ["Overstrike", 0x400],
    ["Left", 0x800],
    ["Right", 0x1000],
    ["Joins2", 0x2000],
    ["Center-left", 0x4000],
    ["Center-right", 0x8000],
    ["Centered outside", 0x10000],
    ["Outside", 0x20000],
    ["Left edge", 0x80000],
    ["Right edge", 0x40000],
    ["Touching", 0x100000]
)


def guess_anchors(data, font):
    al_strings = tuple([x[0] for x in AnchorLocations])
    print(al_strings)
    r=fontforge.askChoices("Anchor types", "What anchor type?", al_strings)
                         #tuple([True for i in range(len(al_strings))]), True)
    print(r)
    print(data, font)


pr = {}

fontforge.registerMenuItem(guess_anchors, None, pr, "Font", None,
                           "Guess Appropriate Anchors")

Type of change

  • New feature

Multiple of which can be selected.

This is needed for fontforge#703, which I'm implementing as a Python script.

This is the first of two new needed APIs. The second will add a new
function that works on `fontforge.glyph` objects, similar to `build`,
but will instead take a combining class type and place an anchor.
@ctrlcctrlv
ctrlcctrlv requested a review from skef February 8, 2020 10:59
@skef

skef commented Feb 8, 2020

Copy link
Copy Markdown
Contributor

I'm happy to review this and strongly approve of the change.

I'm going to start with an optional suggestion, which is that now that we have two optional arguments it would be good to throw some keywords onto them so that they can be specified either by position or by keyword. It's entirely backward compatible with the existing interface and not much more work -- the current PyFFFont_autoWidth() provides a good model of the semantic.

Comment thread fontforge/python.c Resolved
Comment thread fontforge/python.c Resolved
Comment thread fontforge/python.c Resolved
Comment thread fontforge/python.c Resolved
Comment thread fontforge/python.c Resolved
@jtanx

jtanx commented Feb 8, 2020

Copy link
Copy Markdown
Contributor

I'm going to start with an optional suggestion, which is that now that we have two optional arguments it would be good to throw some keywords onto them so that they can be specified either by position or by keyword. It's entirely backward compatible with the existing interface and not much more work -- the current PyFFFont_autoWidth() provides a good model of the semantic.

100% agree with this, something that's been irking me is how we overload the signature of various functions, such that which positional arguments are valid depend on the context - something which you would almost never do if you were to write the interface in pure Python.

@ctrlcctrlv
ctrlcctrlv requested a review from skef February 9, 2020 07:24

@skef skef left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is very close.

Comment thread fontforge/python.c Resolved
Comment thread doc/html/python.html Resolved
@ctrlcctrlv ctrlcctrlv mentioned this pull request Feb 9, 2020

@skef skef left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good, approved.

@ctrlcctrlv
ctrlcctrlv merged commit 512c82c into fontforge:master Feb 9, 2020
Omnikron13 pushed a commit to Omnikron13/fontforge that referenced this pull request May 31, 2022
…#4143)

Multiple of which can be selected.

This is needed for fontforge#703, which I'm implementing as a Python script.

This is the first of two new needed APIs. The second will add a new
function that works on `fontforge.glyph` objects, similar to `build`,
but will instead take a combining class type and place an anchor.
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.

4 participants