Sign up now! · Forgot password?
RSS/Atom feed identi.ca Twitter

Problems using the PF_STRINGARRAY parameter type when writing a Python plugin for Gimp.

This discussion is connected to the gimp-developer-list.gnome.org mailing list which is provided by the GIMP developers and not related to gimpusers.com.

This is a read-only list on gimpusers.com so this discussion thread is read-only, too.

Craig Sanders
2018-05-23 00:17:30 UTC (27 days ago)

Problems using the PF_STRINGARRAY parameter type when writing a Python plugin for Gimp.

Hello.

I'm trying to write a very basic plugin for Gimp using Python and I want its one and only parameter to be of type PF_STRINGARRAY. The goal of my plugin for the time being, is to receive a list of files, and then simply print their names on the Command line, when the plugin is run.

The code for my plugin is as follows;

BEGIN CODE SEGMENT >>>>>

from gimpfu import register, main, pdb, PF_STRINGARRAY

def \ process_list_of_files(

listOfFiles ) :

for filename in listOfFiles :

print("========================================") print("Filename = %s" % filename)
print("========================================")

register( "process-list-of-files", # The name of the command "Process a list of files", # A brief description of the command "Process a list of files", # Help message "John Doe", # Author "John Doe", # Copyright holder "2018", # Date "/Image/Process list of files", # The way the script will be referred to in the menu
"RGB*, GRAY*", # Image mode [
(PF_STRINGARRAY, "listOfFiles", "List of files", [""]) ],
[],
process_list_of_files,
menu="/File/ProcessListOfFiles")

main()

<<<<< END CODE SEGMENT <<<<<

I then run this plugin from the Command line using the following command;

gimp --no-interface --verbose --console-messages --batch-interpreter='plug-in-script-fu-eval' --batch '(python-fu-process-list-of-files RUN-NONINTERACTIVE ["/home/john/test.txt"])' --batch "(gimp-quit 1)"

Unfortunately, it doesn't work for me and complains with the messages;

Starting extension: 'extension-script-fu' batch command experienced an execution error

If I now change my plugin's parameter type to be PF_STRING, and update my code and Command line invocation method accordingly, it works! I know that I could get around this problem by passing filenames in as one string, where the filenames are separated by the ":" character, but I want the code in the plugin to be as simple as possible.

So I guess my question is; is the PF_STRINGARRAY type supported, or am I doing something wrong? I am using Gimp version 2.6.9.

Any help would be immensely appreciated.

Thanks in advance.

Carol Spears
2018-05-23 02:11:54 UTC (26 days ago)

Problems using the PF_STRINGARRAY parameter type when writing a Python plugin for Gimp.

On Tue, May 22, 2018 at 8:17 PM, Craig Sanders

wrote:

Hello.

I'm trying to write a very basic plugin for Gimp using Python and I want its one and only parameter to be of type PF_STRINGARRAY. The goal of my plugin for the time being, is to receive a list of files, and then simply print their names on the Command line, when the plugin is run.

Huh. If I ever knew that PF_STRINGARRAY existed, it did not sink into the gray matter much.

Try this, instead, perhaps. It has the limitation of delivering all of the files in the directory however:

Hmm, I have been doing this in two steps:

import os

def list_directory(directory): cennotts = os.listdir(directory) contents = sorted(cennotts)
return contents

def list_directory_ext(directory, ext): total_contents = list_directory(directory) contents = []
for content in total_contents:
if content.endswith(ext):contents.append(content) return contents

They work with (PF_DIRNAME, "img_dir", "Images directory", ""),

carol

Kevin Payne
2018-05-23 12:00:11 UTC (26 days ago)

Problems using the PF_STRINGARRAY parameter type when writing a Python plugin for Gimp.

I'm trying to write a very basic plugin for Gimp using Python and I want its one and only parameter to be of type PF_STRINGARRAY. The goal of my plugin for the time being, is to receive a list of files, and then simply print their names on the Command line, when the plugin is run.

A bit of Googling leads to the conclusion that PF_STRINGARRAY only exists in a hacked version of gimpfu.py so isn't a standard part of GIMP as shipped.

Ofnuts
2018-05-23 12:39:34 UTC (26 days ago)

Problems using the PF_STRINGARRAY parameter type when writing a Python plugin for Gimp.

If you want to run the script as a batch it doesn't need (and really shouldn't be) a plugin. Then your code is just a plain Python function that takes string parameters, and you don't need to register it. See

https://stackoverflow.com/questions/44430081/how-to-run-python-scripts-using-gimpfu-from-windows-command-line/44435560#44435560

On 05/23/18 02:17, Craig Sanders wrote:

Hello.

I'm trying to write a very basic plugin for Gimp using Python and I want its one and only parameter to be of type PF_STRINGARRAY. The goal of my plugin for the time being, is to receive a list of files, and then simply print their names on the Command line, when the plugin is run.

The code for my plugin is as follows;

BEGIN CODE SEGMENT >>>>>

from gimpfu import register, main, pdb, PF_STRINGARRAY

def \ process_list_of_files(

listOfFiles ) :

for filename in listOfFiles :

print("========================================") print("Filename = %s" % filename)
print("========================================")

register( "process-list-of-files", # The name of the command "Process a list of files", # A brief description of the command "Process a list of files", # Help message "John Doe", # Author "John Doe", # Copyright holder "2018", # Date "/Image/Process list of files", # The way the script will be referred to in the menu
"RGB*, GRAY*", # Image mode [
(PF_STRINGARRAY, "listOfFiles", "List of files", [""]) ],
[],
process_list_of_files,
menu="/File/ProcessListOfFiles")

main()

<<<<< END CODE SEGMENT <<<<<

I then run this plugin from the Command line using the following command;

gimp --no-interface --verbose --console-messages --batch-interpreter='plug-in-script-fu-eval' --batch '(python-fu-process-list-of-files RUN-NONINTERACTIVE ["/home/john/test.txt"])' --batch "(gimp-quit 1)"

Unfortunately, it doesn't work for me and complains with the messages;

Starting extension: 'extension-script-fu' batch command experienced an execution error

If I now change my plugin's parameter type to be PF_STRING, and update my code and Command line invocation method accordingly, it works! I know that I could get around this problem by passing filenames in as one string, where the filenames are separated by the ":" character, but I want the code in the plugin to be as simple as possible.

So I guess my question is; is the PF_STRINGARRAY type supported, or am I doing something wrong? I am using Gimp version 2.6.9.

Any help would be immensely appreciated.

Thanks in advance. _______________________________________________ gimp-developer-list mailing list
List address: gimp-developer-list@gnome.org List membership: https://mail.gnome.org/mailman/listinfo/gimp-developer-list List archives: https://mail.gnome.org/archives/gimp-developer-list

Kevin Cozens
2018-05-25 03:00:01 UTC (24 days ago)

Problems using the PF_STRINGARRAY parameter type when writing a Python plugin for Gimp.

On 2018-05-23 08:00 AM, Kevin Payne wrote:

A bit of Googling leads to the conclusion that PF_STRINGARRAY only exists in a hacked version of gimpfu.py so isn't a standard part of GIMP

I looked at the code for pygimp. Since 2004 the 5 array types are commented out. From what I saw in the code the array types were going to be handled as a list.

Cheers!

Kevin.

http://www.ve3syb.ca/               | "Nerds make the shiny things that
https://www.patreon.com/KevinCozens | distract the mouth-breathers, and
                                     | that's why we're powerful"
Owner of Elecraft K2 #2172          |
#include      |             --Chris Hardwick