After a fair amount of testing, and given its general utility, I've added
controls.py to the visual folder (download from CVS at sourceforge.net, or
download Visual-2002-04-17.zip from http://vpython.org, in the download
section for all platforms).
This module offers buttons, toggle switches, sliders, and pull-down menus.
The full capabilities can be seen from the test routine found at the end of
controls.py (simply execute controls.py to see what happens). Eventually
there will be documentation added to the Visual reference manual.
I would be pleased to receive suggestions/criticisms, and even more pleased
for someone to make major improvements, either in the way the module works
or in the appearance of the control objects.
Here is a short example, which displays a button and changes the button
text every time you click the button. The Python construction "lambda:" is
required for controls.py to have the correct context ("namespace") for
calling the specified routine.
from visual.controls import *
def change(): # Called by controls when button is clicked
if b.text == 'Click me':
b.text = 'Try again'
else:
b.text = 'Click me'
c = controls() # Create controls window
# Create a button in the controls window:
b = button( pos=(0,0), width=60, height=60, text='Click me', action=lambda:
change() )
while 1:
c.interact() # Check for mouse events and drive specified actions
|