Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
My first python plugin review
#9
(12-31-2024, 09:40 PM)origamifreak2 Wrote: I have a question. The gimp_drawable_type() function on line 9 is returning 0 for jpegs, 1 for pngs, and 1 for layer groups. How would I tell the difference between a single layer in a png file and a layer group? I'm probably missing something very simple here.

Code:
   # make sure drawable is a layer
   drawable_type = pdb.gimp_drawable_type(drawable)
   if drawable_type != 0 and drawable_type != 1:
       pdb.gimp_message(drawable_type)
       pdb.gimp_message("Please select a layer")
       return

gimp_drawable_type() isn't about Layer/Channel/Group but about color and alpha support, O being RGB and 1 beibg RGB+alpha.

To test the drawable "genre" you use Python classes with isinstance() with the caveat that a layer group is gimp.GroupLayer but since GroupLayer is a subclass of  Layer, it is also a group. So typically:

Code:
if isinstance(drawable,gimp.Channel): # handles both channels and masks
    complain_and_exit()
elif isinstance(drawable,gimp.GroupLayer): # is a group
    process_group(drawable)
else: # should be a layer
   process_layer(drawable)
Reply


Messages In This Thread
My first python plugin review - by origamifreak2 - 12-28-2024, 02:59 AM
RE: My first python plugin review - by Ofnuts - 12-28-2024, 09:08 AM
RE: My first python plugin review - by Ofnuts - 12-29-2024, 09:18 AM
RE: My first python plugin review - by gasMask - 12-29-2024, 12:22 AM
RE: My first python plugin review - by Ofnuts - 12-31-2024, 09:56 PM
RE: My first python plugin review - by Ofnuts - 01-01-2025, 09:26 AM
RE: My first python plugin review - by Ofnuts - 01-06-2025, 09:03 AM
RE: My first python plugin review - by Ofnuts - Yesterday, 09:18 AM

Forum Jump: