At 19:57 16.07.04, [EMAIL PROTECTED] wrote:
[...]
One question for the group, is it possible to access alignment operations
via the python scripting?  I'd love to have a keybinding which would do
the equivalent of aligning 2 objects middle and center.  I often do this
in order to get boxes of text, I'll draw the object, draw the text centered,
then align center and middle (via many menu dives), finally group them.

If the scripting would allow me to automate this sort of action, or if
I've completely missed something and there's some easier way to do it
I'd love to find out.

See the attached script. Implementing some alignment is pretty easy (I think).
There is no need to implement some some "alignment ops" in the bindings [what ever this means ;]. Everything to accomplish the task was already there.
Only it is lacking the ability to undo at the moment ...


        Hans

import sys, dia

def center_objects (objs) :
        r = objs[0].bounding_box
        cx = (r.right + r.left) / 2
        cy = (r.bottom + r.top) / 2
        for o in objs[1:] :
                r = o.bounding_box
                (x, y) = o.properties["obj_pos"].value
                dx = (r.right + r.left) / 2 - cx
                dy = (r.bottom + r.top) / 2 - cy
                o.move (x - dx, y - dy)

def dia_objects_center_cb (data, flags) :
        grp = data.get_sorted_selected()
        if (len(grp) > 1) :
                center_objects (grp)
                data.update_extents ()
        dia.active_display().diagram.add_update_all()
        
dia.register_callback ("Center Objects", 
                       "<Display>/Objects/Center", 
                       dia_objects_center_cb)

-------- Hans "at" Breuer "dot" Org -----------
Tell me what you need, and I'll tell you how to
get along without it.                -- Dilbert
_______________________________________________
Dia-list mailing list
[EMAIL PROTECTED]
http://mail.gnome.org/mailman/listinfo/dia-list
FAQ at http://www.gnome.org/projects/dia/faq.html
Main page at http://www.gnome.org/projects/dia

Reply via email to