Re: [Gimp-developer] Optimizing border-like selection in python

2010-09-24 Thread Jerry Baker
  Calculating a new selection from the current selection would be faster 
(I think):

def create_border(image, selection_type='rectangle', size=1):
 is_selection, x1, y1, x2, y2 = pdb.gimp_selection_bounds(image)

 if is_selection:
 if size  1:
 size = 1
 if selection_type =='rectangle':
 pdb.gimp_rect_select(image, x1+size, y1+size, 
(x2-x1)-(size*2), (y2-y1)-(size*2), CHANNEL_OP_SUBTRACT, False, 0)
 elif selection_type == 'ellipse':
 pdb.gimp_ellipse_select(image, x1+size, y1+size, 
(x2-x1)-(size*2), (y2-y1)-(size*2), CHANNEL_OP_SUBTRACT, True, False, 0)
 else:
 gimp.message(Please make a selection...)

def test_plugin(image, drawable):
 image.undo_group_start()

 create_border(image)# A rectangular selecion with default 
settings...
 #create_border(image, selection_type='ellipse', size=3) # Or 
Ellipse with custom settings...

 # Fill
 pdb.gimp_edit_fill(drawable, 0)
 pdb.gimp_selection_none(image)

 image.undo_group_end()

On 09/24/2010 10:19 AM, Ofnuts wrote:
Hi,

 My code needs to do a one-pixel-wide selection, at distance x from the
 current selection.  This looks a lot like a border selection except that
 the border selection creates at best a two-pixel wide ribbon and I only
 want one (but if I'm wrong, please tell me how to :-)

 So far my code goes like this:

 # Selects pixels that are between x and x+1 pixels from
 # the original selection. Bumping the selection by one
 # each time doesn't work, a small circle degenerates into
 # a square with rounded corners instead of a big circle.
   def select_ribbon(self,image,selection,dist):
   pdb.gimp_selection_load(selection)
   pdb.gimp_selection_grow(image,dist+1)
   outer=pdb.gimp_selection_save(image)
   pdb.gimp_selection_load(selection)
   pdb.gimp_selection_grow(image,dist)
   inner=pdb.gimp_selection_save(image)
   pdb.gimp_channel_combine_masks(outer,inner,CHANNEL_OP_SUBTRACT,0,0)
   pdb.gimp_selection_load(outer)
   image.remove_channel(outer)
   image.remove_channel(inner)

 That works, but can be slow (especially since it's at the core of a
 loop). Is there any better way? Or useless code to jettison?

 Next improvement is to create a 3-pixels selection and feather it one
 pixel. Anything to be wary of?

 --
 Ofnuts

 ___
 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] Optimizing border-like selection in python

2010-09-24 Thread Jerry Baker
  Ahh... autoformatting... this should be easier to read... (sorry)

def create_border(image, selection_type='rectangle', size=1):
 is_selection, x1, y1, x2, y2 = pdb.gimp_selection_bounds(image)

 if is_selection:
 if size  1:
 size = 1
 if selection_type =='rectangle':
 pdb.gimp_rect_select(image,
 x1+size,
 y1+size,
 (x2-x1)-(size*2),
 (y2-y1)-(size*2),
 CHANNEL_OP_SUBTRACT,
 False,
 0)
 elif selection_type == 'ellipse':
 pdb.gimp_ellipse_select(image,
 x1+size,
 y1+size,
 (x2-x1)-(size*2),
 (y2-y1)-(size*2),
 CHANNEL_OP_SUBTRACT,
 True,
 False,
 0)
 else:
 gimp.message(Please make a selection...)

def test_plugin(image, drawable):
 image.undo_group_start()

 # A rectangular selecion with default settings...
 create_border(image)

  # Ellipse with custom settings... Uncomment to activate
 #create_border(image, selection_type='ellipse', size=3)

 # Fill
 pdb.gimp_edit_fill(drawable, 0)
 pdb.gimp_selection_none(image)

 image.undo_group_end()

