RSS/Atom feed Twitter
Site is read-only, email is disabled

Arrays in Python

This discussion is connected to the gimp-user-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.

6 of 6 messages available
Toggle history

Please log in to manage your subscriptions.

Arrays in Python Beinsezii 09 Apr 19:09
  Arrays in Python Ofnuts 09 Apr 21:06
   Arrays in Python Beinsezii 09 Apr 22:57
    Arrays in Python Ofnuts 10 Apr 07:03
     Arrays in Python Joao S. O. Bueno 10 Apr 11:59
      Arrays in Python Beinsezii 10 Apr 16:15
2018-04-09 19:09:06 UTC (about 6 years ago)
postings
6

Arrays in Python

No matter what I try, I can't get the plugin to load while using an array in either the input params or return values. Taken straight from the 'gimpenums' pydocs, I should have access to "PDB_INT32ARRAY"
"PDB_FLOATARRAY"
and a bunch others, but using any of them causes the script to fail to load in GIMP. And just to make *absolutely sure* it wasn't a typo, I tried their numeric values, too.

I can't just use a bajillion i32's or whatever since the Frankenstein's Monster of a script I'm working on takes an unknown amount of numbers as an input. Could be anywhere from a a few to a few thousand depending on how long you want your PC to act as a space heater. There's a 65% chance I'll re-do the main function of the script in a way where it wouldn't take arrays for layer return purposes, but I'll probably come across the array problem in future scripts anyway.

I've included an example script. What it *should* be able to do is print out whatever array you put into it with something like the python console or another script, but it doesn't even load. It'll appear under "/Beinsezii/" if it *does* load.

Ofnuts
2018-04-09 21:06:59 UTC (about 6 years ago)

Arrays in Python

On 04/09/18 21:09, Beinsezii wrote:

No matter what I try, I can't get the plugin to load while using an array in either the input params or return values. Taken straight from the 'gimpenums' pydocs, I should have access to "PDB_INT32ARRAY"
"PDB_FLOATARRAY"
and a bunch others, but using any of them causes the script to fail to load in GIMP. And just to make *absolutely sure* it wasn't a typo, I tried their numeric values, too.

I can't just use a bajillion i32's or whatever since the Frankenstein's Monster of a script I'm working on takes an unknown amount of numbers as an input. Could be anywhere from a a few to a few thousand depending on how long you want your PC to act as a space heater.
There's a 65% chance I'll re-do the main function of the script in a way where it wouldn't take arrays for layer return purposes, but I'll probably come across the array problem in future scripts anyway.

I've included an example script. What it *should* be able to do is print out whatever array you put into it with something like the python console or another script, but it doesn't even load. It'll appear under "/Beinsezii/" if it *does* load.

Attachments:
* http://www.gimpusers.com/system/attachments/871/original/bsz_array_input_debug.py

AFAIK you can't, but anyway how do you expect the user to enter the bazillion numbers? If you want that many numbers just ask for a file name and read the file.

Or maybe your array can be pixels values in a layer (these are easy to get in Python) in which case the user would just specify a second layer.

2018-04-09 22:57:43 UTC (about 6 years ago)
postings
6

Arrays in Python

AFAIK you can't, but anyway how do you expect the user to enter the bazillion numbers? If you want that many numbers just ask for a file name and read the file.

The user already can. I wrote a custom system for making GTK configuration windows that I use with all my plugins instead of the default python-fu thing that just stacks all the widgets into a grand tower of Babel. Where the enums come into play is allowing other scripts to call this one via the PDB. Not really a problem right now since the registry's dead and therefore it won't end up in the hands of others for a while (right?). I'm just perfectionist.

Guess for now I'll refactor it to make the PDB method take i32's & floats instead of arrays, and if some other weirdo wants the full horror of my plugin, they'll just have to import the class.

If anyone else knows a way or has other inquiries, I'll stay subbed to this thread.

Or maybe your array can be pixels values in a layer (these are easy to get in Python) in which case the user would just specify a second layer.

You say that, but I was entirely unable to get proper pixel info in one of my past scripts. I could get standard 8-bit info, but no 32-bit floating point info that everything apparently uses now (2.10 RC-1). Unless I'm completely missing it, the python-fu docs are patchy at best. Most of my knowledge comes from trying to interpret the auto-generated pydoc stuff, incomplete docs from like 4 years ago, or reverse engineering other over-the-top scripts like LayerFX.

Ofnuts
2018-04-10 07:03:54 UTC (about 6 years ago)

Arrays in Python

On 04/10/18 00:57, Beinsezii wrote:

AFAIK you can't, but anyway how do you expect the user to enter the bazillion numbers? If you want that many numbers just ask for a file name and read the file.

