Gimp-Forum.net
Help.Wanted('Pixel region gimpPy') - 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: Help.Wanted('Pixel region gimpPy') (/Thread-Help-Wanted-Pixel-region-gimpPy)

Pages: 1 2


RE: Help.Wanted('Pixel region gimpPy') - Ofnuts - 03-29-2020

Not bad, but can be made simpler (and more readable):

Instead of list((A,B,C)) you can write [A,B,C]. But bytearray() accepts tuples as well as lists, and returning several elements conveniently makes the function returns a tuple, so in FindColor() lines such as

Code:
return list((0, 255-int(255*((hue%60)/60.0)), 255, opac))


can be just as well spared two levels of parentheses and written:

Code:
return 0, 255-int(255*((hue%60)/60.0)), 255, opac
.

Also, in Python it is valid to have a comma after the last element of the list, so instead of using the 80-era "comma ahead" defensive coding style:

Code:
[
      (PF_IMAGE, "image", "takes current image", None)
      , (PF_DRAWABLE, "drawable", "Input layer", None)
      , (PF_SLIDER, "alphaVal", "Alpha value", 255, [0, 255, 10])
  ],

You can put commas at the end of every line:

Code:
[
      (PF_IMAGE, "image", "takes current image", None),
      (PF_DRAWABLE, "drawable", "Input layer", None),
      (PF_SLIDER, "alphaVal", "Alpha value", 255, [0, 255, 10]),
  ],