From: Dethe E. <de...@li...> - 2006-03-07 21:53:18
|
On 3/7/06, Andrey Antonov <an...@uc...> wrote: > Dear Lady Elza, Um, not even close, but I'll let that slide. > Your letter impressed me much, because it is obvious that you are (from m= y > PoV) a programmer, > or closely connected with programming. I'm a professional programmer at my day job, a hobbyist programmer in my spare time. > I am not a professional programmer, but I have some experience in > programming. > I mean, up to a certain extent I could think :)) in algorithmic way. Mayb= e > because I am a math teacher, or for other reasons, I don't know... There are similarities between programming and math. > Your idea : > """ > You would probably have to walk the tree of objects and convert the > state of each object to a string which, when run, would restore the > original object. Tedious, but not difficult.""" > > is very brilliant and frankly speaking it was the first that came to my m= ind Not really brilliant, pretty much a standard approach. > trying to search my way to > solve the the problem I asked about. It is strange now, after receiving t= he > letter from Bruce, that this topic > haven't been discussed yet between VPython users. For the most part I think people test small bits of code at the command-line and write programs to create larger amounts of code.=20 What I think you want is to build up small bits of code, then to save the state of all of it? There are several approaches which would work, for one, you could just save each line of code to a file before executing it, to have a log of commands which could be re-run to recreate your state. You could have undo by dropping commands off the end of the file. Or, as in my previous post, you could build up a scene, then walk the tree of objects and write out equivalent commands. VPython object constructors can take arguments for pretty much any aspect of their state, so if you have a sphere which is green, with a radius of 2 at location (4,7,8) in the scene, you could write out from visual import * sphere(color=3D(0,1,0), radius=3D2, pos=3D(4,7,8)) Of course, you would have to do this for every type of object that VPython supports, and for every property of each object--and I'm not positive that they are all covered by named arguments. Overall it would be easier to write the files as you go. > Going ahead I ask myself questions for: > 1) bulding the tree of objects and relations between them from the point= of > view of "children and parents objects". Not sure what you mean here. Is what I mention above what you mean? > 2) Also it is closely related to the problem for executing a list of UNDO > commands in order the reach the beginning state of the program or in my c= ase > it is equal in restoring the starting state of the scene. Undo support would almost certainly be influenced by what mechanism you're using to build the environment. I do most of my work on OS X using its Cocoa framework, and Cocoa already has a notion of documents. Working with the standard Cocoa documents you can get a lot of behaviour (loading, saving, prompting to save before exit, undo/redo, etc.) without much work. Implementing it all from scratch is do-able, but much more work, and runs the substantial risk of it not working like other programs (which defeats user expectations). > Could you give me some links to e-books or web sources for mentioned abov= e > questions. I don't have a clear enough idea of what you're trying to do. The python.org website has good pointers for improving your python skills. If you want to create a UI for your students, you'll need to pick a user interface toolkit. This could be Tkinter, which has a good book on it, or wxPython (I think a book is in progress, but not sure of the status). I use Cocoa, but it is OS X only and has no book (yet).=20 There are other options... I don't think VPython integrates with any of the UI frameworks, but I've written VPython programs which communicate to a Tkinter UI via sockets. I hope that helps. --Dethe > Of course looking for the answers is for the next version of the program.= If > the first version wll see the world :)) > > Thank you again > Andrio > > |