Provide a python script to dia on the command line



Hello list,

while exploring ways to generate beautiful(TM) PDFs from dia diagrams (cf. https://mail.gnome.org/archives/dia-list/2014-August/msg00006.html), I noticed there isn't an acceptable way of telling dia to execute a python script from the command line.

Working with the python console a little more, I came to lament this lack of ability a little more. Working with plain XML is not always easy and never pretty, so I set out to give dia the ability to run python scripts. I am done with my initial development and I would like to offer this for discussion, before git HEAD moves on and I have to redo some of my implementation.

I can "dia -i foo.py" to make dia execute foo.py. The script is executed _after_ all modules have been loaded, right before handle_all_diagrams() is called. (This allows using dia's python capabilities to modify diagrams right before they are exported.)

I'm having "dia_is_interactive = FALSE" if the -i option is provided, however I already have half a mind to remove this limitation, but there are implications to consider first.

I use this feature to, ...
... select some objects from a diagram and copy them to their own diagram (for export and submodels), ... change fonts and colors ( of selections of objects) in all diagrams at once,
... put/extract meta information and comments from UML objects, and
... synchronise UML objects used in multiple diagrams.

These are not necessarily new features, but it I get more use out of dia with them.

To implement this feature, I ...

... split off the part where the python plug-in's dia_plugin_init() runs 'python-startup.py' into its own function run_script_oneshot(). ... made the python plug-in's dia_plugin_init() use run_script_oneshot() to avoid code redundancy. ... moved the definition of struct _PluginInfo from lib/plug-ins.c to lib/plug-ins.h, because I need this struct in app/app_procs.c. ... modified app/app_procs.c app_init() to include the -i option and stores the provided filename in a local variable python_script. ... appended python_script to the list of variables that triffer dia_is_interactive=FALSE ... added a block if(python_script) which checks if the python plug-in is loaded, and does run_script_oneshot(python_script) when sensible.

I am not certain how to feel about moving a struct definition into a .h file and I want to be able to pass the GList "files" to run_script_oneshot() and the python interpreter before this is done. Then I also consider creating patch sets to put as enhancement into the bugtracker. For now, there is one big patch attached.

What do you people think about this feature?

Cheers

Martin

Attachment: dia_python_cli.patch
Description: Text Data



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