Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Test for missing data entry
#1
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.
Reply
#2
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:

   
Reply
#3
(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)
Reply
#4
teapot & Ofnuts,

Thanks for your help and advice.
I am now able to test for missing entries and have improved the layout of the GUI.
Also changed the field names and sub-sub-folder names to something more meaningful.

David.
Reply


Forum Jump: