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

EXCITE_CONN = 8
INHIB_CONN = 9
CONN_TYPE = INHIB_CONN

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


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

Philip

----- 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:
Hello

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 
attach 
your script. You know - it is all open source ;)

      Hans

-------- 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
http://mail.gnome.org/mailman/listinfo/dia-list
FAQ at http://live.gnome.org/Dia/Faq
Main page at http://live.gnome.org/Dia





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