Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Learn to create Python3 plugins
#5
(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 :-)
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 programmer_ceds - 12-28-2021, 05:38 PM
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: