Re: Accessing stdin from a Python based GIMP Plugin.

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On Thu, Sep 5, 2019 at 6:38 AM Ofnuts <ofnuts@xxxxxxx> wrote:

> On 9/4/19 6:48 AM, Craig Sanders via gimp-developer-list wrote:
> > Hello all.
> >
> > Are there any gotchas that one should be aware of when accessing stdin
> from
> > a Python based GIMP Plugin?
> >
> > The reason I ask, is because I am implementing a Plugin which seems to be
> > working fine - until such time as I insert the following code into it;
> >
> >
> >
> >      for line in stdin :
>
>
> Works fine for me on Linux (assuming you mean 'sys.stdin' and not
> 'stdin'). This is of course the very stdin stream of the Gimp process.
> Just tested with file, pipe, and terminal and all three work.
>
> Can't say the same for Windows, the standard streams for windowed
> applications do not have a regular behavior (for instance IIRC you will
> hang your plugin if you print more than 8K to sys.stdout).
>
>
> Not sure it is a good idea anyway to use stdin, you have to restart Gimp
> if you want a second run. Why not use a plain file?
>
>
>
> _______________________________________________
> gimp-developer-list mailing list
> List address:    gimp-developer-list@xxxxxxxxx
> List membership:
> https://mail.gnome.org/mailman/listinfo/gimp-developer-list
> List archives:   https://mail.gnome.org/archives/gimp-developer-list


Hello, and thank you very much for your reply to my question - it is
greatly appreciated.

I must say however, that it looks as though you have responded to a draft
copy of the e-mail that I must have sent by accident. Sorry about that - I
don't know how I managed to do it!

The e-mail I meant to send is below.

>>>>> BEGIN INTENDED EMAIL >>>>>

Hello all.

Are there any gotchas that one should be aware of when accessing stdin from
a Python based GIMP Plugin?

The reason I ask, is because I am implementing a Plugin which seems to be
working fine - until such time as I insert the following code into it;

    # Code omitted

    # The sys module is imported at the top of the file.

    list_filenames = ""

    for line in sys.stdin :

        list_filenames = list_filenames + ";" + line

    # Code omitted

If I didn't know better, I'd say the line of code in which the for loop
attempts to read from sys.stdin is causing the problem.

When I run the Plugin - with the above code, from the command line, I get
the following error;

    batch command experienced an execution error:
    Error: ( : 1) eval: unbound variable:
python-fu-runPlugin-multiple-fromList

where runPlugin_multiple_fromList is the name of the Python function which
implements my Plugin.

Now, if I comment out the for loop, then the Plugin works!

I am invoking the following command from the command line (within Linux) in
order to run the Plugin.

    find \
    /home/foo/foreground_images/ \
    -maxdepth 1 \
    -name "*.png" \
    | \
    gimp \
    --no-interface \
    --verbose \
    --console-messages \
    --batch-interpreter="plug-in-script-fu-eval" \
    --batch \
    '( \
    python-fu-runPlugin-multiple-fromList \
    RUN-NONINTERACTIVE \
    "/home/foo/background_images/bg_image.png" \
    "0" \
    "" \
    "/home/foo/images_output/" \
    "0" \
    "result" \
    "0" \
    )' \
    --batch "(gimp-quit 0)"

I'm actually running the command on one line. I have only broken it up
across multiple lines above, to assist with readability.

What I'd ideally like this Plugin to do, is operate on all of the files
which are passed to it via stdin. The find utility is only used above to
help demonstrate the concept. In reality, I will be using another
customised utility which will write the list the files of interest out to
stdout.

Thanks in advance for any assistance.

<<<<< END INTENDED EMAIL <<<<<

I just thought I'd ask the question in case GIMP commandeers stdin and/or
stdout, or does something else that I might not have thought of! I didn't
think GIMP did commandeer stdin and stdout, but I thought I'd ask more
enlightened minds that mine just to be sure. The reason I say this, is
because I wrote a small GIMP Test Plugin which read from stdin, and it
seemed to work okay.

On one other matter, you don't seem to approve of the fact that my Plugin
reads from stdin. Hopefully, my intended email above helps to show you how
I am trying to use it. I also have a variant of my Plugin which does read a
list of image filenames from a file, however the variant which reads the
list of image filenames from stdin seems - at least to me anyway, to be
more in keeping with the Unix programming philosophy. From memory, I think
Eric Raymond might have even talked about programming in this manner is his
book "The Art of Unix Programming.".

Thanks once again for all of your time and assistance. It is appreciated
immensely.
_______________________________________________
gimp-developer-list mailing list
List address:    gimp-developer-list@xxxxxxxxx
List membership: https://mail.gnome.org/mailman/listinfo/gimp-developer-list
List archives:   https://mail.gnome.org/archives/gimp-developer-list



[Index of Archives]     [Video For Linux]     [Photo]     [Yosemite News]     [gtk]     [GIMP for Windows]     [KDE]     [GEGL]     [Gimp's Home]     [Gimp on GUI]     [Gimp on Windows]     [Steve's Art]

  Powered by Linux