Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Learn to create Python3 plugins
#6
(12-28-2021, 05:38 PM)programmer_ceds Wrote:
(12-28-2021, 11:14 AM)z-uo Wrote: Now I passed to the second point: Porting a python2 plugin to python3, but I find a problem on creating a simple transparent layer:
Code:
# ERROR add new trasparent layer
overlay_layer = Gimp.Layer.new(
                       image, 'hide_background',
                       drawable.get_width(), drawable.get_height(),
                       Gimp.ImageType, 100.0,
                       Gimp.LayerMode.NORMAL
)
overlay_layer.fill(Gimp.FillType.TRANSPARENT)
It say that image is not of type Gimp.ImageType:
Code:
File "/home/opensuse/.var/app/org.gimp.GIMP/config/GIMP/2.99/plug-ins/add_baloon/add_baloon.py", line 114, in run
   overlay_layer = Gimp.Layer.new(
TypeError: Expected a Gimp.ImageType, but got type

Why? What I do wrong?
The full code can be find here.

Code:
                   # ERROR add new trasparent layer
                   overlay_layer = Gimp.Layer.new(image, 'hide_background',
                       drawable.get_width(), drawable.get_height(),
                       Gimp.ImageType.RGBA_IMAGE, 100.0,
                       Gimp.LayerMode.NORMAL
                   )
                   result = Gimp.get_pdb().run_procedure('gimp-image-get-item-position',
                                [image,
                                 drawable])

                   position = result.index (1)

                   image.insert_layer(overlay_layer,None,position)
                   overlay_layer.fill(Gimp.FillType.TRANSPARENT)
                   break

Threw me to start with - the problem wasn't with the first parameter (image) but the fifth parameter - the image type.

You also need to insert the new layer - it isn't sufficient to just create it.

The break statement is useful (at the moment anyway) to prevent an endless loop.

There are quite a few places where balloon only has one 'L'

There are also quite a few warnings that are shown in the terminal window that should be addressed.

Happy coding :-)
Thank you for each correction! I reach to create it!
Now I find that with the following commands I have the selection bounds:
Code:
selection = image.get_selection()
flag, non_empty, x1, y1, x2, y2 = selection.bounds(image)
But how to fill that selection with the PP color (or SF color or White or any color)? Where I can find documentation for the instructions (I only found this that is for python2)?
Reply


Messages In This Thread
Learn to create Python3 plugins - by z-uo - 12-27-2021, 09:59 AM
RE: Learn to create Python3 plugins - by z-uo - 12-27-2021, 04:12 PM
RE: Learn to create Python3 plugins - by z-uo - 12-28-2021, 11:14 AM
RE: Learn to create Python3 plugins - by z-uo - 12-28-2021, 07:27 PM
RE: Learn to create Python3 plugins - by z-uo - 12-29-2021, 05:07 PM
RE: Learn to create Python3 plugins - by z-uo - 12-30-2021, 10:16 AM
RE: Learn to create Python3 plugins - by z-uo - 12-30-2021, 04:56 PM
RE: Learn to create Python3 plugins - by z-uo - 12-30-2021, 05:54 PM
RE: Learn to create Python3 plugins - by z-uo - 12-31-2021, 08:40 AM
RE: Learn to create Python3 plugins - by z-uo - 01-02-2022, 10:37 AM

Forum Jump: