Re: How VPython 6 differs from VPython 5
Bruce Sherwood <[email protected]> Sun, 13 Jan 2013 11:26:00 -0700
| Newsgroups | gmane.comp.python.visualpython.user |
|---|---|
| Message-ID | <CAFDG03gmZdsfuV_0poTSY=Ew8PRy_NiuHKYOpkqMyXFuGRx6Rg@mail.gmail.com> |
--===============5580664078354805569== Content-Type: multipart/alternative; boundary=047d7b2e42b211385904d32fa9b3 --047d7b2e42b211385904d32fa9b3 Content-Type: text/plain; charset=UTF-8 Here's an improved version of the differences between VPython 5 and 6; Changes from VPython 5 VPython 6 will run almost all old VPython programs correctly without change The following details about changes may be important in a few unusual cases. 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. Most animation loops already contain a rate statement anyway, to make the animation not run too fast. 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. Programs that use time.sleep will work, but you won't be able to zoom or rotate during the sleep period. You must import visual or vis before importing graph or controls or filedialog, which most users have always done anyway. *Your own program is imported by VPython:* 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. --047d7b2e42b211385904d32fa9b3 Content-Type: text/html; charset=UTF-8 Content-Transfer-Encoding: quoted-printable <div dir=3D"ltr">Here's an improved version of the differences between = VPython 5 and 6;<div><br></div><div><p class=3D"" style=3D"text-align:justi= fy;margin:6pt 0pt 0pt;font-size:10pt;color:rgb(0,0,0);vertical-align:baseli= ne;font-family:sans-serif"> <span class=3D"" style=3D"color:rgb(0,0,160);font-weight:bold">Changes from= VPython 5</span></p><p class=3D"" style=3D"text-align:justify;margin:6pt 0= pt 0pt;font-size:10pt;color:rgb(0,0,0);vertical-align:baseline;font-family:= sans-serif"> VPython 6 will run almost all old VPython programs correctly without change= The following details about changes may be important in a few unusual case= s.</p><p class=3D"" style=3D"text-align:justify;margin:6pt 0pt 0pt;font-siz= e:10pt;color:rgb(0,0,0);vertical-align:baseline;font-family:sans-serif"> An animation loop must contain a=C2=A0<span class=3D"" style=3D"color:rgb(2= 55,0,0)">rate</span>=C2=A0or=C2=A0<span class=3D"" style=3D"color:rgb(255,0= ,0)">sleep</span>=C2=A0statement, which limits the number of loop iteration= s 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=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, t= he scene will not be updated until and unless the loop is completed. Most a= nimation loops already contain a rate statement anyway, to make the animati= on not run too fast.</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. Programs that use= time.sleep will work, but you won't be able to zoom or rotate during t= he sleep period.</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"><strong>Y= our own program is imported by VPython:</strong>=C2=A0For technical reasons= , it is necessary for VPython 6 to do something rather unusual. When you im= port visual (or vis), your own program is in turn imported by the visual mo= dule. For this reason, you should import visual near the start of your prog= ram, because any executable statements preceding the import will be execute= d twice. The import of visual is also re-executed, but this is harmless bec= ause in Python a repeated import doesn't repeat the calculations 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> --047d7b2e42b211385904d32fa9b3-- --===============5580664078354805569== 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 --===============5580664078354805569== 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 --===============5580664078354805569==--