Skip to content

Comments

Graphical Modeler: fix UI produced by Python export#3373

Closed
landam wants to merge 1 commit intoOSGeo:mainfrom
landam:gmodeler_fix_ui
Closed

Graphical Modeler: fix UI produced by Python export#3373
landam wants to merge 1 commit intoOSGeo:mainfrom
landam:gmodeler_fix_ui

Conversation

@landam
Copy link
Member

@landam landam commented Jan 24, 2024

Python scripts generated by Graphical Modeler (Python editor -> Save As) contain broken UI definition. Sample model attached:
buffer.gxm.zip

# %module
# % description: Script generated by wxGUI Graphical Modeler.
# %end
...

Extra space between # and % causes that GConsole skips interface completely: https://github.com/OSGeo/grass/blob/main/gui/wxpython/core/gconsole.py#L641

Screencast.from.2024-01-24.14-37-48.webm

The PR fixes this bug:

Screencast.from.2024-01-24.14-45-45.webm

@landam landam requested a review from pesekon2 January 24, 2024 13:49
@github-actions github-actions bot added GUI wxGUI related Python Related code is in Python labels Jan 24, 2024
@landam landam self-assigned this Jan 24, 2024
@landam landam added the bug Something isn't working label Jan 24, 2024
@landam landam added this to the 8.4.0 milestone Jan 24, 2024
@echoix
Copy link
Member

echoix commented Jan 24, 2024

I was about to approve the changes, but I double checked the current python scripts in the repo. Why does the parser not fail with scripts in the repo, but would fail with the exported ones? See PR here when it was added #1287.

And the specific changes to g.parser's c code
https://github.com/OSGeo/grass/pull/1287/files#diff-04161dc11445b34906e6fe1ddbd8e9828238cc979d0bde765f8fb0f05f3ed8a4R106-R115

Current code for g.parser is:

line_size = strlen(buff);
if (line_size > 2 && buff[0] == '#') {
if (buff[1] == '%')
cmd = buff + 2;
else if (line_size > 3 && buff[1] == ' ' && buff[2] == '%')
cmd = buff + 3;
else
continue;
}
else {
continue;
}

Current code for gconsole.py:

skipInterface = True
if os.path.splitext(command[0])[1] in (".py", ".sh"):
try:
sfile = open(command[0], "r")
for line in sfile.readlines():
if len(line) < 2:
continue
if line[0] == "#" and line[1] == "%":
skipInterface = False
break
sfile.close()
except OSError:
pass

If its an urgent fix, this PR could go through, as it is fixing the consequence of the bug, but maybe fixing the source of the problem would be a better solution.

@landam
Copy link
Member Author

landam commented Jan 25, 2024

I was about to approve the changes, but I double checked the current python scripts in the repo. Why does the parser not fail with scripts in the repo, but would fail with the exported ones? See PR here when it was added #1287.

you are right, I was not aware of #1287.

If its an urgent fix, this PR could go through, as it is fixing the consequence of the bug, but maybe fixing the source of the problem would be a better solution.

This PR is replaced by #3375

@landam landam closed this Jan 25, 2024
@landam landam deleted the gmodeler_fix_ui branch January 25, 2024 08:15
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working GUI wxGUI related Python Related code is in Python

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants