<div dir="ltr"><div class="gmail_default" style="font-size:small">Hi,</div><div class="gmail_default" style="font-size:small"><br></div><div class="gmail_default" style="font-size:small">As promised, I did an example, please see:</div><div class="gmail_default"><a href="https://lorensen.github.io/VTKExamples/site/Python/Interaction/CallBack/" target="_blank">https://lorensen.github.io/<wbr>VTKExamples/site/Python/<wbr>Interaction/CallBack/</a> </div><div class="gmail_default">and</div><div class="gmail_default"> <a href="https://lorensen.github.io/VTKExamples/site/Cxx/Interaction/CallBack/">https://lorensen.github.io/VTKExamples/site/Cxx/Interaction/CallBack/</a><br></div><div class="gmail_default"><br></div><div class="gmail_default" style="font-size:small">Also look at:</div><div class="gmail_default"><a href="https://lorensen.github.io/VTKExamples/site/Python/VisualizationAlgorithms/StreamlinesWithLineWidget/" target="_blank">https://lorensen.github.io/<wbr>VTKExamples/site/Python/<wbr>VisualizationAlgorithms/<wbr>StreamlinesWithLineWidget/</a><br></div><div class="gmail_default"><br></div><div class="gmail_default">Thanks to Bill Lorensen for some solving markdown issues in the case of CallBack.</div><div class="gmail_default"><br></div><div class="gmail_default">Please feel free to improve/correct the examples.</div><div class="gmail_default"><br></div><div class="gmail_default">Regards</div><div class="gmail_default">   Andrew</div><div class="gmail_default"><br></div><div class="gmail_extra"><br><div class="gmail_quote">On Mon, Nov 13, 2017 at 1:26 AM, Oliver Natt <span dir="ltr"><<a href="mailto:onatt@gmx.de" target="_blank">onatt@gmx.de</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
  
    
  
  <div 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('<wbr>LeftButtonPressEvent', cb)</tt></p>
    <p>The last two lines can, of course, be abbreviated to:<br>
      <tt>interactor.AddObserver('<wbr>LeftButtonPressEvent', </tt><tt>DummyCallback(renwin))</tt><br>
    </p>
    <p>Best regards<br>
      Oliver<br>
    </p><span class="">
    <p><br>
    </p>
    <div class="m_6558941804065284527moz-cite-prefix">Am 11.11.2017 um 23:46 schrieb Andrew
      Maclean:<br>
    </div>
    <blockquote type="cite">
      <div dir="ltr">
        <div style="font-size:small">Ok</div>
        <div style="font-size:small">I have got
          it.</div>
        <div style="font-size:small">This works:</div>
        <div style="font-size:small"><br>
        </div>
        <div 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">'<wbr>LeftButtonPressEvent'</span>, DummyFunc)
</pre></pre>
        </div>
        <div class="gmail_extra"><br>
        </div>
        <div class="gmail_extra">
          <div 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 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 style="font-size:small">​This is
              something totally strange to C++ programmers!</div>
            <div style="font-size:small"><br>
            </div>
            <div style="font-size:small">What a
              neat approach!​</div>
            <br>
          </div>
          <br>
        </div>
      </div>
    </blockquote>
    <br>
    </span><span class="HOEnZb"><font color="#888888"><pre class="m_6558941804065284527moz-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="m_6558941804065284527moz-txt-link-abbreviated" href="mailto:onatt@gmx.de" target="_blank">onatt@gmx.de</a>
</pre>
  </font></span></div>

</blockquote></div><br><br clear="all"><div><br></div>-- <br><div class="gmail_signature" data-smartmail="gmail_signature">___________________________________________<br>Andrew J. P. Maclean<br><br>___________________________________________</div>
</div></div>