GO2cam Javascript API  6.11
Use of dialogs

The JavaScript API provides the possibility to use dialogs designed with Qt Designer from Qt framework .

You can find all the documentation for Qt Designer here.

Qt Dialogs

Dialogs can be designed with Qt Designer and saved as .ui files. .ui files can then be used in scripts to interact with the users

Basically, components of the dialogs are retrieved in the script by their name, i.e. objectName property in Qt Designer, and some callbacks are predifined to catch clicks or value modification.

Display a dialog

Dialogs are managed with the object GO2SDialogUtil, and a dialog is displayed when calling GO2SDialogUtil.ExecDialog.

‍When lauching a .js file, the variable scriptFilePath allows to know where the .js is executed and so find a .ui relatively

// this will launch the dialog LineParam.ui made with Qt Designer
var dialog = GO2SDialogUtil.ExecDialog(scriptFilePath+'/LineParam.ui')
Warning
Do not use QDialogButtonBox when creating a dialog box!

Getting values

The example bellow gives a simple way to use a dialog in order to ask values from user LineParam.ui

//get a line supposed to be driven by an angle, and identified with label 'line_angle'
var line_a = GO2SGeometryUtil.GetByName('line_angle')[0]
//get a line supposed to be parallel to line_a driven by a parallel distance. Identified with label 'line_parallel'
var line_p = GO2SGeometryUtil.GetByName('line_parallel')[0]
//callback called just after dialog is launched to initialise it
var InitDialog = function()
{
//fill the dialog component named 'angle' with the line angle value
GO2SDialogUtil.SetDouble('angle', line_a.GetParam(GO2SParam.angle))
//fill the dialog component named 'distance' with the line parallel distance
GO2SDialogUtil.SetDouble('distance', line_p.GetParam(GO2SParam.length))
}
//callback called when a button is clicked
var PushButton_Clicked = function(name)
{
//if the button named 'okButton' is clicked (i.e. our OK button)
if(name == 'okButton')
{
//get the value from the dialog component named 'angle' and set as new angle for the line
line_a.SetParam(GO2SParam.angle, GO2SDialogUtil.GetDouble('angle'))
//get the value from the dialog component named 'distance' and set as new parallel distance for the line
line_p.SetParam(GO2SParam.length, GO2SDialogUtil.GetDouble('distance'))
}
}
//Launch the dialog to ask new angle and distance
var dialog = GO2SDialogUtil.ExecDialog(scriptFilePath+'/LineParam.ui')

Dialog callbacks

Global interaction

InitDialog

This callback is called just before a dialog box is launched using GO2SDialogUtil.ExecDialog define this callback in the script and set its content to initialise content of the dialog

var InitDialog = function()
{
}
ShowControlDialog

This callback is called when a dialog box is shown

var ShowControlDialog = function()
{
}
HideControlDialog

This callback is called when a dialog box is hidden

var HideControlDialog = function()
{
}
ResizeControlDialog

This callback is called when a dialog box is resized

var ResizeControlDialog = function()
{
}
EnterControlDialog

This callback is called when mouse enters the dialog

var EnterControlDialog = function()
{
}
LeaveControlDialog

This callback is called when mouse leaves the dialog

var LeaveControlDialog = function()
{
}

Control interaction

Remarks
in all the fuctions bellow, the variable name refers to the name of the widget given in Qt Designer

Push button

PushButton_Clicked

This callback is called when a push button is clicked in the dialog

var PushButton_Clicked = function(name)
{
}

Spin box

SpinBox_SetValue

This callback is called when a spin box is modified in the dialog
value is the new value of the controlcode

var SpinBox_SetValue = function(name, value)
{
}

Double spin box

DoubleSpinBox_SetValue

This callback is called when a double spin box is modified in the dialog
value is the new value of the control

var DoubleSpinBox_SetValue = function(name, value)
{
}

Check box

CheckBox_SetChecked

This callback is called when a check box is set or unset checked in the dialog
check is a boolean value that indicates if the control is newly set or unset

var CheckBox_SetChecked = function(name, check)
{
}
CheckBox_StateChanged

This callback is called when a 3 states check box is modified in the dialog
state is the new state of the control (-1, 0 or 1)

var CheckBox_StateChanged = function(name, state)
{
}

Radio button

RadioButton_SetChecked

This callback is called when a radio button is modified in the dialog
check is a boolean value that indicates if the control is newly selected or not

var RadioButton_SetChecked = function(name, check)
{
}

Combo box

ComboBox_CurrentChanged

This callback is called when a combo box is modified in the dialog
text is the text of the newly selected item in the combo

var ComboBox_CurrentTextChanged = function(name, text)
{
}
ComboBox_CurrentChanged

This callback is called when a combo box is modified in the dialog
index is the position of the newly selected item in the combo

var ComboBox_CurrentIndexChanged = function(name, index)
{
}

Table widget

Table_SelectionChanged

This callback is called when an item (cell or line) is newly selected in a table

var Table_SelectionChanged = function(name)
{
}
Table_Clicked

This callback is called when a cell is clicked in a table
row and col are line an column number of the clicked item

var Table_Clicked = function(name, row, col)
{
}
Table_DoubleClicked

This callback is called when a cell is double clicked in a table
row and col are line an column number of the double clicked item

var Table_DoubleClicked = function(name, row, col)
{
}
Table_ValueChanged

This callback is called when the content of a cell is modified in a table
row and col are line an column number of the modified item

var Table_ValueChanged = function(name, row, col)
{
}