Not bad, but:
Technical :
- Your code is missing a "Shebang" that identifies it as
Python (for those folks on Linux and OSX). The first line should be:
- Your registration should have an explicit PF_IMAGE parameter (and then you drop the useless "drawable" parameter in the function definition)
[
(PF_IMAGE, 'image', 'Input image', None),
(PF_INT, "int_Hor_Guide_Cnt", "Number of Horizontal Sections", 0),
(PF_INT, "int_Vert_Guide_Cnt", "Number of Verticle Sections", 0)
],
- You are using a deprecated menu registration method, current method has a specific named parameter to specify the menu. In addition the current trend is to avoid adding items in the already busy image menu bar. Put your code with the other guide-related menus:
"April 2020",
"Custom Guides",
"*",
[
(PF_INT, "int_Hor_Guide_Cnt", "Number of Horizontal Sections", 0),
(PF_INT, "int_Vert_Guide_Cnt", "Number of Verticle Sections", 0)
],
[],
void_create_custom_guides,
menu='<image>/Image/Guides/'
- Your description field is a bit misleading since the entered count applies to the number of sections not the number of guides
- You don't need the "from inspect import trace"
- You should bracket the function body between image.undo_group_start() and image.undo_group_end() so that the effect of your plugin can be undone with a single Ctr-Z (otherwise it is on Ctrl-Z per added guide).
- Your script crashes with en entry count of 0 (and does weird things with negative values).In practice your smaller entry is 1 (which also happens to be a valid value for which no guide is added), you can have the check done for you using a spinner (PF_SPINNER) instead of a free entry field (PF_INT):
(PF_SPINNER, "int_Hor_Guide_Cnt", "Number of Horizontal Sections", 1, (1,100, 1)),
Coding:
-
Hungarian notation is really outmoded, and when used with snake_case is a complete eyesore (I won't even mention your attempts at a novel snake_And_Camel_Case). And if you do it, at least do it fully, you missed out a gimp_image_image and a gimp_drawable_drawable
.
- Copying a variable into a variable when neither changes is pointless (int_image_width/int_image_height)
- You can easily avoid a pair of variables:
int_hguide = int_horz_space
for cnt in range( 1, int_Hor_Guide_Cnt ):
pdb.gimp_image_add_hguide( image, int_hguide )
int_hguide += int_horz_space
v.s.
for cnt in range( 1, int_Hor_Guide_Cnt ):
pdb.gimp_image_add_hguide( image, int_horz_space*cnt )
but in a more pythonic way you would just let
Python iterate the positions:
for guidePos in range( int_Hor_Guide_Cnt,image.width,int_Hor_Guide_Cnt ):
pdb.gimp_image_add_hguide( image, guidePos)
Finally, it's all fine and dandy until the number of sections doesn't divide the image width/height, so you have to either not do it, or use some more complex code to try to spread the excess/missing pixels across some sections so that the end result still looks good.
Welcome to the club