Python menu extension

Issue #21 resolved
Georg Mayr-Duffner created an issue

In the announcement mail from december it was suggested to use a user_init.py file for this task. I found this: http://pastebin.com/ji2VRFrL, changed all sortsmillff to sortsmill and register_fontforge_menu_item to register_fontforge_menu_entry and saved it in ~/.config/sortsmill-tools but no menu item appeared. Did I miss something?

Comments (11)

  1. Barry Schwartz

    You now have to follow the directions in guile/sortsmill/python.scm to use the Python API. Otherwise user_init.py is not loaded.

    The details of the interface may also change, although old FF style menu entries should work.

    It’s also possible to add menu entries directly in user-init.scm. Again, the details of the interface may change, and are not documented, but it does let one actually design a menu tree directly as a tree. :)

  2. Barry Schwartz

    (Some may object I am making things hard, but sites and distros can simply activate Python in the /etc configuration if they want.)

  3. Georg Mayr-Duffner reporter

    No problem, as long as it’s just about putting a file in a certain place ;)

    I tried again now with above mentioned file, but I have a doubt: there is a cascade of submenues like this: P→y→t→h→o→… all the way through the letters of 'Python entry' in this line:

    menu_path = 'Python entry',
    

    This is not what I’d expect when I compare it with the output of the following line which is simply submenu→Python entry:

    menu_path = ['submenu','Python entry'],
    

    I tried to find a clue in usermenu.scm—without success (which doesn’t mean anything).

  4. Georg Mayr-Duffner reporter

    It’s still the same, I don’t think this behaviour is intended. See this picture: georgduffner.at/diverses/menuentry.png

  5. Barry Schwartz

    I haven’t looked at it yet but do want to say that this looks like an example of what I dislike about Python. You make a small error and instead of indexing through the elements of a list you are indexing through the characters of a string. What you should be seeing is either a compiler error or, at least, an exception.

    The creators of Python thought they were being clever by letting the same operation do dozens of different things depending on the type handed to it, but what I see is software whose behavior is extremely difficult to control or test. It is better for the program to quit working than for it to do the wrong thing.

  6. Barry Schwartz

    This is where the error is going to be (in usermenu/python.scm):

              [menu-path-® (map pystring->string (pysequence->list menu-path^))]
    

    I want to get that on record so I can make a fool of myself when that turns out not to be it. :)

    It’s going to be the ‘pysequence->list’ procedure, or more precisely the existence of such a thing as a ‘PySequence’. I would have to put in all kinds of explicit type checking if I wanted to make this halfway safe, but probably I’ll just check for the special case of a string argument.

  7. Log in to comment