PyGimp;Change color;Bucket fill selected - 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: PyGimp;Change color;Bucket fill selected (/Thread-PyGimp-Change-color-Bucket-fill-selected) |
PyGimp;Change color;Bucket fill selected - FloppaDisk - 03-15-2020 Hi. Trying to change the color of the bucket fill function in python gimp, but due to my inexperience with python and the structure between gimp and python i have not been successful. Information im looking for is: How to swap the pre-selected colors How to set new color How to fill and selected area How to select and area All of which needs to take place in pyGimp The bellow code is what i have so far, but the result is what i expect. Expected result should be an grid (almost like a chess board) where pyGimp color individual squares in one of the two colors (foreground and background) #Select and square pdb.gimp_rect_select(img, gPosX+pX, gPosY+pY, wid, hig, CHANNEL_OP_REPLACE, False, 0.0) #Fill the square draw.fill(FILL_FOREGROUND) RE: PyGimp;Change color;Bucket fill selected - Ofnuts - 03-15-2020 What you want is: Code: ➤> pdb.gimp_image_select_rectangle(img, CHANNEL_OP_REPLACE, gPosX+pX, gPosY+pY, wid, hig) To recap the various fill options, you can/should currently use:
Avoid using gimp_edit_bucket_fill, gimp_edit_bucket_fill_full, gimp_drawable_edit_fill, and gimp_bucket_fill that are deprecated. RE: PyGimp;Change color;Bucket fill selected - Ofnuts - 03-15-2020 For the colors: To swap FG/BG colors use gimp_context_swap_colors To set a given color you need the help of the gimpcolor module: Code: import gimpcolor Note that in these calls/constructors, when you use integers they are understood to be in the 0-255 range (or 0-360 for hues) and when you use floats they are understood as values in the 0.0-1.0 range. gimpcolors has several color definitions (RHB, HSV, HSL, CYMK) but the Gimp API wants the RGB type (hence the to_rgb() method on most). Since you change the context, you should normally restore it before exiting the script, this is done by bracketing your script code between gimp_context_push() and gimp_context_pop(). In practice to make sure that this happens you also bracket your code with a try/catch and restore the context after you have caught any exception. And while you are at it you can also bracket your code with undo markers so that you can undo all the script actions with a single Ctrl-Z. The problem with catching the exception is that it masks errors and makes debugging difficult but you can retrieve the exception information to display it, so your plugin code becomes: Code: import traceback Or if you prefer the lighter form with Gimp objects: Code: import traceback |