Re: [Gimp-developer] pdb.gimp_get_item_by_id(), or ids and layers and layer groups

2011-02-07 Thread saulgoode
Quoting Javier Candeira jav...@candeira.com:

 On Mon, Feb 7, 2011 at 2:30 AM,
 saulgo...@flashingtwelve.brickfilms.com wrote:
 The PDB functions already exist for handling layer groups, and
 Script-fu does not have any problem making use of these functions. The
 Python-fu extension has not yet been updated to handle groups (there
 is no 'group' class).

 Do you mean that the Python-fu extension doesn't yet have access to
 the proper script-fu functions from pdb?

Not exactly. In Python, a layer is a reference to a data structure  
(in C terminology, a pointer to a struct). One of the fields is the  
layer's ID number. The PDB only deals with these ID numbers, and  
Python doesn't provide a direct way to handle IDs. The only thing you  
could do is get a list of all layers/groups (which would be a list of  
pointers to structures) and search that list for the structure  
containing the appropriate ID. Since the 'gimp-image-get-layers'  
procedure now only returns the IDs of the top-level layers/groups,  
there is no way to perform such a search. At some point, this will be  
remedied but to my knowledge there is currently no way to do what you  
want with Python.

Script-fu does not encounter this problem because there is no  
Script-fu data structure for a layer -- a layer is identified by the  
same ID number that the PDB uses. It does not matter that the layer  
IDs returned by 'gimp-image-get-layers' might actually be group IDs,  
to Script-fu it is just a number. Script-fu can pass that same number  
back to the PDB and the procedure will know what to do with it (for  
example, a call to 'gimp-item-is-group ID-number' will inform  
Script-fu that the ID belongs to a group object).

It is up to the script programmer to make sure that he passes the  
proper IDs to procedures -- there is no type safety for these GIMP  
objects. For example, if a layer's ID is passed to  
'gimp-item-get-children' then a run-time error will occur because that  
procedure is expecting a group object's ID number.

 If you can do this via script-fu, do you mind providing me with the
 calls, so I can try and call them from Python?

The following script will save your tree to the specified directory  
using the flat naming approach I described earlier. I did not attempt  
to get too fancy soas to keep the code simple. You will probably wish  
to base your filename on the image's name, rather than the directory  
name as I have done (be sure to handle the possibility of an  
Untitled image).

