Re: Inter script updates
- From: Hans Breuer <hans breuer org>
- To: discussions about usage and development of dia <dia-list gnome org>
- Subject: Re: Inter script updates
- Date: Thu, 07 May 2009 22:22:48 +0200
At 07.05.2009 14:46, Philip Cavaco wrote:
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?
Given that display drawing is done in idle update your blinking needs allow
idle to happen. Updated script attached.
Hans
-------- Hans "at" Breuer "dot" Org -----------
Tell me what you need, and I'll tell you how to
get along without it. -- Dilbert
import dia
import time
import gobject
class Blinker :
def __init__ (self, d, e, i) :
self.repeats = i
self.dia = d
self.ell = e
def blink (self) :
n = self.repeats
self.repeats -= 1
# requeue this handler
if n % 2 == 0 :
self.ell.properties['fill_colour'] = "red"
else :
self.ell.properties['fill_colour'] = "white"
self.dia.add_update_all()
self.dia.flush()
return n > 0
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
b = Blinker(d, ellipse, 10)
gobject.timeout_add(250, b.blink)
dia.register_action("Blinker","Blinker",
"/DisplayMenu/Dialogs/DialogsExtensionStart",
main)
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]