Inter script updates



Hello,

I want to put this question out there before diving into the code. I am
trying to write a python script which can update the active_display
multiple times within the same script. Basically an animation.

I have been experimenting with the different update methods
(add_update_all, update_connectitons, update_extends, flush) at
different levels (dia, dia.active_display(), dia.active_display().diagram).

Does anyone have suggestions on how I can get this working?

#Make an ellipse object blink

import dia
import time

def main(data,flags):
    """
    
    Arguments:
    - `data`:
    - `flags`:
    """
    d= dia.active_display().diagram
    layer = d.data.active_layer
    objects = layer.objects
    #find an ellipse object
    ellipse = None
    for obj in objects:
        if obj.type.name == "Standard - Ellipse":
            ellipse = obj
            break
    if not ellipse:
        #no ellipse was found don't do anything
        return
    
    for x in range(10):
        ellipse.properties['fill_colour'] = "red"
        print "RED"
        d.add_update_all()
        d.flush()
        time.sleep(1)
        ellipse.properties['fill_colour'] = "white"
        print "WHITE"
        d.add_update_all()
        time.sleep(1)


dia.register_action("Blinker","Blinker",
                    "/DisplayMenu/Dialogs/DialogsExtensionStart",
                    main)

Thank you in advance,
Philip




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