Post Reply 

Python-Fu Script Not Registering

Sep 14, 2014, 00:48 (This post was last modified: Sep 14, 2014 01:58 by image_artist.)
Post: #1
Python-Fu Script Not Registering
While coding my very first Script-Fu script, I've made a decision to switch to Python-Fu for the benefit of easier coding provided by a modern programming language, although Python-Fu seems to lack good user documentation and tutorials and I have never coded in Python.

I'm making an effort to trasition to Python-Fu, and the very first problem I've encountered is that my Python-Fu script doesn't even register at all; it doesn't show up on the image menu.

I was able to successfully create and run my very first Python-Fu script, by creating a Python-Fu script file with the example on http://www.gimp.org/docs/python/index.html, and saving it in my GIMP user plug-in file folder; so I know that Python-Fu works on my GIMP installation, and the problem I'm having isn't a Python-Fu script file placement issue.

Code:
#!/usr/bin/env python


import math
from gimpfu import *


def python_fuzzy_intensity_spectrum_compression(timg, tdrawable,
                                                i8NewIntensitySpectrumLowerLimit = 0,
                                                i8NewIntensitySpectrumUpperLimit = 255,
                                                bToggleAutomaticFuzzyIntensitySpectrumCompression = 1,
                                                i8NewIntensitySpectrumNumberOfSubRanges = 5,
                                                i81stOutputSubRangeLowerLimit = 0,
                                                i82ndOutputSubRangeLowerLimit = 0,
                                                i83rdOutputSubRangeLowerLimit = 0,
                                                i84thOutputSubRangeLowerLimit = 0,
                                                i85thOutputSubRangeLowerLimit = 0,
                                                i86thOutputSubRangeLowerLimit = 0,
                                                i87thOutputSubRangeLowerLimit = 0,
                                                i88thOutputSubRangeLowerLimit = 0,
                                                i89thOutputSubRangeLowerLimit = 0,
                                                i810thOutputSubRangeLowerLimit = 0
                                                ):


register(
        "python-fu-fuzzy-intensity-spectrum-compression",
        "Fuzzy Intensity Spectrum Compression",
        "Compresses the intensity spectrum of an existing image according to the user's specification.",
        "Allen Young",
        "2014, Allen Young.",
        "September 5, 2014",
        "<Image>/Filters/Enhance/Fuzzy Intensity Spectrum Compression...",
        "RGB*, GRAY*",
        [
            (PF_SLIDER,
             "new_intensity_spectrum_lower_limit",
             "New Intensity Spectrum Lower Limit",
             0, 0, 255, 1),
            (PF_SLIDER,
             "new_intensity_spectrum_upper_limit",
             "New Intensity Spectrum Upper Limit",
             255, 0, 255, 1),
            (PF_TOGGLE,
             "automatic_fuzzy_intensity_spectrum_compression",
             "Automatic Fuzzy Intensity Spectrum Compression",
             1),
            (PF_INT8,
             "new_intensity_spectrum_number_of_sub_ranges",
             "New Intensity Spectrum Number of Sub-Ranges",
             5),
            (PF_INT8,
             "1st_output_sub_range_lower_limit",
             "1st Output Sub-Range Lower Limit",
             0),
            (PF_INT8,
             "2nd_output_sub_range_lower_limit",
             "2nd Output Sub-Range Lower Limit",
             0),
            (PF_INT8,
             "3rd_output_sub_range_lower_limit",
             "3rd Output Sub-Range Lower Limit",
             0),
            (PF_INT8,
             "4th_output_sub_range_lower_limit",
             "4th Output Sub-Range Lower Limit",
             0),
            (PF_INT8,
             "5th_output_sub_range_lower_limit",
             "5th Output Sub-Range Lower Limit",
             0),
            (PF_INT8,
             "6th_output_sub_range_lower_limit",
             "6th Output Sub-Range Lower Limit",
             0),
            (PF_INT8,
             "7th_output_sub_range_lower_limit",
             "7th Output Sub-Range Lower Limit",
             0),
            (PF_INT8,
             "8th_output_sub_range_lower_limit",
             "8th Output Sub-Range Lower Limit",
             0),
            (PF_INT8,
             "9th_output_sub_range_lower_limit",
             "9th Output Sub-Range Lower Limit",
             0),
            (PF_INT8,
             "10th_output_sub_range_lower_limit",
             "10th Output Sub-Range Lower Limit",
             0)
        ],
        [],
        python_fuzzy_intensity_spectrum_compression)

