Results 1 to 8 of 8

Thread: GIMP Invalid Syntax Error - Problems with image Filepath?

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1

    Default GIMP Invalid Syntax Error - Problems with image Filepath?

    So I'm not familiar with python at all, and am trying to run a script (Charerg's Climate Generator to be precise) from the python console in GIMP so I can figure out why the script crashes. However, for some reason I cannot run the dang thing, and it appears my familiarity with MATLAB and Java isn't helpful at all. Here's the original script as summoned from the browser:
    pdb.python_fu_climate_generator(img)

    I replace img with the filepath, as such:
    pdb.python_fu_climate_generator(D:\Documents\Legen darium\Map\World Map (v2)\suru backup.xcf)

    And get the following error:
    syntax error.PNG

    I would've thought that entering the absolute filepath without any modification would get it to work, but it seems my lack of understanding python is problematic, as the script is able to run fine when called from Gimp's application window. While I know something is wrong with how I'm filling in the "img" slot, I'm not quite sure how to properly search for it on google; what's wrong with my syntax? Help would be much appreciated.

  2. #2
    Administrator Redrobes's Avatar
    Join Date
    Dec 2007
    Location
    England
    Posts
    7,256
    Blog Entries
    8

    Default

    You could put some quotes around it. Try normal double quotes " and then try single quotes ' if that doesnt work.

    Given that is claiming a syntax error that implies its not trying to read that as a string but a command. So I bet that its just that its not quoted to make it string. When a language says something like "<input>" it means replace the <input> bit with the filename but its saying that you need double quotes around that to make it "<input>".

    One thing you also need to know is that windows directory separator is a \ but linux-unix is /.

    But in most languages the backslash is treated as a special character that means make the next character a control code. So \n is the newline character. When quoting with double quotes the backslashes mean convert character but with single quotes it usually means take what you have between them literally. So a backslash means a backslash. So you may find that even tho it reckoned you should have double quotes around it you might find single ones work better in this case.

    If it is the case that only double quotes are allowed and it doesnt like the back slashes then for every time you have a backslash then try making it a pair of backslashes. This is because in most languages the special control code of \\ is itself backslash so that you are able to specify one if you have to. I.e. it could be that you need to put

    climate_generator( "D:\\Documents\\Legendarium\\ ... etc " )

    And... you might find that the spaces in the filename need a backslash. I.e. when it says "World Map" you put in "World\ Map".

    Try a selection of those hints. Python will probably do the whole thing correctly with a set of single ' quotes ' .
    Last edited by Redrobes; 10-26-2020 at 02:29 PM.

  3. #3

    Default

    Doing so (both with and without the .xcf in case that mattered) resulted in a "wrong parameter type" error.

    Inputs:
    pdb.python_fu_climate_generator("D:\Documents\Lege ndarium\Map\World Map (v2)\suru backup.xcf")
    pdb.python_fu_climate_generator('D:\Documents\Lege ndarium\Map\World Map (v2)\suru backup.xcf')
    pdb.python_fu_climate_generator("D:\Documents\Lege ndarium\Map\World Map (v2)\suru backup")
    pdb.python_fu_climate_generator('D:\Documents\Lege ndarium\Map\World Map (v2)\suru backup')

  4. #4
    Administrator Redrobes's Avatar
    Join Date
    Dec 2007
    Location
    England
    Posts
    7,256
    Blog Entries
    8

    Default

    Hi, just been checking... python appears to be a bit non standard in its string processing (typical !).

    try double quoting the filename but put a r in front of the first quote. I.e.

    pdb.python_fu_climate_generator( r"D:\Documents\Lege ndarium\Map\World Map (v2)\suru backup.xcf" )


    EDIT: BTW, can you post a link to this climate generator. I cant seem to find it with google etc. I am wondering what the parameter is supposed to take.
    Last edited by Redrobes; 10-26-2020 at 02:41 PM.

  5. #5

    Default

    I tried it with the r in front, but still no dice - TypeError: wrong parameter type

    Here's the link to the post

  6. #6
    Administrator Redrobes's Avatar
    Join Date
    Dec 2007
    Location
    England
    Posts
    7,256
    Blog Entries
    8

    Default

    Ahh, right now looking at the script I can see that its expecting an open image which is what is being passed to the function. That image type is defined in the documentaion here:

    https://www.gimp.org/docs/python/#IMAGE-OBJECT

    It appears that you have to load the image from a file which will assign it to an image object.

    https://stackoverflow.com/questions/...gimp-file-load

    I.e. its reckoning that you need a line like this:
    img = pdb.gimp_file_load(fname, fname, run_mode=gimpfu.RUN_NONINTERACTIVE)

    So I think in your case you need:

    fname = r"D:\Documents\Lege ndarium\Map\World Map (v2)\suru backup.xcf"
    img = pdb.gimp_file_load(fname, fname, run_mode=gimpfu.RUN_NONINTERACTIVE)
    pdb.python_fu_climate_generator( img )

    If this doesnt work then I am out of ideas having not done a lot of python nor having ever done gimp python-fu.

  7. #7

    Default

    Thank you for your help - that actually got it to start running. Granted, it still crashed, but at least I was able to get it to run.

  8. #8
    Administrator Redrobes's Avatar
    Join Date
    Dec 2007
    Location
    England
    Posts
    7,256
    Blog Entries
    8

    Default

    Glad that worked out for you. It was a bit of a guess but at least now you can work out the details.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •