Vizard 7 » Reference » Graphical user interfaces (GUIs) » GUI elements » Getting data from GUI elements
7.7

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 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.

#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