<div class="gmail_quote"><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex;"><br>
<br>
Now if I could just turn that into a COM object (seriously, I&#39;m trying to figure<br>
out how to call movingballs2.py, a Vpython script, from Visual FoxPro).<br>
<br></blockquote><div><br></div><div><br></div><div>OK, I turned it into a COM object, pretty mickey mouse, yet instructive (at least to me):</div><span class="Apple-style-span" style="font-family: arial, sans-serif; font-size: 13px; border-collapse: collapse; "><div class="gmail_quote">
<span class="Apple-style-span" style="font-family: arial, sans-serif; font-size: 13px; border-collapse: collapse; "><br></span></div>VFP = Visual FoxPro and in the middle you&#39;ll see how I&#39;m in the interactive shell of that language, and creating this Python object.</span></div>
<div class="gmail_quote"><span class="Apple-style-span" style="font-family: arial, sans-serif; font-size: 13px; border-collapse: collapse; "><br></span></div><div class="gmail_quote"><span class="Apple-style-span" style="font-family: arial, sans-serif; font-size: 13px; border-collapse: collapse; ">Even though control returns to the host language, the threads spawn and do their business, taking their time to fill a randomly named text file in some pre-specified directory.</span></div>
<div class="gmail_quote"><span class="Apple-style-span" style="font-family: arial, sans-serif; font-size: 13px; border-collapse: collapse; "><br></span></div><div class="gmail_quote"><font class="Apple-style-span" face="arial, sans-serif"><span class="Apple-style-span" style="border-collapse: collapse;">My thanks to Mark Hammond the one and only for swinging by on comp.lang.python -- more acknowledgment in my blog:</span></font></div>
<div class="gmail_quote"><font class="Apple-style-span" face="arial, sans-serif"><span class="Apple-style-span" style="border-collapse: collapse;"><br></span></font></div><div class="gmail_quote"><font class="Apple-style-span" face="arial, sans-serif"><span class="Apple-style-span" style="border-collapse: collapse;"><a href="http://mybizmo.blogspot.com/2010/12/office-work.html">http://mybizmo.blogspot.com/2010/12/office-work.html</a></span></font></div>
<div class="gmail_quote"><font class="Apple-style-span" face="arial, sans-serif"><span class="Apple-style-span" style="border-collapse: collapse; "><br></span></font></div><div class="gmail_quote"><font class="Apple-style-span" face="arial, sans-serif"><span class="Apple-style-span" style="border-collapse: collapse;">Here&#39;s the COM version (pycomsupport dependency not included for brevity)</span></font></div>
<div class="gmail_quote"><span class="Apple-style-span" style="font-family: arial, sans-serif; font-size: 13px; border-collapse: collapse; "><br>import threading<br>from random import choice, randint<br>import pycomsupport<br>
import os<br>import time<br><br>applause = [&quot;Bravo!\n&quot;,&quot;Clap Clap\n&quot;,&quot;Yay!\n&quot;,&quot;whistle\n&quot;,&quot;shreek\n&quot;]<br>laugh = [&quot;chuckle\n&quot;, &quot;guffaw\n&quot;, &quot;hoot\n&quot;, &quot;howl\n&quot;, &quot;ROFL\n&quot;]<br>
boo = [&quot;Boo!\n&quot;, &quot;Nada mas!\n&quot;, &quot;hissss\n&quot;]<br><br>class MPSS_Audience ( object ):<br><br>   _public_methods_ = [ &#39;applause_track&#39;, &#39;laugh_track&#39;, &#39;boo_track&#39; ]<br>   _reg_progid_ = &quot;LoadOpt.Feedback&quot;<br>
<br>   # Use pythoncom.CreateGuid()&quot; to make a new clsid<br>   _reg_clsid_ = &#39;{BFE032DC-0F31-47CA-A714-7D6AADA41F5C}&#39;<br><br>   def __init__(self, ident = None):<br>       self.logger = ident<br>       fp = os.path.normpath(&quot;C:\Users\Kirby\Documents\Visual FoxPro<br>
Projects\mpss&quot;)<br>       fn = pycomsupport.randomstring(8)+&quot;.txt&quot;<br>       self.output = os.path.join(fp, fn)<br><br>   def _noise_threads(self, noise_type):<br>       hnd = open(self.output, &#39;w&#39;)<br>
       for i in range(10):<br>           AudiencePerson(hnd, choice(noise_type), randint(0,5)).start()<br><br>   def applause_track(self):<br>       self._noise_threads(applause)<br><br>   def laugh_track(self):<br>       self._noise_threads(laugh)<br>
<br>   def boo_track(self):<br>       self._noise_threads(boo)<br><br><br>class AudiencePerson( threading.Thread ):<br><br>   def __init__(self, output, an, interval):<br>       self.output = output<br>       self.audience_noise = an<br>
       self.interval = interval<br>       super(AudiencePerson, self).__init__()<br><br>   def run(self):<br>       for i in range(5):<br>           self.output.write(self.getName() + &quot;: &quot; + self.audience_noise)<br>
           time.sleep(self.interval)<br><br>def testme():<br>   loObj = MPSS_Audience(1)<br>   loObj.laugh_track()<br><br>if __name__ == &quot;__main__&quot;:<br>   print &quot;Registering COM server...&quot;<br>   import win32com.server.register<br>
   win32com.server.register.UseCommandLine(MPSS_Audience)<br>   testme()<br><br><br>On the VFP side:<br><br>loCircus = CREATEOBJECT(&quot;Loadopt.Feedback&quot;, &quot;some param&quot;)<br>loCircus.applause_track()<br><br>
control returns immediately, even though the text file<br>takes quite awhile to fill, thanks to the several second<br>delays between thread writes.  The final file:<br><br>Thread-1: whistle<br>Thread-2: shreek<br>Thread-3: shreek<br>
Thread-4: whistle<br>Thread-5: Yay!<br>Thread-6: whistle<br>Thread-7: Yay!<br>Thread-7: Yay!<br>Thread-7: Yay!<br>Thread-7: Yay!<br>Thread-7: Yay!<br>Thread-8: Clap Clap<br>Thread-9: Clap Clap<br>Thread-9: Clap Clap<br>Thread-9: Clap Clap<br>
Thread-9: Clap Clap<br>Thread-9: Clap Clap<br>Thread-10: Clap Clap<br>Thread-2: shreek<br>Thread-8: Clap Clap<br>Thread-2: shreek<br>Thread-8: Clap Clap<br>Thread-2: shreek<br>Thread-4: whistle<br>Thread-5: Yay!<br>Thread-6: whistle<br>
Thread-8: Clap Clap<br>Thread-1: whistle<br>Thread-2: shreek<br>Thread-3: shreek<br>Thread-8: Clap Clap<br>Thread-10: Clap Clap<br>Thread-4: whistle<br>Thread-5: Yay!<br>Thread-6: whistle<br>Thread-1: whistle<br>Thread-3: shreek<br>
Thread-4: whistle<br>Thread-5: Yay!<br>Thread-6: whistle<br>Thread-10: Clap Clap<br>Thread-1: whistle<br>Thread-4: whistle<br>Thread-3: shreek<br>Thread-5: Yay!<br>Thread-6: whistle<br>Thread-10: Clap Clap<br>Thread-1: whistle<br>
Thread-3: shreek<br></span><div><span class="Apple-style-span" style="font-family: arial, sans-serif; font-size: 13px; border-collapse: collapse; ">Thread-10: Clap Clap</span></div><div><br><span class="Apple-style-span" style="font-family: arial, sans-serif; font-size: 13px; border-collapse: collapse; "></span></div>
<div>Kirby</div><div><br></div></div>