The user already can. I wrote a custom system for making GTK configuration windows that I use with all my plugins instead of the default python-fu thing that just stacks all the widgets into a grand tower of Babel. Where the enums come into play is allowing other scripts to call this one via the PDB. Not really a problem right now since the registry's dead and therefore it won't end up in the hands of others for a while (right?). I'm just perfectionist.

Guess for now I'll refactor it to make the PDB method take i32's & floats instead of arrays, and if some other weirdo wants the full horror of my plugin, they'll just have to import the class.

If anyone else knows a way or has other inquiries, I'll stay subbed to this thread.

Or maybe your array can be pixels values in a layer (these are easy to get in Python) in which case the user would just specify a second layer.

You say that, but I was entirely unable to get proper pixel info in one of my past scripts. I could get standard 8-bit info, but no 32-bit floating point info that everything apparently uses now (2.10 RC-1). Unless I'm completely missing it, the python-fu docs are patchy at best. Most of my knowledge comes from trying to interpret the auto-generated pydoc stuff, incomplete docs from like 4 years ago, or reverse engineering other over-the-top scripts like LayerFX.

I have rarely seen a Python script use another, most people would just copy the code they need to avoid the dependency. And you can factor you code to have a class that does the work and a registration facade, so that other Pythin script can import you code and call the useful code directly.

Joao S. O. Bueno
2018-04-10 11:59:51 UTC (about 6 years ago)

Arrays in Python

It is just Python -

Just use on the calee script an inner function - one to be publicly exposed on the PDB taking user arguments, and another one internal meant to be called from other Python functions .

On this, simply use a Python list.

You can manipulate `sys.path` in order to be able to import other installed GIMP scripts PY files.

Just don't expect the Procedural Database way of calling parameters, essentially created more than
20 years ago with Scheme/lisp in mind to be able to handle the flexibility one have in modern Python parameter passing.

If you need the user to feed in several numbers on the UI, and wants to use GIMP-FU, (and not
design your own custom GTK UI), my suggestion is to use a string, and tell the user to separate the nubmers by spaces or commas - on the Python side, you just split and convert the argument.

Other than that, yes, GIMp-Fu should be able to handle these PDB arrays as arguments - despite
the workarounds I just described.
Could you can fill a bug in bugzilla about that?

Regards,

js -> wrote:

On 04/10/18 00:57, Beinsezii wrote:

AFAIK you can't, but anyway how do you expect the user to enter the bazillion numbers? If you want that many numbers just ask for a file name and read the file.

The user already can. I wrote a custom system for making GTK configuration windows that I use with all my plugins instead of the default python-fu thing
that just stacks all the widgets into a grand tower of Babel. Where the enums come into play is allowing other scripts to call this one via
the PDB. Not really a problem right now since the registry's dead and therefore
it won't end up in the hands of others for a while (right?). I'm just perfectionist.

Guess for now I'll refactor it to make the PDB method take i32's & floats instead of arrays, and if some other weirdo wants the full horror of my plugin,
they'll just have to import the class.

If anyone else knows a way or has other inquiries, I'll stay subbed to this
thread.

Or maybe your array can be pixels values in a layer (these are easy to get in Python) in which case the user would just specify a second layer.

You say that, but I was entirely unable to get proper pixel info in one of my
past scripts. I could get standard 8-bit info, but no 32-bit floating point info
that everything apparently uses now (2.10 RC-1). Unless I'm completely missing it, the python-fu docs are patchy at best. Most of
my knowledge comes from trying to interpret the auto-generated pydoc stuff,
incomplete docs from like 4 years ago, or reverse engineering other over-the-top
scripts like LayerFX.

I have rarely seen a Python script use another, most people would just copy the code they need to avoid the dependency. And you can factor you code to have a class that does the work and a registration facade, so that other Pythin script can import you code and call the useful code directly.

_______________________________________________ gimp-user-list mailing list
List address: gimp-user-list@gnome.org List membership: https://mail.gnome.org/mailman/listinfo/gimp-user-list List archives: https://mail.gnome.org/archives/gimp-user-list

2018-04-10 16:15:53 UTC (about 6 years ago)
postings
6

Arrays in Python

I have rarely seen a Python script use another, most people would just copy the code they need to avoid the dependency.

That's one of Python's strongest points, though. Just import everything you don't want to deal with yourself.

And you can factor you
code to have a class that does the work and a registration facade, so that other Pythin script can import you code and call the useful code directly.

They should already be able to call the code by running ".plugin.main()" from the module. ....right? *tests*
Nope. NVM. Don't have access to the image/drawable variables if called from within another script. Will make main() a separate function instead of part of the class. The GUI already doesn't call it directly, so it should be easy to fix.

If you need the user to feed in several numbers on the UI, and wants to use GIMP-FU, (and not
design your own custom GTK UI), my suggestion is to use a string, and tell the user to separate the nubmers by spaces or commas - on the Python side, you just split and convert the argument.

https://i.imgur.com/pFCuj17.png