Open topic with navigation
Getting data from GUI elements
To pull user input from buttons, boxes and sliders, you can call them
directly or set up a callback that gets triggered by new input.
Getting data from a buttons, checkboxes and sliders
Use <GUI element>.get() to get the
data from a button, check box or
slider.
- If <GUI element> is a button
or a checkbox, the command will
return a '0' if the button is down and '1' if it's up.
- If <GUI element> is a slider,
the command will return the tick's position along the bar.
If you want to know if the user is currently moving the tick on a slider,
use <slider>.dragging(). If the user
is dragging the tick, the command will return a '1'.
data = mySlider.get() #Get
the tick location.
isDragging = mySlider.dragging() #Is
the tick dragging?
Getting data from a text boxes
The <GUI element>.get() command
will give you the typed input from a textbox. You can also get the cursor
location in the textbox using <text box>.getCursorPos().
myTextBox = viz.addTextbox()
myTextBox.get() #Get the text in the
box.
myTextBox.getCursorPos() #Get the
position of the cursor.
Getting data from droplists
Use <droplist>.getSelection() to get the index of the current
selection on the droplist. Note: since this command will only give you
the current index, you can use <droplist>.getItems() to find out
the whole array of items and then use the index to pick out the value
of the selected item.
#Find the index of the current selection.
drop.getSelection()
#Find the selection itself.
drop.getItems()[ drop.getSelection() ]
Setting up a GUI callback
The action library has methods
of registering callback functions for GUI callback events. The commands
<vizact>.onbuttondown,
<vizact>.onbuttonup,
<vizact>.onslider,
<vizact>.onlist,
and <vizact>.ontextbox
will handle the following events.
- Button events (viz.BUTTON_EVENT)
: triggered by checkboxes, buttons, radio buttons, or clicking on a drop-down
menu.
- Slider events (viz.SLIDER_EVENT)
: triggered by sliders and progress bars.
- List events (viz.LIST_EVENT)
: triggered when someone makes a new choice from a drop-down menu (but
not when the current selection is re-selected).
- Textbox events (viz.TEXTBOX_EVENT)
: triggered when text is entered in a text box.
#Add and position a slider and progress bar.
mySlider = viz.addSlider()
myProgressBar = viz.addProgressBar('How much?')
mySlider.setPosition(.5,.5)
myProgressBar.setPosition(.5,.25)
#Create functions to handle slider events
def sliderChanged(pos):
print('mySlider is at
' + str(pos))
vizact.onslider(mySlider,sliderChanged)
def progressBarChanged(pos):
print('myProgressBar
is at ' + str(pos))
vizact.onslider(myProgressBar,progressBarChanged)
See also
In this section:
User interface basics
GUI elements
Getting
data from GUI elements
GUI appearance
vizinfo
vizmenu
vizinput
vizdlg
vizconfig
viztip
Displaying HTML
GUI command table
Other sections:
Event Basics
Action basics
Text node basics
Example scripts:
vizInfo
vizMenu
Prompt