How can I save a DiagramData to a dia file in the python plug-in?



Hi -

If I have a DiagramData object (but not a Diagram object) in the python plugin, is there a simple way to export that DiagramData out to a .dia file?


The context is this: I have an export filter that I've written using the python plug-in. In the "normal operation" mode, everything is working fine and I get an export to the format in question. What I was hoping to do is to add some error reporting such that if the input Dia diagram had a "semantic error" (in terms of the semantics of my diagrams), then I could put out a new Dia diagram which was identical to the original but had the offending object marked (e.g. by coloring it red). Since this is all part of an export filter, I have the DiagramData through the interface of the begin_render() method, but I don't have a Diagram object.


I did try a few things:

My first thought was to get the Diagram object from dia.diagrams(), but that turned out to be empty when I ran the filter from the command line as 'dia -t foo bar.dia'.

My second thought was to create a new Diagram object via dia.new(), but I couldn't find a way to use my existing DiagramData object as the superclass instance - it doesn't seem like dia.new() takes a DiagramData as an argument, and I couldn't figure out a way to set my newDiagram.data to my existing DiagramData from begin_render() after the fact.

My third thought was to try to call the existing export filter for dia files directly, but I couldn't figure out how to get a filter instance in python. (I saw that in bindings/test.py there were references to dia.filter_guess_export_filter()', but when I tried to invoke that function through the Python Console dialog I got a missing attribute error - not part of the python API, I guess.)

My fourth thought was to bypass the passed in DiagramData object and instead use dia.load() to load a copy of the original input diagram directly. This works (since begin_render() also gives me the output filename and in my particular use case I can infer the full path of the input file from the output filename and from there make a copy, dia.load() it, modify object colors, save it, and so on), but it feels sort of roundabout and the input-file finding is fragile.



So, any advice on a correct and robust way to do this?

Thanks.

Dan


P.S. This was all attempted with Dia 0.97.1 and also with the latest from the git repository (with python and swig included as described at http://dia-installer.de/howto/compile_msvc/index.html) on Ubuntu Linux 11.10.



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]