Quoting Ram Yalamanchili <ramyinc@...>:
> I'm using diacanvas for an OSS colloboration tool. I haven't found much help
> in the python extension documentation, as its very flaky, so hoping someone
> here can answer a few questions.
> First, I am trying to draw a variety of stuff on the canvas, like Lines,
> Rectangles, Square, circle, etc..
diacanvas.shape.Path can be used for rectangles: it has a cyclic
connects the first and last point together.
Circes and ellipses can be made with diacanvas.shape.Ellipse.
diacanvas.CanvasLine is a CanvasItem implementing a line. It uses shapes
(drawing primitives) from the diacanvas.shape package. Same for CanvasBox
(which uses diacanvas.shape.Path to create a rectangle.
There is an implementation for an out-of-the-box circle or ellipse
> But, so far the only parameter to pass canvas_view.set_tool i could find
> dia.canvasLine for a line and dia.canvasBox for a rectangle. How can i make
> a square, circle, ellipse? I went through the documentation hoping ot find
> something for a python interface, but no luck :/ I read about the DiaShape,
> anyone can point or give some demo code if i have to build my own diashape
> tool in python?
You can not build your own DiaShape classes. You can however, build your own
CanvasItem classes which draw more complex objects using existing shapes.
> Second, I want to keep track of all objects being added/modified to the
> canvas. So, I wrote the following class which calls PlacementTool and looks
> for a button_releave_event. At this point I will know the new object
> created. But I'm doubtful it this is the most elegant way. Any ideas on how
> i can best keep track of objects created and the modifications done to them?
> Also, this doesn't take care of modifications done to existing objects. I'm
> still not sure how to do this. Is there anyway I can iterate on all the
> objects present on the canvas?
You can add an event handler to the DiaPlacementTool. This event
handler can do
whatever it likes with the item.
Hope this helps. Have a look at the test-canvas.py script and Gaphor
(http://gaphor.sf.net). Check the gaphor CVS repository and look at
> class WBCanvasTool(pt.PlacementTool):
> def __init__(self, arg, **properties):
> super(self.__class__, self).__init__(arg, **properties)
> def do_button_release_event(self, view, event):
> print "Added item: ", self.new_object.type
> pt.PlacementTool.do_button_release_event(self, view, event)
> I call the tool creation as follows:
> self.brush_tool = WBCanvasTool(dia.CanvasLine, color=self.brush_color)
> thanks in advance!
> - Ram