Macro editor seems to show line numbers modulo 100000

Need help, or want to share a macro? Post here!
Forum rules
Be nice to others! Respect the FreeCAD code of conduct!
Post Reply
aleph0
Posts: 43
Joined: Fri Jan 29, 2016 10:04 am
Location: Cambridge, England
Contact:

Macro editor seems to show line numbers modulo 100000

Post by aleph0 »

FreeCAD's macro editor seems to truncate line numbers to 5 digits, printing them modulo 100000. This explains the fact that puzzled me, at least, that in an earlier post I seemed to be creating about 200,000 facets with only about 97,000 lines of macro code which consisted almost entirely of top-level (not in a loop or function) calls to facets.append(Part.Face(Part.makePolygon(...). Actually I had a lot more than 97,000 lines but the editor was displaying the last line number incorrectly. This was seen in FreeCAD 0.18. I did try to search this forum to see if this issue had been reported before (and possibly fixed in a later version), but the forum's search engine thinks that both "line" and "number" are words too common to search for. Screenshot shows the line number turning over from 99999 to 00000.
linenumbers.png
linenumbers.png (11.19 KiB) Viewed 595 times
User avatar
onekk
Veteran
Posts: 6149
Joined: Sat Jan 17, 2015 7:48 am
Contact:

Re: Macro editor seems to show line numbers modulo 100000

Post by onekk »

aleph0 wrote: Sun May 21, 2023 4:22 pm ...
A Macro with more than 99999 lines is obviously a non sense, python itself is advising to not exceed 2000 lines.

The point is that FreeCAD python editor is made to make simple things not full fledged programs, and is good for what is designed for.

Using 0.18.4 and reporting errorfor it is also a non sense as even if there will be a bug, it will not be fixed as it is not supported . Actually a release for 0.21 is imminent and probably a 0.20.3 bugfix release.

Regards

Carlo D.
GitHub page: https://github.com/onekk/freecad-doc.
- In deep articles on FreeCAD.
- Learning how to model with scripting.
- Various other stuffs.

Blog: https://okkmkblog.wordpress.com/
User avatar
chennes
Veteran
Posts: 3884
Joined: Fri Dec 23, 2016 3:38 pm
Location: Norman, OK, USA
Contact:

Re: Macro editor seems to show line numbers modulo 100000

Post by chennes »

The width of the line number area is hard-coded to:

Code: Select all

QtTools::horizontalAdvance(fontMetrics(), QLatin1String("0000")) + 10;
in TextEdit.cpp (that is, the width of the four zeros, plus ten points). Numbers are shown right-aligned, so you're generally only going to be able to see the last five or so digits. The use-case here, where the "macro" appears to itself be programmatically-generated (and is extremely long), was not anticipated. Fixing this would mean dynamically resizing the line number area width based on the number of lines in the file: not impossible, and maybe a good project for someone who is looking for an introduction to the FreeCAD codebase.
Chris Hennes
Pioneer Library System
GitHub profile, LinkedIn profile, chrishennes.com
TheMarkster
Veteran
Posts: 5505
Joined: Thu Apr 05, 2018 1:53 am

Re: Macro editor seems to show line numbers modulo 100000

Post by TheMarkster »

chennes wrote: Mon May 22, 2023 2:15 am The width of the line number area is hard-coded to:

Code: Select all

QtTools::horizontalAdvance(fontMetrics(), QLatin1String("0000")) + 10;
in TextEdit.cpp (that is, the width of the four zeros, plus ten points). Numbers are shown right-aligned, so you're generally only going to be able to see the last five or so digits. The use-case here, where the "macro" appears to itself be programmatically-generated (and is extremely long), was not anticipated. Fixing this would mean dynamically resizing the line number area width based on the number of lines in the file: not impossible, and maybe a good project for someone who is looking for an introduction to the FreeCAD codebase.
A trivial fix would be to just change the hard-coding from 4 to 5 digits. I don't think it would be such an inconvenience to have that column one character wider.
Post Reply