PR #6408 - Addon manager: Auto-add Macro toolbar button

Post here if you have re-based and finalised code to integrate into master, which was discussed, agreed to and tested in other forums. You can also submit your PR directly on github.
Forum rules
Be nice to others! Respect the FreeCAD code of conduct!
User avatar
chennes
Veteran
Posts: 3876
Joined: Fri Dec 23, 2016 3:38 pm
Location: Norman, OK, USA
Contact:

PR #6408 - Addon manager: Auto-add Macro toolbar button

Post by chennes »

By popular request, this last major feature addition to the Addon Manager will hopefully (barring any unforeseen explosions) be incorporated into the 0.20 release. From the PR:
The main work of this commit is to add a workflow following the installation of a new macro that asks if you would like to add this macro to a toolbar. The exact behavior will depend on whether you already have custom toolbars or not: if you do, then you'll be prompted as to whether you want to install the button in one of them, or to create a new toolbar. If you don't have any custom toolbars this is skipped, and one is automatically created. If the macro provides an icon, that is used in the toolbar. If not, the current behavior is to display the name of the macro. I am evaluating whether auto-creation of an icon is feasible/desirable, and welcome your comments in this regard.

Several other minor changes to macro installation behavior are also implemented in support of this new feature: most notably, two additional methods for supplying the macros' icon are implemented. First, it was noted that several macros attempted to use an online URL for their icon, even though this was not supported. Now, if an http or https link is provided for the __icon__ field, that file is downloaded and used as the macro's icon both in the Addon Manager and when installed to a toolbar. Second, if either __icon__ or __xpm__ contain a triple-quoted string, that string is treated as XPM data and written into a *.xpm file. If the data results in a valid XPM-formatted icon, that icon is then used both in the Addon Manager and in toolbars as the icon for that macro. Note that this data must be triple-quoted, and triple quotes are explicitly disallowed for any other metadata fields.
Chris Hennes
Pioneer Library System
GitHub profile, LinkedIn profile, chrishennes.com
kisolre
Veteran
Posts: 4162
Joined: Wed Nov 21, 2018 1:13 pm

Re: PR #6408 - Addon manager: Auto-add Macro toolbar button

Post by kisolre »

On adding Bevel macro its icon is not added to the toolbar. Just the name.
User avatar
chennes
Veteran
Posts: 3876
Joined: Fri Dec 23, 2016 3:38 pm
Location: Norman, OK, USA
Contact:

Re: PR #6408 - Addon manager: Auto-add Macro toolbar button

Post by chennes »

kisolre wrote: Mon Feb 21, 2022 11:31 am On adding Bevel macro
I don't see a version of the Bevel macro with an __icon__ specification -- do you have a link?
Chris Hennes
Pioneer Library System
GitHub profile, LinkedIn profile, chrishennes.com
kisolre
Veteran
Posts: 4162
Joined: Wed Nov 21, 2018 1:13 pm

Re: PR #6408 - Addon manager: Auto-add Macro toolbar button

Post by kisolre »

chennes wrote: Mon Feb 21, 2022 3:47 pm do you have a link?
Maybe I was expecting too much and did not properly read the PR message. Since there is an icon in on the macro Wiki page I assumed that this can be used somehow.
User avatar
chennes
Veteran
Posts: 3876
Joined: Fri Dec 23, 2016 3:38 pm
Location: Norman, OK, USA
Contact:

Re: PR #6408 - Addon manager: Auto-add Macro toolbar button

Post by chennes »

It is now possible to use those icons, but the macro author has to actually set it in the __icon__ metadata.
Chris Hennes
Pioneer Library System
GitHub profile, LinkedIn profile, chrishennes.com
User avatar
Kunda1
Veteran
Posts: 13434
Joined: Thu Jan 05, 2017 9:03 pm

Re: PR #6408 - Addon manager: Auto-add Macro toolbar button

Post by Kunda1 »

mario52 wrote:
CC @mario52
CC @galou_breizh
Alone you go faster. Together we go farther
Please mark thread [Solved]
Want to contribute back to FC? Checkout:
'good first issues' | Open TODOs and FIXMEs | How to Help FreeCAD | How to report Bugs
User avatar
chennes
Veteran
Posts: 3876
Joined: Fri Dec 23, 2016 3:38 pm
Location: Norman, OK, USA
Contact:

