Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Validating data entry
#1
I have been updating my website_photos1.py plug-in to make it more useful and also as part of my learning exercise.

Is it possible to validate that "Sub Directory" and "New Name" have been entered and if not return the user to the entry screen?
I have been searching for several days to find an example of code to do this, without success.

An additional query: How to put additional lines of text or separators in the UI of a plug-in in order to make it more readable or give explanation.


.zip   website_photos1.zip (Size: 2.96 KB / Downloads: 36)

David.


Attached Files Image(s)
   
Reply
#2
No to both if you are using the auto-generated UI. You can write your own dialog (especially here since you don't need the Gimp widgets) but it is somewhat more complicated. Then you can make it look like you want and perform the checks you want (typically, you disable the OK button as long as you haven't got everything filled correctly).

Otherwise my usual way to deal with the situation is to initialize the fields with sensible defaults and if they are empty (which requires some user effort) to reuse the defaults. Nice UIs are fine, but in such scripts handling the UI quickly becomes the most important part of the code.
Reply
#3
(12-19-2024, 12:40 PM)Ofnuts Wrote: No to both if you are using the auto-generated UI. You can write your own dialog (especially here since you don't need the Gimp widgets) but it is somewhat more complicated. Then you can make it look like you want and perform the checks you want (typically, you disable the OK button as long as you haven't got everything filled correctly).

Otherwise my usual way to deal with the situation is to initialize the fields with sensible defaults and if they are empty (which requires some user effort) to reuse the defaults. Nice UIs are fine, but in such scripts handling the UI  quickly becomes the most important part of the code.

Ofnuts,

Thanks for the reply.

David.
Reply
#4
Hi David,

I work around the restrictions.

For your first issue: The first thing my plugins do is check the values from the dialog box, collect any errors and if any report them all in one gimp message. Then if there were any errors the plugin returns before it's done any work.  It's up the the user to run the plugin again, e.g. use Filters -> Repeat 'My plugin' and correct the data they entered.

For your second issue: I include \n in the dialog box text and put in more text or a mini fake separator with underscores.

If a dialog box is going to contain long names I put some unbreakable spaces at the end of the the short blurb to force the dialog box to be wider.

For example here's what a dialog box would look like:

   

with this code:

Code:
# To make the dialog box wider.
short_blurb_wider = u'\u00a0' * 100

# To indicate sections in the dialog box.
divider = '\n' + '_' * 40

# To make the message box wider to lessen messages wrapping.
message_box_wider = '\n' + u'\u00a0' * 130

short_blurb = '''Website Photos1
''' + short_blurb_wider

register(
    "python_website_photos1",
    short_blurb,
    "Website Photos1",
    "David Marsden",
    "David Marsden",
    "November 2024",
    "<Image>/Python-Fu/Website Photos1...",
    "RGB*, GRAY*",
    [
        (PF_DIRNAME, "outputFolder", "Output directory", "Desktop"),
        (PF_STRING, "subDir", "Sub Directory", "/blah/gimp-rocks/a-really-long-name-fits", 0),
        (PF_STRING, "nName", "New Name" + divider, "fred", 0),
        (PF_TOGGLE, "large", "Large means really\nreally big, if not bigger\nor perhaps longer.", 1),
        (PF_TOGGLE, "small", "Small needs more\ninformation here.", 1),
        (PF_TOGGLE, "thumbnail", "Thumbnail" + divider, 1),
        (PF_SPINNER, "maxdimL", "Large Max. Dimension", 900, (600, 1200, 1)),
        (PF_SPINNER, "maxdimS", "T'nail Max. Dimension", 200, (100, 300, 1)),
    ],
    [],
    python_website_photos1)
Reply
#5
teapot,

Many thanks for your reply and the valuable suggestions.

David.
Reply


Forum Jump: