From: Bruce S. <Bru...@nc...> - 2009-09-09 16:21:55
|
It is interesting that VPython has recently become of interest to a community of expert programmers who would like to embed it in larger environments. I myself don't feel competent to think through or implement mechanisms to make this feasible (and currently I'm overcommitted to other work having to do with a major revision of a textbook and associated supplementary materials), and David Scherer, who does have the necessary competence, is not available, so what needs to happen is for someone or someones to step forward and try something. Bruce Sherwood Michele Mattioni wrote: > Hi All, > > I would like to add my two cents on this matter. > > If I understood correctly there is a growing need to integrate visual > window with a bigger library, that can be QT, GTK, WxPython or you > named it. > > Until now the approach that most of us has taken is to use something > similar to the one pointed out in the previous mail and now in the > FAQ. > > Shortly in this approach there are two threads running: > (i) visual thread, that is a gtk thread which manage the display with > the related zoom and rotate action. > (ii) application thread which manage to run the library of choice with > the application (e.g.: Another GTK thread, a QT one or wxPython.) > > This is all good until you want to do something different than zoom or > rotate the object. > > Let's take the click example: > http://vpython.org/contents/docs/visual/mouse_click.html > What is suggested is to enter a while True loop which will exit only > if that action will happen. This is called busy waiting and this is > bad. > > This is bad because the CPU is constantly checking if something has > been clicked. This happens every cycle making the computer > unresponsive and degrading the performance of the program. It's > acceptable for smaller program, it's completely cumbersome for bigger > one. > > To avoid the loss of performance somebody has proposed to use a timer, > as pointed out in the FAQ and the link above is one of the possible > solution; but this is not a workaround and just move the problem to > the update time of the timer without solving the problem. > > So the question is: > Why am I able to rotate or to zoom the objects without wasting CPU and > not to click on the objects? At the end of the day it's the same > window and it's the same objects! > > Shortly because the first two events are embedded in the visual > threads, and the GTK (as all the major UI library) is event driven. > Only if an event happens, the main loop will respond, checking if the > event is known and acts; otherwise nothing will happen. > > The last one comes from outside the main visual loop and because our > event is not recorded in the visual loop, we need to: > - Lock the application with a while true > - Wait until our user click on the object. > > If our user does not click on the object and change his mind we can't > do anything about it. He can only click. However he can still rotate > and zoom because this event are managed (and recognised) by the visual > main loop. > > What is the solution? > > Deploy a proper visual widget that can be integrated in GTK, QT, > wxPython, windows and MAc. > > The code starti the display: > http://visualpython.cvs.sourceforge.net/viewvc/visualpython/vpython-core2/src/gtk2/display.cpp?revision=1.57&view=markup > > should be divided in two chunks: > - One class with all the visual goodness > - Several class which extend the first class and provide a GTK widget, > wxPython widget and Qt widget (and I guess windows and Mac.) > > This will give the possibility to insert visual in the main thread of > any bigger application and and experienced developer can make a full > use of the visual abilities registering as many event he wants (so the > click, the rotate, the zoom, the selection of objects). > > For the beginner developer we have just to write a wrapper for the > widget that will start the application and then everything can be used > as before. > > This is what I understood looking with the code and developing a bit > with visual (that is really great piece of software Thanks! :) ) > > Do you think is the right way to go? > > Cheers, > Michele > |