How VPython 6 differs from VPython 5
Bruce Sherwood <[email protected]> Sun, 13 Jan 2013 00:15:46 -0700
| Newsgroups | gmane.comp.python.visualpython.user |
|---|---|
| Message-ID | <CAFDG03jyX=mhyM6HFa_nr8+=EzEkNFbCqG7YRztrpsE66TYt5w@mail.gmail.com> |
--===============2986564707474428102== Content-Type: multipart/alternative; boundary=e89a8ff2459b21df0204d3264ccc --e89a8ff2459b21df0204d3264ccc Content-Type: text/plain; charset=UTF-8 Here is detailed information on how VPython 6 differs from VPython 5, which will be incorporated in the Help for upcoming releases of VPython 6. Note that the fact that in a main program __name__ isn't '__main__' is an unavoidable "feature", not a bug. That is, there doesn't seem to be a way to make this work. As described below, the way to test a module is to import it from a test routine. Changes from VPython 5 The new version makes an essential change to the syntax of VPython programs. Now, an animation loop *MUST* contain a rate or sleep statement, which limits the number of loop iterations per second as before but also when appropriate (about 30 times per second) updates the 3D scene and handles mouse and keyboard events. Without a rate or sleep statement, the scene will not be updated until and unless the loop is completed. You should use the new function sleep rather than time.sleep. The new function periodically renders the scene and processes mouse events, making it possible to continue using zoom and rotate, whereas time.sleep does not do this. You must import visual or vis before importing graph or controls or filedialog, which most users have always done anyway. For technical reasons, it is necessary for VPython 6 to do something rather unusual. When you import visual (or vis), your own program is in turn imported by the visual module. For this reason, you should import visual near the start of your program, because any executable statements preceding the import will be executed twice. The import of visual is also re-executed, but this is harmless because in Python a repeated import doesn't repeat the calculations in the imported module. *Importing your own modules:* If you create your own module (lib.py, say) that imports visual, and you import lib from a program named demo.py, you need to import visual in demo.py before importing lib, so that demo is the base program (when lib imports visual, that will be the second import of visual and will not lead to lib being imported by visual). Note that the standard trick of testing a module on the basis of __name__=='__main__' won't work, because the program will be imported by visual. To test a module, import it from a test program rather than trying to use __name__=='__main__' within the module. --e89a8ff2459b21df0204d3264ccc Content-Type: text/html; charset=UTF-8 Content-Transfer-Encoding: quoted-printable <div dir=3D"ltr">Here is detailed information on how VPython 6 differs from= VPython 5, which will be incorporated in the Help for upcoming releases of= VPython 6. Note that the fact that in a main program __name__ isn't &#= 39;__main__' is an unavoidable "feature", not a bug. That is,= there doesn't seem to be a way to make this work. As described below, = the way to test a module is to import it from a test routine.<br> <div><br></div><div><p class=3D"" style=3D"text-align:justify;margin:6pt 0p= t 0pt;font-size:10pt;color:rgb(0,0,0);vertical-align:baseline;font-family:s= ans-serif"><span class=3D"" style=3D"color:rgb(0,0,160);font-weight:bold">C= hanges from VPython 5</span></p> <p class=3D"" style=3D"text-align:justify;margin:6pt 0pt 0pt;font-size:10pt= ;color:rgb(0,0,0);vertical-align:baseline;font-family:sans-serif">The new v= ersion makes an essential change to the syntax of VPython programs. Now, an= animation loop=C2=A0<strong><em>MUST</em></strong>=C2=A0contain a=C2=A0<sp= an class=3D"" style=3D"color:rgb(255,0,0)">rate</span>=C2=A0or=C2=A0<span c= lass=3D"" style=3D"color:rgb(255,0,0)">sleep</span>=C2=A0statement, which l= imits the number of loop iterations per second as before but also when appr= opriate (about 30 times per second) updates the 3D scene and handles mouse = and keyboard events. Without a=C2=A0<span class=3D"" style=3D"color:rgb(255= ,0,0)">rate</span>=C2=A0or=C2=A0<span class=3D"" style=3D"color:rgb(255,0,0= )">sleep</span>=C2=A0statement, the scene will not be updated until and unl= ess the loop is completed.</p> <p class=3D"" style=3D"text-align:justify;margin:6pt 0pt 0pt;font-size:10pt= ;color:rgb(0,0,0);vertical-align:baseline;font-family:sans-serif">You shoul= d use the new function=C2=A0<span class=3D"" style=3D"color:rgb(255,0,0)">s= leep</span>=C2=A0rather than time.sleep. The new function periodically rend= ers the scene and processes mouse events, making it possible to continue us= ing zoom and rotate, whereas time.sleep does not do this.</p> <p class=3D"" style=3D"text-align:justify;margin:6pt 0pt 0pt;font-size:10pt= ;color:rgb(0,0,0);vertical-align:baseline;font-family:sans-serif">You must = import visual or vis before importing graph or controls or filedialog, whic= h most users have always done anyway.</p> <p class=3D"" style=3D"text-align:justify;margin:6pt 0pt 0pt;font-size:10pt= ;color:rgb(0,0,0);vertical-align:baseline;font-family:sans-serif">For techn= ical reasons, it is necessary for VPython 6 to do something rather unusual.= When you import visual (or vis), your own program is in turn imported by t= he visual module. For this reason, you should import visual near the start = of your program, because any executable statements preceding the import wil= l be executed twice. The import of visual is also re-executed, but this is = harmless because in Python a repeated import doesn't repeat the calcula= tions in the imported module.</p> <p class=3D"" style=3D"text-align:justify;margin:6pt 0pt 0pt;font-size:10pt= ;color:rgb(0,0,0);vertical-align:baseline;font-family:sans-serif"><strong>I= mporting your own modules:</strong>=C2=A0If you create your own module (lib= .py, say) that imports visual, and you import lib from a program named demo= .py, you need to import visual in demo.py before importing lib, so that dem= o is the base program (when lib imports visual, that will be the second imp= ort of visual and will not lead to lib being imported by visual). Note that= the standard trick of testing a module on the basis of __name__=3D=3D'= __main__' won't work, because the program will be imported by visua= l. To test a module, import it from a test program rather than trying to us= e __name__=3D=3D'__main__' within the module.</p> </div></div> --e89a8ff2459b21df0204d3264ccc-- --===============2986564707474428102== Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Content-Disposition: inline ------------------------------------------------------------------------------ Master Visual Studio, SharePoint, SQL, ASP.NET, C# 2012, HTML5, CSS, MVC, Windows 8 Apps, JavaScript and much more. Keep your skills current with LearnDevNow - 3,200 step-by-step video tutorials by Microsoft MVPs and experts. ON SALE this month only -- learn more at: http://p.sf.net/sfu/learnmore_123012 --===============2986564707474428102== Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Content-Disposition: inline _______________________________________________ Visualpython-users mailing list Visualpython-users-5NWGOfrQmneRv+LV9MX5uipxlwaOVQ5f@public.gmane.org https://lists.sourceforge.net/lists/listinfo/visualpython-users --===============2986564707474428102==--