From: Bruce S. <Bru...@nc...> - 2013-01-25 22:55:35
|
It occurs to me that a note I posted to the wxPython forum might be of some interest to the VPython community: You might like to see how far we've gotten, with lots of help from this wxPython community. Below is a screen shot of the wxPython-based VPython (the image of this demo came from Windows and also displays correctly on Linux; everything but the menus works on a Mac). In the past, the 3D canvas had to fill the window; there couldn't be other widgets in the window. In the program, the 3D cube rotates, and the controls let you change the color, the rotation speed, and the rotation direction, and you can also type into the text control. The 3D portion of the code is pretty trivial. The first statement creates a window and the second places an OpenGL canvas in the left half of the window. You'll note that some adjustment is made so that the canvas is L*L but the window is larger. w = window(width=2*(L+window.get_dw()), height=L+window.get_dh(), title='Widgets') display(window=w, y = 0, width=L, height=L, forward=-vector(0,1,2)) cube = box(color=color.red) ... wxPython code to make widgets for setting color, and rotation speed and direction while True: rate(100) cube.rotate(axis=(0,1,0), angle=cube.dir*cube.dtheta) Of equal importance to widgets is the fact that it was possible to eliminate very nearly all platform-dependent C++ code (there are small instances of platform-dependent Python code, but that's trivial). The only remaining platform-dependent C++ code is GetProcAddress. Of critical importance is that the new VPython works on 64-bit Cocoa-based Macs, something that was impossible with the old VPython, which was Carbon-based. I've also run up against a significant platform-dependent display issue which I've "solved" temporarily on one particular Linux with hard-coded integers. The VPython API has always had the user specify the width and height of a window as the outer bounds, so that one can easily place (say) two windows adjacent to each other or one below the other, with the canvas being smaller than that. I need to know the dimensions of the writable area, but unfortunately only for Windows will wxWidgets give me the dimensions of borders, title bar, and menu bar. For Mac and Linux, the values are all -1. For both Windows and Mac, these values are probably extremely stable (I use hard-coded integers for the Mac), but on different distributions of Linux, or for different window managers on the same Linux, I don't know how to get the dimension information I need. Note that my problems are somewhat different from those using wxPython to create apps. VPython is middleware; people use VPython to create apps. This puts an additional burden on VPython to be universally cross-platform, not just cross-platform for a particular app. Availability note: At vpython.org one can get an experimental version of the wxPython-based VPython, but the support for widgets isn't yet included even in that experimental package. However, the up-to-date source code is available at https://github.com/BruceSherwood/vpython-wx. The program widgets.py that generated the image is at the repository in site-packages/visual/examples. [image: Inline image 1] |