Defining a line with its endpoints

I am using a Python script to calculate the end points of a line segment, (x1, y1) and (x2, y2). I then want to change the endpoints of a line on my user’s window to equal those two points. How can I change the coordinates of a line segment’s endpoints via Python script (in the Developer I can edit the endpoints and stipulate their coordinates, but I want to do it programatically)?

Any guidance would be helpful. Thanks,


Hi Cas,

I had a look for you and couldn’t work out a simple way to change a standard line, but you could have a look at the paintable canvas.

Here is a simple example of a line that you can tie to your dynamic properties. You would have to define custom properties on the paintable canvas component for ‘myX’, ‘myY’ which you can then update.

This code would go in the canvas’s event handler for paint/repaint. When you create a new canvas it comes pre-filled with a pump example which you can have a look at too.

[code]from java.awt.geom import Line2D

g =
line = Line2D.Float(0, 100, event.source.myX, event.source.myY)

Hope this is of help.


The paintable canvas solution is really going to be the best way to go. If there is some specific reason this solution won’t work for you let me know.