main()

What am I not doing right? How can I make the above Python-Fu script properly register?
Find all posts by this user
Quote this message in a reply
Sep 14, 2014, 13:24 (This post was last modified: Sep 14, 2014 13:47 by image_artist.)
Post: #2
RE: Python-Fu Script Not Registering
Thank you for so much info. I really appreciate it.

Inserting 'pass' resolved the issue.

I've cleaned up the code, and now it works as it should.

Code:
#!/usr/bin/env python

from gimpfu import *

def check_output_sub_range_lower_limit_list_validity(
        u8NumberOfOutputSubRanges,
        u8listOutputSubRangeLowerLimits):
    pass

def compute_output_sub_range_lower_limits(
        u8OutputIntensitySpectrumLowerLimit,
        u8OutputIntensitySpectrumUpperLimit,
        u8NumberOfOutputSubRanges):
    pass

def python_fu_fuzzy_intensity_spectrum_compression(imageInput, drawableInput,
                                                u8OutputIntensitySpectrumLowerLimit = 0,
                                                u8OutputIntensitySpectrumUpperLimit = 255,
                                                bAutomaticFuzzyIntensitySpectrumCompression = True,
                                                u8OutputIntensitySpectrumNumberOfSubRanges = 5,
                                                u8OutputSubRangeLowerLimit1 = 0,
                                                u8OutputSubRangeLowerLimit2 = 0,
                                                u8OutputSubRangeLowerLimit3 = 0,
                                                u8OutputSubRangeLowerLimit4 = 0,
                                                u8OutputSubRangeLowerLimit5 = 0,
                                                u8OutputSubRangeLowerLimit6 = 0,
                                                u8OutputSubRangeLowerLimit7 = 0,
                                                u8OutputSubRangeLowerLimit8 = 0,
                                                u8OutputSubRangeLowerLimit9 = 0,
                                                u8OutputSubRangeLowerLimit10 = 0):

    pdb.gimp_message("Lo, behold the magic of GIMP Python-Fu!  "
                     + "The value of bAutomaticFuzzyIntensitySpectrumCompression is "
                     + str(bAutomaticFuzzyIntensitySpectrumCompression) + "!  "
                     + "The value of u8OutputSubRangeLowerLimit1 is "
                     + str(u8OutputSubRangeLowerLimit1) + "!")


