[vtkusers] SetClientData in python (David Gobbi)
andrew.amaclean at gmail.com
Wed Nov 15 23:25:45 EST 2017
As promised, I did an example, please see:
Also look at:
Thanks to Bill Lorensen for some solving markdown issues in the case of
Please feel free to improve/correct the examples.
On Mon, Nov 13, 2017 at 1:26 AM, Oliver Natt <onatt at gmx.de> wrote:
> Dear Andrew,
> Davids proposal ist great. However, it appears a bit strange to most
> programmers. I prefer for this purpose to make a new class which is a
> callable. I think, this makes the code more readable for most programmers
> since the data attribute is already initialized within the class itself.
> Your example would look like this:
> class DummyCallback:
> def __init__(self, data):
> self.data = data
> def __call__(self, obj, event):
> print(ev, self.data)
> cb = DummyCallback(renwin)
> interactor.AddObserver('LeftButtonPressEvent', cb)
> The last two lines can, of course, be abbreviated to:
> interactor.AddObserver('LeftButtonPressEvent', DummyCallback(renwin))
> Best regards
> Am 11.11.2017 um 23:46 schrieb Andrew Maclean:
> I have got it.
> This works:
> def DummyFunc(obj, ev):
> print(ev, DummyFunc.data)
> DummyFunc.data = renwin# How do I pass my obj_2 ?interactor.AddObserver('LeftButtonPressEvent', DummyFunc)
> David, you may be able to explain this better than I can but I assume
> this is what happens:
> Here we are adding a new attribute to DummyFunc. We can do this
> because Python functions are in fact objects.
> This is something totally strange to C++ programmers!
> What a neat approach!
> Oliver Natt,
> Jägerstraße 26b
> 90451 Nürnberg
> Phone: +49 (0) 9 11 - 71 58 71 40
> Mobile +49 (0) 1 76 - 20 82 27 38
> E-Mail: onatt at gmx.de
Andrew J. P. Maclean
-------------- next part --------------
An HTML attachment was scrubbed...
More information about the vtkusers