Next thing that happens is that it breaks because it can't find the startup file (python-startup.py). It turns out to be looking for it in /usr/local/share/dia even though I run it from the source script. Needs fixing, but till then I can do make install and have that work. Added warning for when that happens.
Next problem: It crashes in what looks like the pygtk init part. I'm a little worried as to whether it's finding the right pygtk, for 1.2 or 2.0. Can't see a place in the configure rule to check a version, and the python module seems to be called the same regardless of version. That's not very nice during a change-over period.
-- LarsClausen - 15 Jan 2003
Got some hints from the pygtk FAQ showed me how to force the right version, which is now done in python-startup.py.
The script shown above is put into ~/.dia/python/hello.py, and I restart Dia. Le Voila! A new menu item turns up in Dia. We're halfway there.
-- LarsClausen - 15 Jan 2003
Onwards and forwards and all that! Created a new script from hello, called courses.py, and took some code from debug_objects.py (which goes through the layers and objects). So far so good. After a little look at the API, I can go through nodes and check how many connections there are in each:
import sys,dia
def courses_callback(data, flags):
print "Updating nodes..."
for layer in data.layers :
for o in layer.objects :
connected = 0;
for c in o.connections :
connected = connected + len(c.connected)
if connected > 2 :
print str(o), " is big"
dia.register_callback("Courses Script",
"/Plugins/Courses",
courses_callback)
And this works! Now comes the tricky part -- changing size dependent on the number of connections.
Hit upon a snag in this part: If the plugin has a compile error, the python plugin just says it fails to load, no explanation. But aha! Since syntax checking at least is done before modules are loaded, I can just run the script on the command line: python courses.py. That gives me the error.
Now comes the problem: How to set a value in a property? For starters, I want to set the line width (a real). But it complains about a type error -- value is an object. I don't know how to make an object out of a real.
Besides, I don't know if this fits into the undo system, I see no traces of it.
|