On 09/24/2010 06:18 PM, Jerry Baker wrote:
Calculating a new selection from the current selection would be faster
 (I think):

 def create_border(image, selection_type='rectangle', size=1):
   is_selection, x1, y1, x2, y2 = pdb.gimp_selection_bounds(image)

   if is_selection:
   if size  1:
   size = 1
   if selection_type =='rectangle':
   pdb.gimp_rect_select(image, x1+size, y1+size,
 (x2-x1)-(size*2), (y2-y1)-(size*2), CHANNEL_OP_SUBTRACT, False, 0)
   elif selection_type == 'ellipse':
   pdb.gimp_ellipse_select(image, x1+size, y1+size,
 (x2-x1)-(size*2), (y2-y1)-(size*2), CHANNEL_OP_SUBTRACT, True, False, 0)
   else:
   gimp.message(Please make a selection...)

 def test_plugin(image, drawable):
   image.undo_group_start()

   create_border(image)# A rectangular selecion with default
 settings...
   #create_border(image, selection_type='ellipse', size=3) # Or
 Ellipse with custom settings...

   # Fill
   pdb.gimp_edit_fill(drawable, 0)
   pdb.gimp_selection_none(image)

   image.undo_group_end()

 On 09/24/2010 10:19 AM, Ofnuts wrote:
 Hi,

 My code needs to do a one-pixel-wide selection, at distance x from the
 current selection.  This looks a lot like a border selection except that
 the border selection creates at best a two-pixel wide ribbon and I only
 want one (but if I'm wrong, please tell me how to :-)

 So far my code goes like this:

 # Selects pixels that are between x and x+1 pixels from
 # the original selection. Bumping the selection by one
 # each time doesn't work, a small circle degenerates into
 # a square with rounded corners instead of a big circle.
def select_ribbon(self,image,selection,dist):
pdb.gimp_selection_load(selection)
pdb.gimp_selection_grow(image,dist+1)
outer=pdb.gimp_selection_save(image)
pdb.gimp_selection_load(selection)
pdb.gimp_selection_grow(image,dist)
inner=pdb.gimp_selection_save(image)

 pdb.gimp_channel_combine_masks(outer,inner,CHANNEL_OP_SUBTRACT,0,0)
pdb.gimp_selection_load(outer)
image.remove_channel(outer)
image.remove_channel(inner)

 That works, but can be slow (especially since it's at the core of a
 loop). Is there any better way? Or useless code to jettison?

 Next improvement is to create a 3-pixels selection and feather it one
 pixel. Anything to be wary of?

 --
 Ofnuts

 ___
 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

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


Re: [Gimp-developer] Python plugin registration: choosing between a closed set of strings

2010-09-07 Thread Jerry Baker
 If your 'variants' are similar you could just use PF_OPTION and change 
your variables/options with an if/else...


Or you can define different functions and register them separately in 
the same file. The 'palette-to-gradient.py' file in the source does 
this... 
http://git.gnome.org/browse/gimp/tree/plug-ins/pygimp/plug-ins/palette-to-gradient.py


On 09/07/2010 10:53 AM, Ofnuts wrote:

   I'd like the user to select a variant of a plugin (among 3 to 5
ones). I would normally do so with a R/O drop-down box displaying the
names. Is there a way to do so using the right type of parameter type in
the registration (couldn't find it)?

Otherwise what would be the recommended way to do it? Define separate
plugins for each variant?

Btw, can I define several plugins (ie, register() calls) in one single
Python file? Or what is the best way (ie, easier to install for the
end-user) to share code between Python plugins?

--
Ofnuts

___
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] Scripting-Questions

2010-08-22 Thread Jerry Baker
  Console Example:
# Get Active Image
  image = gimp.image_list()[0]

# Load an image into a layer
  loaded_layer = pdb.gimp_file_load_layer(image, 
path/to/other_image.jpg)

# Add loaded layer to image
  image.add_layer(loaded_layer, 0)

On 08/22/2010 07:53 AM, oli...@first.in-berlin.de wrote:
 Hi Jerry,

 thanks for your hints.

 Another question: I want to use gimp-file-load-layer and don't
 know how to access it.

 Any idea?

 Ciao,
 Oliver


 On Sat, Aug 21, 2010 at 06:23:04PM -0400, Jerry Baker wrote:
Hi Oliver,

 1) Insert a layer at lowest position...
 The image.add_layer method position argument is what you need to
 specify. 0 places a new layer at the top, 1 would be under the first
 layer, 2 under the second layer, etc...
 image.layers give you the list of layers in the image. Use
 len(image.layers) to place it at the bottom...

 Console example:
 # Get Active Image
 image = gimp.image_list()[0]

 # Create a new layer
 new_layer = gimp.Layer(image, My New Layer, image.width,
 image.height, RGBA_IMAGE,100, NORMAL_MODE)
 # Add Layer Lowest Position
 image.add_layer(new_layer, len(image.layers))

 2) Fit canvas to layers
 You'll want to use: gimp-image-resize-to-layers

 Console:
 image = gimp.image_list()[0]
 pdb.gimp_image_resize_to_layers(image)
 3) The current documentation at
 http://www.gimp.org/docs/python/index.html and the pdb is about the
 best we gimp-python users have. There are a few sites out there with
 some posts, but everything is pretty dated. I'm currently picking
 away at a full tutorial and complete updated reference which I'll
 post here when I get it completed. I'm about 75% completed with it.


 On 08/21/2010 05:08 PM, oli...@first.in-berlin.de wrote:
 1)image.add-layer: how can I insert at the lowest position?

 2)   how can I script Fit canvas to layers?

 3)   gimp.* / pdb.* and so on: which names using for Python, when
   looking at the procedure browser?

   For example: i could not find out, how to call
   gimp-file-load-layer
   I tried with gimp.*  with pdb.*  without that also


 The procedure browser seems to be good for scheme-users,
 but for Python this is just a hint, and needs permanently
 dabbling around.


 Where can I find better documentatoion for Python-scripting?


 Ciao,
 Oliver
 ___
 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

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


Re: [Gimp-developer] Scripting-Questions

2010-08-21 Thread Jerry Baker

  Hi Oliver,

1) Insert a layer at lowest position...
The image.add_layer method position argument is what you need to 
specify. 0 places a new layer at the top, 1 would be under the first 
layer, 2 under the second layer, etc...
image.layers give you the list of layers in the image. Use 
len(image.layers) to place it at the bottom...


Console example:
 # Get Active Image
 image = gimp.image_list()[0]

 # Create a new layer
 new_layer = gimp.Layer(image, My New Layer, image.width, 
image.height, RGBA_IMAGE,100, NORMAL_MODE)


 # Add Layer Lowest Position
 image.add_layer(new_layer, len(image.layers))


2) Fit canvas to layers
You'll want to use: gimp-image-resize-to-layers

Console:
 image = gimp.image_list()[0]
 pdb.gimp_image_resize_to_layers(image)

3) The current documentation at 
http://www.gimp.org/docs/python/index.html and the pdb is about the best 
we gimp-python users have. There are a few sites out there with some 
posts, but everything is pretty dated. I'm currently picking away at a 
full tutorial and complete updated reference which I'll post here when I 
get it completed. I'm about 75% completed with it.



On 08/21/2010 05:08 PM, oli...@first.in-berlin.de wrote:

1)image.add-layer: how can I insert at the lowest position?

2)   how can I script Fit canvas to layers?

3)   gimp.* / pdb.* and so on: which names using for Python, when
  looking at the procedure browser?

  For example: i could not find out, how to call
  gimp-file-load-layer
  I tried with gimp.*  with pdb.*  without that also


The procedure browser seems to be good for scheme-users,
but for Python this is just a hint, and needs permanently
dabbling around.


Where can I find better documentatoion for Python-scripting?


Ciao,
Oliver
___
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] remove layer should not force you to last selected layer

2010-03-05 Thread Jerry Baker
I've always hated the way that worked, I've got a script that deletes 
the active layer, then sets the layer underneath it to active if anyone 
wants to use it...

#!/usr/bin/env python
# -*- coding: utf-8 -*-
#
#   delete-layer.py - Version 1.0
#   Copyright (C) 07/11/2008 by Jerry Baker jba...@gimpthoughts.com
#   www.gimpthoughts.com
#
#   Deletes active layer then selects the layer underneath.
#
#   This program is free software; you can redistribute it and/or modify
#   it under the terms of the GNU General Public License as published by
#   the Free Software Foundation; either version 2 of the License, or
#   (at your option) any later version.
#
#   This program is distributed in the hope that it will be useful,
#   but WITHOUT ANY WARRANTY; without even the implied warranty of
#   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
#   GNU General Public License for more details.
#
#   You should have received a copy of the GNU General Public License
#   along with this program; if not, write to the Free Software
#   Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 
02111-1307, USA.

