#!/usr/bin/env python

from gimpfu import *

def python_fu_line_test(img, layer):
    exists, x1, y1, x2, y2 = pdb.gimp_selection_bounds(img)
    if not exists :
        return

    # Stroke the current selection, to show where it was
    # before deleting it:
    pdb.gimp_edit_stroke(layer)

    pdb.gimp_selection_none(img)

    #
    # Draw the line first.
    # But don't go quite all the way to the end, because that
    # would make a rounded tip where the arrow point should be.
    #
    strokes = [ x1, y1, x2, y2 ]

    pdb.gimp_paintbrush(layer, 0, 4, strokes, 0, 0)

    # Restore the old selection.
    # Doesn't work in 2.6.
    # pdb.gimp_image_select_item(img, CHANNEL_OP_REPLACE, savesel)

register(
         "python_line_test",
         "Test of gimp_paintbrush lines",
         "Test of gimp_paintbrush lines",
         "Akkana Peck", "Akkana Peck",
         "2014",
         "<Image>/Filters/Line Test",
         "*",
         [
         ],
         [],
         python_fu_line_test)

main()