If you need further assistance, I recommend that you post to the GIMP  
Users Group forum ( http://gug.criticalhit.dk/viewforum.php?f=8 ). I  
visit there daily.

(define (script-fu-sg-save-tree image dir-name)
   (define (process-items items prefix)
 (set! prefix (string-append prefix ++))
 (while (not (null? items))
   (if (zero? (car (gimp-item-is-group (car items
 (let ((filename (string-append prefix (car  
(gimp-item-get-name (car items))
   (file-png-save-defaults RUN-NONINTERACTIVE image (car  
items) filename filename)
   (set! items (cdr items)) )
 (begin
   (process-items (vector-list (cadr (gimp-item-get-children  
(car items
  (string-append prefix (car  
(gimp-item-get-name (car items )
   (set! items (cdr items)) 
   (process-items
   (vector-list
  (cadr (gimp-image-get-layers image)))
   (string-append
   dir-name
   DIR-SEPARATOR
   (unbreakupstr (last (strbreakup dir-name DIR-SEPARATOR))  
DIR-SEPARATOR) )))

(script-fu-register script-fu-sg-save-tree
   Save image tree...
   Save each layer as a PNG retaining group information
   saulgoode
   saulgoode
   February 2011
   *
   SF-IMAGE   The image   0
   SF-DIRNAME Image Directory /home/saul
   )

(script-fu-menu-register script-fu-sg-save-tree
  Image/File/Save)





___
Gimp-developer mailing list
Gimp-developer@lists.XCF.Berkeley.EDU
https://lists.XCF.Berkeley.EDU/mailman/listinfo/gimp-developer


Re: [Gimp-developer] pdb.gimp_get_item_by_id(), or ids and layers and layer groups

2011-02-07 Thread Javier Candeira
On Mon, Feb 7, 2011 at 8:44 PM,
saulgo...@flashingtwelve.brickfilms.com wrote:
 Quoting Javier Candeira jav...@candeira.com:

 On Mon, Feb 7, 2011 at 2:30 AM,
 saulgo...@flashingtwelve.brickfilms.com wrote:

 The PDB functions already exist for handling layer groups, and
 Script-fu does not have any problem making use of these functions. The
 Python-fu extension has not yet been updated to handle groups (there
 is no 'group' class).

 Do you mean that the Python-fu extension doesn't yet have access to
 the proper script-fu functions from pdb?

 Not exactly. In Python, a layer is a reference to a data structure (in C
 terminology, a pointer to a struct). One of the fields is the layer's ID
 number. The PDB only deals with these ID numbers, and Python doesn't provide
 a direct way to handle IDs. The only thing you could do is get a list of all
 layers/groups (which would be a list of pointers to structures) and search
 that list for the structure containing the appropriate ID. Since the
 'gimp-image-get-layers' procedure now only returns the IDs of the top-level
 layers/groups, there is no way to perform such a search. At some point, this
 will be remedied but to my knowledge there is currently no way to do what
 you want with Python.

 Script-fu does not encounter this problem because there is no Script-fu data
 structure for a layer -- a layer is identified by the same ID number that
 the PDB uses. It does not matter that the layer IDs returned by
 'gimp-image-get-layers' might actually be group IDs, to Script-fu it is
 just a number. Script-fu can pass that same number back to the PDB and the
 procedure will know what to do with it (for example, a call to
 'gimp-item-is-group ID-number' will inform Script-fu that the ID belongs to
 a group object).

Thank you, thank you so much. You may have saved my bacon already,
just with this explanation. The rest is (very good) gravy. Back to the
code grindstone now...

Javier
___
Gimp-developer mailing list
Gimp-developer@lists.XCF.Berkeley.EDU
https://lists.XCF.Berkeley.EDU/mailman/listinfo/gimp-developer


[Gimp-developer] pdb.gimp_get_item_by_id(), or ids and layers and layer groups

2011-02-06 Thread Javier Candeira
First of all, a big thank you to the developers for an great image
editing program.

I am writing a python-gimp export script for an animation tool, using
Ubuntu 10.10 maverick with Gimp version 2.7.3 from this ubuntu PPA,
which is not a nightly build of your devel tree, but close enough:
https://launchpad.net/~matthaeus123/+archive/mrw-gimp-svn

The workflow expects a gimp document's layers to be exported as a tree
of files, where the directory structure is determined by the
document's layer groups. So, if group panel_1 has sublayers foo
and bar, and group panel_2 has sublayers blargh and foobar,
the expected output looks like this:

$ tree exported_layers
exported_layers
|-- panel_1
|   |-- bar.png
|   `-- foo.png
`-- panel_2
|-- blargh.png
`-- foobar.png

How can one get the layer objects that correspond to a given group?
It's easy to get layer IDs, it's not clear how to access the layer
object even if one knows its ID.

The gimp.image.layers sequence only contains the first-level layers
and layer groups, not all the layers. In our document, all layers
belong to a group, so that sequence only contains layer groups.

When getting the children of a given group,
pdb.gimp_item_get_children(group)[1] returns a tuple of IDs. Having
only each layer's ID and not the layer object means one can't, for
instance, make a new layer as a duplicate of an existing one. This
code fails with a type error:
  newlayer = pdb.gimp_layer_new_from_drawable(layerID, image)

Is there something I'm missing/doing wrong, or is this a gap in the
available script-fu methods?

Thanks,

Javier Candeira.
___
Gimp-developer mailing list
Gimp-developer@lists.XCF.Berkeley.EDU
https://lists.XCF.Berkeley.EDU/mailman/listinfo/gimp-developer


Re: [Gimp-developer] pdb.gimp_get_item_by_id(), or ids and layers and layer groups

2011-02-06 Thread Rob Antonishen
I'm not a dev but AFAIK none of the layer group stuff es exposed in
the pdb, so has not been added to script-fu or python.

-Rob A

On 2/6/11, Javier Candeira jav...@candeira.com wrote:
 First of all, a big thank you to the developers for an great image
 editing program.

 I am writing a python-gimp export script for an animation tool, using
 Ubuntu 10.10 maverick with Gimp version 2.7.3 from this ubuntu PPA,
 which is not a nightly build of your devel tree, but close enough:
 https://launchpad.net/~matthaeus123/+archive/mrw-gimp-svn

 The workflow expects a gimp document's layers to be exported as a tree
 of files, where the directory structure is determined by the
 document's layer groups. So, if group panel_1 has sublayers foo
 and bar, and group panel_2 has sublayers blargh and foobar,
 the expected output looks like this:

 $ tree exported_layers
 exported_layers
 |-- panel_1
 |   |-- bar.png
 |   `-- foo.png
 `-- panel_2
 |-- blargh.png
 `-- foobar.png

 How can one get the layer objects that correspond to a given group?
 It's easy to get layer IDs, it's not clear how to access the layer
 object even if one knows its ID.

 The gimp.image.layers sequence only contains the first-level layers
 and layer groups, not all the layers. In our document, all layers
 belong to a group, so that sequence only contains layer groups.

 When getting the children of a given group,
 pdb.gimp_item_get_children(group)[1] returns a tuple of IDs. Having
 only each layer's ID and not the layer object means one can't, for
 instance, make a new layer as a duplicate of an existing one. This
 code fails with a type error:
   newlayer = pdb.gimp_layer_new_from_drawable(layerID, image)

 Is there something I'm missing/doing wrong, or is this a gap in the
 available script-fu methods?

 Thanks,

 Javier Candeira.
 ___
 Gimp-developer mailing list
 Gimp-developer@lists.XCF.Berkeley.EDU
 https://lists.XCF.Berkeley.EDU/mailman/listinfo/gimp-developer

___
Gimp-developer mailing list
Gimp-developer@lists.XCF.Berkeley.EDU
https://lists.XCF.Berkeley.EDU/mailman/listinfo/gimp-developer


Re: [Gimp-developer] pdb.gimp_get_item_by_id(), or ids and layers and layer groups

2011-02-06 Thread saulgoode
Quoting Rob Antonishen rob.antonis...@gmail.com:

 I'm not a dev but AFAIK none of the layer group stuff es exposed in
 the pdb, so has not been added to script-fu or python.

 On 2/6/11, Javier Candeira jav...@candeira.com wrote:
 :
 :
 The gimp.image.layers sequence only contains the first-level layers
 and layer groups, not all the layers. In our document, all layers
 belong to a group, so that sequence only contains layer groups.
 :
 :
 Is there something I'm missing/doing wrong, or is this a gap in the
 available script-fu methods?

The PDB functions already exist for handling layer groups, and  
Script-fu does not have any problem making use of these functions. The  
Python-fu extension has not yet been updated to handle groups (there  
is no 'group' class).

Unfortunately, Script-fu does not provide a way to create  
subdirectories so a direct scripting solution to Javier's problem is  
not available. Using Script-fu, each layer could be saved with the  
layer tree structure information embedded in the filenames. For example

exported_layers++panel_1++bar.png
exported_layers++panel_1++foo.png
exported_layers++panel_2++blargh.png
exported_layers++panel_2++foobar.png

A BASH script could then relocate these files to a suitable directory  
tree (or perhaps the animation tool could deal with the flat files  
directly, extracting the embedded information from the filenames).

Of course, writing a C plug-in would avoid these problems.

___
Gimp-developer mailing list
Gimp-developer@lists.XCF.Berkeley.EDU
https://lists.XCF.Berkeley.EDU/mailman/listinfo/gimp-developer


Re: [Gimp-developer] pdb.gimp_get_item_by_id(), or ids and layers and layer groups

2011-02-06 Thread Rob Antonishen
On Sun, Feb 6, 2011 at 10:30 AM,
saulgo...@flashingtwelve.brickfilms.com wrote:
 The PDB functions already exist for handling layer groups, and
 Script-fu does not have any problem making use of these functions. The
 Python-fu extension has not yet been updated to handle groups (there
 is no 'group' class).


I stand corrected.  When were they added into 2.7?

-Rob A
___
Gimp-developer mailing list
Gimp-developer@lists.XCF.Berkeley.EDU
https://lists.XCF.Berkeley.EDU/mailman/listinfo/gimp-developer