# --- Imports
from gimpfu import *

gettext.install(gimp20-python, gimp.locale_directory, unicode=True)

def delete_layer(image, drawable):
 image.undo_group_start()

 layer_index = image.layers.index(image.active_layer)
 if layer_index == (len(image.layers)-1):
 layer_index -= 1
 image.remove_layer(image.active_layer)
 if layer_index = 0:
 image.active_layer = image.layers[layer_index]

 image.undo_group_end()

register(
 delete-layer,
 N_(Deletes active layer then selects the layer underneath.),
 Deletes active layer then selects the layer underneath.,
 Jerry Baker,
 Jerry Baker,
 07/11/2008,
 N_(Delete Active Layer),
 RGB*, GRAY*, INDEXED*,
 [
 # --- Parameters
 (PF_IMAGE, image, _(Image), None),
 (PF_DRAWABLE, layer, _(Drawable), None),
 ],
 [
 # --- Results
 ],
 delete_layer,
 menu=Image/_Layer,
 domain=(gimp20-python, gimp.locale_directory)
 )

main()




On 03/05/2010 02:22 PM, Martin Nordholts wrote:
 On 03/05/2010 03:20 AM, Luiz Felipe Moraes Pereira wrote:

 Hi again, the original discussion is in the link below:
 https://bugzilla.gnome.org/show_bug.cgi?id=611758

 I was advised to present this idea here, what do you think?

 Also I do not mind much about not having a selected layer after
 the deletion of a layer. But the forced viewer scroll down( or up ),
 depending of the last selected layer is a problem.
  
 To me, having the layers dialog scroll to a seemingly random place after
 deleting a layer is a clear usability problem. A user should not have to
 worry about what layer that was previously selected when deleting a layer.

/ Martin




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


[Gimp-developer] Toolbox UI/Docking

2010-02-22 Thread Jerry Baker
For discussion...

https://bugzilla.gnome.org/show_bug.cgi?id=610344

Add docking capabilities to the toolbox so it would be possible to dock 
another
dialog to the top, bottom, left or right of the toolbox or dock the 
toolbox on
the top, bottom, left, or right of another dialog window. (In 
multi-window mode
and single-window mode)

 From an irc discussion:
(08:44:36 AM) jbaker: speaking of ui, is it possible to move the toolbox 
to the
right of the image in sw mode ?
(08:48:33 AM) guiguru: jbaker: should be
(08:48:55 AM) guiguru: it is free tear off and docking in swm
(08:50:14 AM) jbaker: guiguru: i think the toolbox is a different widget 
than
the other dialogs, as far as I can tell there is really no place to grab 
it...
(08:50:43 AM) guiguru: it is different, but that needs to be fixed then
(08:51:23 AM) Death: Grabbing wilber would make sense for me...


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


[Gimp-developer] Adding plug-in-paths to python path

2010-02-03 Thread Jerry Baker
I'm trying to figure out the best way to add all of the paths listed in 
gimprc under 'plug-in-path' to the python path in order to properly 
support the python package/module structure.
http://docs.python.org/tutorial/modules.html#packages

Adding this would allow better organization of larger python plugins and 
import statements would work correctly.

As far as I can tell there is three problems to solve.

 1) Getting the directories added to sys.path
 2) When gimp scans directories for plugins to register, it'll also 
need to search through all of the folders
 3) When scanning the files, ignore the files without the register 
function. (right now is outputs a warning)

Right now I'm just trying to solve the first problem.
The first option is to add the following code(or something similar) to 
gimpfu.py and gimpplugin.py
Most plugins are going to use gimpfu, but adding it in both spots would 
work for those that just use gimpplugin.

