<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
</head>
<body text="#000000" bgcolor="#FFFFFF">
<p>Dear Andrew,</p>
<p>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:<br>
</p>
<p><tt>class DummyCallback:</tt><tt><br>
</tt><tt> def __init__(self, data):</tt><tt><br>
</tt><tt> self.data = data</tt><tt><br>
</tt><tt> def __call__(self, obj, event):</tt><tt><br>
</tt><tt> print(ev, self.data)</tt><tt><br>
</tt><tt><br>
</tt><tt>cb = DummyCallback(renwin)</tt><tt><br>
</tt><tt>interactor.AddObserver('LeftButtonPressEvent', cb)</tt></p>
<p>The last two lines can, of course, be abbreviated to:<br>
<tt>interactor.AddObserver('LeftButtonPressEvent', </tt><tt>DummyCallback(renwin))</tt><br>
</p>
<p>Best regards<br>
Oliver<br>
</p>
<p><br>
</p>
<div class="moz-cite-prefix">Am 11.11.2017 um 23:46 schrieb Andrew
Maclean:<br>
</div>
<blockquote type="cite"
cite="mid:CAHDsG9NYmxG-GqwOCZTPHavn0ThEC5CcBo-_OrSLZybC-h2hAg@mail.gmail.com">
<div dir="ltr">
<div class="gmail_default" style="font-size:small">Ok</div>
<div class="gmail_default" style="font-size:small">I have got
it.</div>
<div class="gmail_default" style="font-size:small">This works:</div>
<div class="gmail_default" style="font-size:small"><br>
</div>
<div class="gmail_default" style="font-size:small">
<pre style="color:rgb(0,0,0);font-family:"Courier New";font-size:9pt"><pre style="font-family:"Courier New";font-size:9pt"><span style="color:rgb(0,0,128);font-weight:bold">def </span>DummyFunc(<span style="color:rgb(128,128,128)">obj</span>, ev):
<span style="color:rgb(0,0,128)">print</span>(ev, DummyFunc.data)
DummyFunc.data = renwin
<span style="color:rgb(128,128,128);font-style:italic"># How do I pass my obj_2 ?
</span>interactor.AddObserver(<span style="color:rgb(0,128,128);font-weight:bold">'LeftButtonPressEvent'</span>, DummyFunc)
</pre></pre>
</div>
<div class="gmail_extra"><br>
</div>
<div class="gmail_extra">
<div class="gmail_default" style="font-size:small">David, you
may be able to explain this better than I can but I assume
this is what happens:</div>
<div class="gmail_quote">
<div class="gmail_default" style="font-size:small"> Here
we are adding a new attribute to DummyFunc. We can do this
because Python functions are in fact objects.</div>
<br>
</div>
<div class="gmail_quote">
<div class="gmail_default" style="font-size:small">This is
something totally strange to C++ programmers!</div>
<div class="gmail_default" style="font-size:small"><br>
</div>
<div class="gmail_default" style="font-size:small">What a
neat approach!</div>
<br>
</div>
<br>
</div>
</div>
</blockquote>
<br>
<pre class="moz-signature" cols="72">--
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: <a class="moz-txt-link-abbreviated" href="mailto:onatt@gmx.de">onatt@gmx.de</a>
</pre>
</body>
</html>