gotcha

Author Topic: Extensions - using shared preferences  (Read 1900 times)

December 26, 2017, 02:09:22 PM
Read 1900 times

MartyMacGyver

  • Sr. Newbie

  • Offline
  • **

  • 4
Background: I am working with a Python extension that sets persistent options for itself. For expedience I want to call that extension from other extension description files. However, it seems that preferences are keyed by the unique `id` of the extension description file, thus ext1.inx cannot see the preferences of ext2.inx (even if they both call into the same exact script). The goal is to decompose access to some frequently-used functions currently housed in a "notebook" with several tabs into one-click extensions (removing the need to click, select a tab, perhaps select a dropdown and finally apply a simple operation).

Some of the functions are already amenable to this - but others depend on user options originally set from the notebook itself (the script for which contains all the functionality) for proper operation, and cannot get to those options from their scope.

How would one accomplish this concept of shared preferences within the existing Inkscape framework? I'd prefer not to access the preferences file directly but will do so if there is no other way forward... I'd hope there might be some way to walk the options tree but it's not clear if there's any way to access the parent of the `options` branch that the extension gets on execution.
  • 0.92.2 (x64)
  • Windows 7, OSX 10.13+

December 26, 2017, 10:36:55 PM
Reply #1

brynn

  • Administrator

  • Offline
  • ******

  • 3,941
  • Gender
    Female

    Female
    • Inkscape Community
Welcome to the forum!

I actually can't answer your questions, since writing extensions is over my head.  We do have a member who might be able to help.  I haven't seen her for the last couple of days, so I'm thinking she might be away for the holiday.

If she can't help, or if you don't want to wait to find out, you can contact developers directly using the Devel mailing list: https://inkscape.org/en/community/mailing-lists/.  Possibly you could get help on the development IRC:  https://inkscape.org/en/community/discussion/

We do have a bit of a guide for writing extensions, which might answer your questions.  It's too far over my head for me to even know if the guide answers your questions.  But fwiw:  https://inkscape.org/en/develop/extensions/
  • Inkscape version 0.92.3
  • Windows 7 Pro, 64-bit
Inkscape Tutorials (and manuals)                      Inkscape Community Gallery                        Inkscape for Cutting Design                     



"Be ashamed to die until you have won some victory for humanity" - Horace Mann                       

December 26, 2017, 11:15:12 PM
Reply #2

MartyMacGyver

  • Sr. Newbie

  • Offline
  • **

  • 4
I appreciate the info! I've been delving into the extension format (as well as the Inkscape source code) to see if this can done. It seems like it should've come up before but so far I haven't found anything matching the keywords I'd expect to be involved.

I will keep an eye out for a response here, and may give the dev list or IRC a try as well if it comes to that. I suspect it's not intrinsically possible within the framework but it'd be good to know that for sure before going down other paths (like directly accessing the settings file).
  • 0.92.2 (x64)
  • Windows 7, OSX 10.13+

December 27, 2017, 09:50:33 AM
Reply #3

Moini

  • IC Mentor

  • Offline
  • ******

  • 1,568
    • VektorRascheln
So, do I understand correctly that you want to access one extension's presets (which are saved in the preferences file) from inside another extension?

I believe the extension's id in the inx file must be unique, and each extension only gets passed the saved parameters for its own id, but just like you, I've only inferred that. I think we're right, though.

You could perhaps add your own preferences file... (but this will not prefill the entry fields correctly, if it differs from the contents of the preferences file). Or read the original one, as suggested.

December 27, 2017, 12:54:46 PM
Reply #4

MartyMacGyver

  • Sr. Newbie

  • Offline
  • **

  • 4
Thanks for the reply!

To me, an extension is the code that performs the action(s) plus its menu entry point(s) (thus, several menu items might interact with the same pool of preferences). You might have one piece of backend code that handles multiple commands, which require a shared set of parameters, and which may come in from any number of menu options. Or you might have several such pieces of code, each handling its subset of preferences but requiring access to the others in its family.

Here, it seems that design pattern is inverted, with each menu item being the "extension" complete with a unique ID that identifies its preferences and *only* its preferences. While the backend code may be the single, shared script, the preferences would only be scoped to the ones based on the id of the menu item it is called from.

If there is a concept of a preference hierarchy here, I'm not seeing it so far.

There are ways around this, but they come at a cost: either one makes the sole entry point for a complex extension a notebook of panes and pulldowns (adding UI complexity), or one has several "extension" menu entries as entry points and manually manages the preferences file directly.

The latter assumes that the preferences file handle isn't held persistently open by Inkscape - and it's also not clear if the UI can be made to show preferred values on startup anyway, though in my specific case I just need to know their values at this point, as the gui is hidden for that "single click" functionality. This would be best managed within Inkscape though. Perhaps it's worth a feature request, though I'm not sure how amenable the devs would be to that.

I appreciate the input, and if there are other ideas I'm open to them as well.
  • 0.92.2 (x64)
  • Windows 7, OSX 10.13+

