Re: Changing objects layer through Python

That did the trick. Now I am stuck on a way to update the image with all
changes I made. The script completely connects all "Standard - Ellipse"
within the currently selection. The connections do not appear unless I
manually move each Ellipse in the diagram. I have tried using
update_extents, add_update_all, and update_connections but none seem to
do what I need.

Here is the script

# This function completely connects the given group of "Standard - Ellipse" 
# objects with "Standard - Arc" objects with open circles (ending 9).

import dia


def complete_connect(data,flags):
    - `data`:
    - `flags`:
    d = dia.active_display().diagram
    layer =
    grp = d.get_sorted_selected()
    connType = dia.get_object_type("Standard - Arc")
    for o in grp:
        if == 'Standard - Ellipse':
            for target in grp:
                if == 'Standard - Ellipse' and not o ==
                    #Connect to all other nodes except itself
                    temp_conn, h1, h2 = connType.create(0,0)
          ['end_arrow'].value.type =
                    layer.add_object(temp_conn, 0)
    #Apply changes to display

#Create a menu item in dia to call the complete_connect function
dia.register_action ("CompleteConnect", "Complete Connect", 


----- Original Message -----
From: Hans Breuer <hans breuer org>
Date: Sunday, March 15, 2009 3:45 pm
Subject: Re: Changing objects layer through Python
To: discussions about usage and development of dia <dia-list gnome org>

At 15.03.2009 11:31, Philip Cavaco wrote:

Is it currently possible to bring objects up in front of all other
objects through the python interface. 
Just from reading the (pydia-layer.c and layer.c) code I assume the 
following to work:

      n = len(layer.objects)
      layer.remove_object (obj)
      # we could as well choose a 'big enough' number
      layer.add_object (obj, n)

Alternatively is it possible to
push an object behind another when it is created.

      layer.add_object (obj, 0)

should do the trick. But again I have not tried it. I'm just 
deducing from 
reading the source.

If this is possible how do I do it.

If the above does not work, I may be looking in more detail if you 
your script. You know - it is all open source ;)


-------- 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
dia-list gnome org
FAQ at
Main page at

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