register(
        "python_fu_fuzzy_intensity_spectrum_compression",
        "Fuzzy Intensity Spectrum Compression",
        "Compresses the intensity spectrum of an existing image according to the user's specification.",
        "Allen Young",
        "2014, Allen Young.",
        "September 5, 2014",
        "<Image>/Filters/Enhance/Fuzzy Intensity Spectrum Compression...",
        "RGB*, GRAY*",
        [
            (PF_SLIDER,
             "output_intensity_spectrum_lower_limit",
             "Output Intensity Spectrum Lower Limit",
             0, (0, 255, 1)),
            (PF_SLIDER,
             "output_intensity_spectrum_upper_limit",
             "Output Intensity Spectrum Upper Limit",
             255, (0, 255, 1)),
            (PF_TOGGLE,
             "automatic_fuzzy_intensity_spectrum_compression",
             "Automatic Fuzzy Intensity Spectrum Compression",
             1),
            (PF_INT,
             "output_intensity_spectrum_number_of_sub_ranges",
             "Output Intensity Spectrum Number of Sub-Ranges",
             5),
            (PF_INT,
             "output_sub_range_lower_limit_1",
             "1st Output Sub-Range Lower Limit",
             0),
            (PF_INT,
             "output_sub_range_lower_limit_2",
             "2nd Output Sub-Range Lower Limit",
             0),
            (PF_INT,
             "output_sub_range_lower_limit_3",
             "3rd Output Sub-Range Lower Limit",
             0),
            (PF_INT,
             "output_sub_range_lower_limit_4",
             "4th Output Sub-Range Lower Limit",
             0),
            (PF_INT,
             "output_sub_range_lower_limit_5",
             "5th Output Sub-Range Lower Limit",
             0),
            (PF_INT,
             "output_sub_range_lower_limit_6",
             "6th Output Sub-Range Lower Limit",
             0),
            (PF_INT,
             "output_sub_range_lower_limit_7",
             "7th Output Sub-Range Lower Limit",
             0),
            (PF_INT,
             "output_sub_range_lower_limit_8",
             "8th Output Sub-Range Lower Limit",
             0),
            (PF_INT,
             "output_sub_range_lower_limit_9",
             "9th Output Sub-Range Lower Limit",
             0),
            (PF_INT,
             "output_sub_range_lower_limit_10",
             "10th Output Sub-Range Lower Limit",
             0)
        ],
        [],
        python_fu_fuzzy_intensity_spectrum_compression)

main()

Quote:Fuzzy Intensity Spectrum Compression Message

Lo, behold the magic of GIMP Python-Fu! The value of bAutomaticFuzzyIntensitySpectrumCompression is False! The value of u8OutputSubRangeLowerLimit1 is 32423!

Just as a side note: I'm aware that Python being what it is (i.e. a high-level interpreted language that is designed for fast and convenient coding), using Systems Hungarian notation in Python code is probably against recommended good practice and is pointless (not just in Python, but in any high-level programming language). However, I code image and video processing software technology systems in C, assembly, and OpenCL, at sub-pixel, pixel, and super-pixel levels, with thousands of variables that consume several gigabytes to terabytes of memory during execution in distributed parallel computing environment, and the careful categorization of variables makes or breaks the systems, so I do have to care at the lowest levels; for that reason, letting go of using Systems Hungarian notation in pixel-level image manipulation code is quite hard for me; in lax code, I wouldn't care about using Systems Hungarian notation, or any Hungarian notation whatsoever.

I have provided the default values for the input parameter variables only because they were in the example on http://www.gimp.org/docs/python/index.html, although they seemed unnecessary.

I have used PF_INT8 only because it's listed on http://www.gimp.org/docs/python/index.html, just to see what happens. After an experiment, I can conclude that using PF_INT8 DOES NOT prevent a Python-Fu function from registering; however, the input values are not restricted to the int-8 range as you've noted, so I'm using PF_INT in my Python-Fu register function. (In any case, I need the 8-bit unsigned integer type, not the 8-bit integer type.)


I'm beginning to think that Python is an awesome high-level programming language; no wonder it's so popular.

Now I'm onto doing a bit of coding in Python on Emacs...
Find all posts by this user
Quote this message in a reply
Post Reply 


Possibly Related Threads...
Thread: Author Replies: Views: Last Post
  Request for script chlebna 1 174 Sep 13, 2017 09:35
Last Post: ythgilb
  Request for script - Guillotine + Watermark sunslick 1 231 Sep 4, 2017 08:51
Last Post: ythgilb
  Script-fu: How to create new, addressable layer using gimp-floating-sel-to-layer Bertholom√§us 2 235 Aug 31, 2017 14:32
Last Post: Bertholomäus
  How to modify this script-fu? Zakary81 1 198 Aug 23, 2017 12:48
Last Post: paynekj
  Loading PythonFu Plugin: ImportError for .../python/gimp.so (GIMP 2.8.22/OSX/Py2.7.9) joroek 1 318 Jul 11, 2017 07:26
Last Post: ythgilb

Forum Jump:


GIMP ForumPortalArchiveContactTermsRSS