import sys
try:
 gimprc_file = open(gimp.personal_rc_file(gimprc), r)
 for line in gimprc_file:
 if line.startswith((plug-in-path):
 for path in line.split('')[1].split(':'):
 sys.path.append(path)
except:
 pass

This approach works, but the same code is in two different spots.

2nd option that I came up with is to make the change in gimpmodule.c in 
the initgimp function. Having the change in this module would work 
everywhere.
I'm not a C person so my best attempt so far is something along the lines of

 PyRun_SimpleString(import sys);
 Loop paths here
 PyRun_SimpleString(sys.path.append('looped_paths'));

I tried using gimp_gimprc_query(plug-in-path) to get the paths, but 
calling this in initgimp causes the 'gimp wire read' error.
So I figure using this approach, I'll have to load and parse the gimprc 
manually.

I would really like to see this functionality added to trunk so if you 
have any suggestions on what would be an acceptable solution I'd really 
appreciate it...

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


Re: [Gimp-developer] some current 2.7 issues

2009-12-07 Thread Jerry Baker
Liam R E Quin wrote:
 Some nits ,some -- especially (2) and (4) -- bigger than others...

 (1) The file-export dialogue action button says save, not export
 (sounds really minor but given the save/export changes, can actually
 be confusing)

 (2) The default save location should not be ~/Documents in the case that
 a file has been imported - it should default to the directory
 containing the imported image (see the spec)

 (3) in most programs, save mirrors open, and export mirrors
 import - if GIMP is erally an XCF editor, open should work
 for .xcf and .xcf.gz files, and File-import should be there for
 the rare 99% case when you want e.g. to touch up a photo, and
 open a non-xcf file. So, please add file-import, with import
 as the label on the dialogue box. (I think?)

 (4) images interfere with each other. E.g. open a colour image, and a
 grayscale one, and watch the colour one turn to grayscale whenever
 the grayscae one becomes active... and the grey one goes to RGB
 seemingly at random, too.  This and (2) are making it difficult
 to use GIMP right now.

 (5) I'm not sure that the image title bar is up to spec at all times
 with respect to imported/exported. At any rate the little language
 for setting the image title in preferences probably needs to be
 expanded to include
 . the imported image name  (separately) folder
 . the last exported filename  (separately) folder
 . the (imported) / (exported) string

 (6) There needs to be indication in the title bar (by
 default) of when an image has been exported/overwritten, not only
 immediately, but for the rest of the session, e.g. as
   *warmsock (*exported)
   warmsock (*exported)
   warmsock (exported)
   *warmsock (exported)
 depending on whether the image has been changed since last saved or
 exported respectively.  Not doing this means that people will lose
 work.  There have already been requests to get rid of the file has
 not been saved message when you close the image, since in most (no
 all) workflows it's bogus, as the exported image is the final
 product.  So, people get used to ignoring it even when they have
 not exported an image, and right now you can't esaily tell if you
 did or not.

 (7) Martin is not allowed to wear shoes until (2) and (4) are fixed!

 (8) The curves and levels dialogues look really snazzy in full-screen
 mode, composited against the layer.  Some problems with this
 (obviously incomplete) code...
 . no title on the doc, so may not always be obvious what it is
 . no way to drag the dock to a different part of the image
 . once docks are composited they stay that way, even after you
   leave full-screen mode. But they are not cmposited _before_ you
   go into full-screen mode, so I think it's a bug.


 I can file bugzilla entries for these but probably not for a few days.

 Liam


 ___
 Gimp-developer mailing list
 Gimp-developer@lists.XCF.Berkeley.EDU
 https://lists.XCF.Berkeley.EDU/mailman/listinfo/gimp-developer
   
Not sure about script-fu and the others, but the python code will have 
to be adjusted to handle the new layer groups.

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


[Gimp-developer] Workflow Tips ?

2009-11-20 Thread Jerry Baker
I keep running into the limits of gimp python so I've finally decided to 
start learning C. In python the development process is a lot faster. 
Basically Edit File  Save  Run. - There are a lot more steps 
involved on the C side...

I was wondering if anyone could give me some tips for speeding the Edit 
  Compile  Install process up and improving my workflow...
___
Gimp-developer mailing list
Gimp-developer@lists.XCF.Berkeley.EDU
https://lists.XCF.Berkeley.EDU/mailman/listinfo/gimp-developer