December 27, 2017, 02:36:37 PM
Reply #5

Moini

  • IC Mentor

  • Offline
  • ******

  • 1,568
    • VektorRascheln
Yes, one inx file = one id = one set of entries in the preferences.xml.

And yes, there could be an issue with changing preferences... Because Inkscape only saves the file at the time you quit the program. Not when you make a change, and also not when Inkscape crashes or is killed, and also, every window seems to use its own preferences copy (partially... leading to weird effects if you have two windows open and change preferences - like drawing in wrong default colors for a tool, or showing a different color in the cursor than the one you will get...), and the one that is closed last wins... So, there are already a 'couple' of issues...

There is one option that makes an extension interface completely independent from Inkscape: use your own (interface). Zenity, tkinter, python-gtk, whichever you want. Then you can load and use your own extension-specific preferences.

Unrelated, but maybe useful: There are command line options for using .noprefs for an extension (http://wiki.inkscape.org/wiki/index.php/Script_extensions#Verbs_interface_and_the_id_tag), and for using a specific preferences file (https://inkscape.org/doc/inkscape-man.html)


December 27, 2017, 03:40:57 PM
Reply #6

MartyMacGyver

  • Sr. Newbie

  • Offline
  • **

  • 4
Damn, that is a problem then, though it may explain some odd behavior I've heard about. Sounds like buggy behavior though - seems like the preferences subsystem might be due for an overhaul (there is some discussion of that at the bottom of http://wiki.inkscape.org/wiki/index.php/Preferences_subsystem, but that appears to be from several years ago). Hierarchical preferences would be a handy way to bridge existing behavior with potentially new behavior (e.g, prefs under id `foo.bar` could be inherited by `foo.bar.a` and `foo.bar.b`... or something like that.)

Do you think this is worth suggesting on the list? It's not clear how long it is between releases here, let alone how long it'd take to implement something like this, or if it'd even be welcome.

Having a fully independent interface is possible but very non-trivial. There might be a third way: mixing in an extension-specific preferences file but still using the rest of the framework as-is. It'd have the same permissions as Inkscape (or the user running it) and it can be portable.

At this point I need to see if there is a standard way to plug in custom values before a UI is drawn, without requiring the existing prefs - I think it's possible on init but I'm not positive.
  • 0.92.2 (x64)
  • Windows 7, OSX 10.13+

December 28, 2017, 05:22:51 AM
Reply #7

Moini

  • IC Mentor

  • Offline
  • ******

  • 1,568
    • VektorRascheln
There's no way to tell beforehand what devs will do :) Just try it.
I personally think it's probably not a priority thing, and might be a frightening task, as messing with prefs is... well, frightening. But you never know what sparks the interest of a dev ;-)

There's also no way to predict the date of a release. I'd guess 0.93 will be released sometime in spring 2018, or maybe late spring. After a hackfest, probably not before. But who knows. 0.93 is meant to be a version for early adopters... and 0.92 is intended to be maintained for some time in parallel, because relevant breaking changes in 0.93 are expected. 0.92 is probably not going to get any major changes.

I don't know of any way to influence the numbers/selections prefilled in the extension dialogs when you start Inkscape (other than by editing preferences.xml). My experience suggests that they are loaded from the preferences.xml, unless there aren't any entries for that extension in it yet, and then they're loaded from the inx file. You'd need to read the code or ask the devs to be sure.

December 30, 2017, 05:14:21 AM
Reply #8

brynn

  • Administrator

  • Offline
  • ******

  • 3,941
  • Gender
    Female

    Female
    • Inkscape Community
 :ot1:
You know, the old MacGyver show (can't remember what it was called - maybe it was just "MacGyver"??) sure took the sad end of a lot of jokes back in the day.  But I'll take Richard Dean Anderson any day, over the "new MacGyver".  To me, the new one is now the joke!  OMGoodness, I tried to watch the new one once, but a half hour into an hour show, and I was still looking for a plot to develop!

I don't have the technical expertise to understand what you want to do with Inkscape.  But I do understand what it means to MacGyver something!
 :ot2:

I'd say, work up some kind of hands on example for the developers to look at  - or at least as far as you can go with it, and then ask for suggestions to finish.

Good luck!
  • Inkscape version 0.92.3
  • Windows 7 Pro, 64-bit
Inkscape Tutorials (and manuals)                      Inkscape Community Gallery                        Inkscape for Cutting Design                     



"Be ashamed to die until you have won some victory for humanity" - Horace Mann                       

December 30, 2017, 07:55:57 AM
Reply #9

Moini

  • IC Mentor

  • Offline
  • ******

  • 1,568
    • VektorRascheln
Lol, I fully agree with you, Brynn :) (although one can get used to the new one... His sidekicks have worse roles to fill, though. Sometimes, I wonder why on earth those nice-looking people agreed to say those dialog lines that make them sound like total idiots... Hope they got paid well.)