From: Bruce S. <Bru...@nc...> - 2013-01-13 07:15:53
|
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. |