Re: PR #6408 - Addon manager: Auto-add Macro toolbar button

Post by chennes »

kisolre wrote: Mon Feb 21, 2022 4:03 pm Since there is an icon in on the macro Wiki page I assumed that this can be used somehow.
OK, I've tweaked the PR to try to parse the wiki page for those images. It's slower than if the macro specified __icon__ directly, but I think it's still a useful bit of code. That said, I think we should encourage macro authors to use the metadata so we can avoid the page scraping parser.
Chris Hennes
Pioneer Library System
GitHub profile, LinkedIn profile, chrishennes.com
kisolre
Veteran
Posts: 4162
Joined: Wed Nov 21, 2018 1:13 pm

Re: PR #6408 - Addon manager: Auto-add Macro toolbar button

Post by kisolre »

chennes wrote: Mon Feb 21, 2022 8:17 pm That said, I think we should encourage macro authors to use the metadata so we can avoid the page scraping parser.
+10 :) I hope that there is a guide for that.
But for the bunch of old working macros expecting all the authors to be active and follow changes is unreasonable IMO.
User avatar
chennes
Veteran
Posts: 3876
Joined: Fri Dec 23, 2016 3:38 pm
Location: Norman, OK, USA
Contact:

Re: PR #6408 - Addon manager: Auto-add Macro toolbar button

Post by chennes »

kisolre wrote: Mon Feb 21, 2022 8:27 pm expecting all the authors to be active and follow changes is unreasonable IMO.
Yes, absolutely -- my only concern is for "copy-and-paste" coding. I don't want new macro writers to see that this works for old macros, and decide to just do it that way. But the benefit to end users is large, so I think it's worth the small extra parsing time.
Chris Hennes
Pioneer Library System
GitHub profile, LinkedIn profile, chrishennes.com
User avatar
chennes
Veteran
Posts: 3876
Joined: Fri Dec 23, 2016 3:38 pm
Location: Norman, OK, USA
Contact:

Re: PR #6408 - Addon manager: Auto-add Macro toolbar button

Post by chennes »

Just for the record, the new macro icon parsing behavior is this:

First, if the macro is downloaded from the git macro repository and __icon__ is a relative path, that icon path is installed along with the macro. It is not necessary to include the icon file in the __files__ list, it is handled automatically. This is the fastest and simplest method, and preferred for macros hosted on git.

The next steps apply regardless of where the macro is hosted:

If an http or https link is provided for the __icon__ field, that file is downloaded and used as the macro's icon both in the Addon Manager and when installed to a toolbar. The icon's name is used as-is from the URL, and the file itself is placed directly alongside the macro in the user's macro directory, ignoring the rest of the URL path. The Addon Manager does not attempt to disambiguate names: care should be taken to avoid name collisions (e.g. don't call your icon "icon.svg", etc.).

Next, if either __icon__ or __xpm__ contain a triple-quoted string, that string is treated as XPM data and written into a *.xpm file. If the data results in a valid XPM-formatted icon, that icon is then used both in the Addon Manager and in toolbars as the icon for that macro. Note that this data must be triple-quoted, and triple quotes are explicitly disallowed for any other metadata fields.

Finally, if no data has been found by the preceding steps, and the macro is fetched from the Wiki, a pair of heuristic parsing functions are used in an attempt to download an icon for the macro from its wiki page. The first function is straightforward, and seeks links of the following form:

Code: Select all

<a href="https://www.freecadweb.org/wiki/images/f/f5/Macro_3D_Parametric_Curve.png">ToolBar Icon</a>
If that is a link directly to a file, that file is used as the macro's icon. In most cases this works correctly, but in some cases rather than providing a direct link to the icon file, the link is instead a wiki "File:" link, which does not provide direct access to the icon. If that is the case, the link is followed, and the resulting wiki page downloaded and parsed for the text fullImageLink -- the first <img> tag following that trigger text is used as the macro's icon. This is significantly slower and more fragile than if the macro specifies a path directly to the image, but a non-trivial number of macros use File: links instead of direct image links, so this is provided as a final fallback.
Chris Hennes
Pioneer Library System
GitHub profile, LinkedIn profile, chrishennes.com
Post Reply