NatronGui
Inherits QDialog ../NatronEngine/UserParamHolder
A modal dialog to ask information to the user or to warn about something. See detailed<modalDialog.details>
description...
- def
addWidget<NatronGui.PyModalDialog.addWidget>
(widget) - def
getParam<NatronGui.PyModalDialog.getParam>
(scriptName) - def
insertWidget<NatronGui.PyModalDialog.insertWidget>
(index,widget) - def
setParamChangedCallback<NatronGui.PyModalDialog.setParamChangedCallback>
(callback)
The modal dialog is a way to ask the user for data or to inform him/her about something going on. A modal window means that control will not be returned to the user (i.e. no event will be processed) until the user closed the dialog.
If you are looking for a simple way to just ask a question or report an error, warning or even just a miscenalleous information, use the informationDialog(title,message)<NatronGui.PyGuiApplication.informationDialog>
function.
To create a new PyModalDialog
, just use the createModalDialog()<NatronGui.GuiApp.createModalDialog>
function, e.g.:
# In the Script Editor
dialog = app1.createModalDialog()
To show the dialog to the user, use the exec_()<>
function inherited from QDialog
:
dialog.exec_()
Note that once exec_()<>
is called, no instruction will be executed until the user closed the dialog.
The modal dialog always has OK and Cancel buttons. To query which button the user pressed, inspect the return value of the exec_()<>
call:
if dialog.exec_():
#The user pressed OK
...
else:
#The user pressed Cancel or Escape
You can start adding user parameters using all the createXParam<>
functions inherited from the NatronEngine.UserParamHolder
class.
Once all your parameters are created, create the GUI for them using the refreshUserParamsGUI()<NatronEngine.UserParamHolder.refreshUserParamsGUI>
function:
myInteger = dialog.createIntParam("myInt","This is an integer very important")
myInteger.setAnimationEnabled(False)
myInteger.setAddNewLine(False)
#Create a boolean on the same line
myBoolean = dialog.createBooleanParam("myBool","Yet another important boolean")
dialog.refreshUserParamsGUI()
dialog.exec_()
You can then retrieve the value of a parameter once the dialog is finished using the getParam(scriptName)<NatronGui.PyModalDialog.getParam>
function:
if dialog.exec_():
intValue = dialog.getParam("myInt").get()
boolValue = dialog.getParam("myBool").get()
Warning
Unlike the Effect<Effect>
class, parameters on modal dialogs are not automatically declared by Natron, which means you cannot do stuff like dialog.intValue
NatronGui.PyModalDialog.addWidget(widget)
- param widget
Append a QWidget inherited widget at the bottom of the dialog. This allows to add custom GUI created directly using PySide that will be inserted after any custom parameter.
NatronGui.PyModalDialog.getParam(scriptName)
- param scriptName
str
- rtype
Param<NatronEngine.Param>
Returns the user parameter with the given scriptName if it exists or None otherwise.
NatronGui.PyModalDialog.insertWidget(index,widget)
- param index
int
- param widget
PySide.QtGui.QWidget
Inserts a QWidget inherited widget at the given index of the layout in the dialog. This allows to add custom GUI created directly using PySide. The widget will always be inserted after any user parameter.
NatronGui.PyModalDialog.setParamChangedCallback(callback)
- param callback
str
Registers the given Python callback<callbacks>
to be called whenever a user parameter changed. The parameter callback is a string that should contain the name of a Python function.
The signature of the callback<callbacks>
used on PyModalDialog<pyModalDialog>
is:
callback(paramName, app, userEdited)
- paramName indicating the
script-name<autoVar>
of the parameter which just had its value changed. - app : This variable will be set so it points to the correct
application instance<App>
. - userEdited : This indicates whether or not the parameter change is due to user interaction (i.e: because the user changed the value by theirself) or due to another parameter changing the value of the parameter via a derivative of the
setValue(value)<>
function.
Example:
def myParamChangedCallback(paramName, app, userEdited):
if paramName == "myInt":
intValue = thisParam.get()
if intValue > 0:
myBoolean.setVisible(False)
dialog.setParamChangedCallback("myParamChangedCallback")