Gimp-Forum.net
Test for missing data entry - Printable Version

+- Gimp-Forum.net (https://www.gimp-forum.net)
+-- Forum: GIMP (https://www.gimp-forum.net/Forum-GIMP)
+--- Forum: Extending the GIMP (https://www.gimp-forum.net/Forum-Extending-the-GIMP)
+---- Forum: Scripting questions (https://www.gimp-forum.net/Forum-Scripting-questions)
+---- Thread: Test for missing data entry (/Thread-Test-for-missing-data-entry)



Test for missing data entry - david - 12-20-2024

Another of my stupid questions!!!

In my website photos plug-in, if I test for missing data input, how do I get it to print only my gimp message and exit.

I have been searching for this all day and tried numerous things without success.
Most of the things I have tried add additional error messages.

David.


RE: Test for missing data entry - teapot - 12-20-2024

If you make a variable, say called err, that's a string containing an error message you can do this near the start of your python_website_photos1 function:

Code:
    if err:
        pdb.gimp_message(err)
        return

The return stops your plugin from running.

Or perhaps you could have the error messages in a list, say called all_err, of strings. Then you could do:

Code:
    if all_err:
        pdb.gimp_message('\n'.join(all_err))
        return

You could try this in gimp's python console:
Filters -> Python-Fu -> Console

Code:
all_err = ['abc', 'def', 'ghi']
pdb.gimp_message('\n'.join(all_err))

You should get this:

[attachment=12823]


RE: Test for missing data entry - Ofnuts - 12-20-2024

(12-20-2024, 05:17 PM)david Wrote: Another of my stupid questions!!!

In my website photos plug-in, if I test for missing data input, how do I get it to print only my gimp message and exit.

I have been searching for this all day and tried numerous things without success.
Most of the things I have tried add additional error messages.

David.

If you exit properly there shouldn't be any. My plugins are usually architected like this:

Code:
import traceback

def pluginImplementation(image,etc...):

    image.undo_group_start() # so that whatever happens, only one single Ctrl-Z to revert
    gimp.context_push() # if the code alters the context, otherwise omitted
    
    try: # start Try/except block
    
        # implementation code goes here. Can call functions
        
        if some_error_case:
            raise Exception('This message will be displayed to the user')
        
        # some more implmentation code
        
    except Exception as e: # catch any exception raised by the code
        pdb.gimp_message(e.args[0]) # Error message to the user
        print traceback.format_exc() # Traceback to terminal for developper
        
    gimp.context_pop() # if there was a push() at the top
    image.undo_group_end() # close the undo group (done whatever happened before, error or success)