Natron Logo
v2.3.15
  • User Guide
  • Reference Guide
  • Developers Guide
    • Python API
    • Introduction
    • Getting started
      • Creating and controlling nodes
      • Controlling parameters
      • Parameters expressions
      • Working with groups
      • Using Callbacks
      • Rendering
      • Using the rotoscoping functionalities
      • Using the tracker functionalities
      • Modal dialogs
        • Simple dialogs
        • More refined dialogs
      • User menu commands
      • PySide panels
      • Controlling the viewer
    • Natron Python FAQ
    • Tutorials
Natron
  • Docs »
  • Developers Guide »
  • Getting started »
  • Modal dialogs
  • Edit on GitHub

Modal dialogs¶

Modal dialogs are windows (or popup) that inform the user about something or ask for some information and that does not allow any other action to be performed while the dialog is opened.

This can be used as a quick way to retrieve user inputs.

Simple dialogs¶

The most simple dialogs in Natron are the information/warning/error/question dialog which basically just take some text in input and may return a reply from the user

natron.informationDialog("Info","Here is a relevant info")
../_images/infoDialog.png
natron.warningDialog("Warning","Warning you might lose everything on your computer")
../_images/warnDialog.png
natron.errorDialog("Error","Something went wrong, oops.")
../_images/errorDialog.png
reply = natron.questionDialog("Question","Are you sure you paid the license for Natron ?;)")
if reply == NatronEngine.Natron.StandardButtonEnum.eStandardButtonNo:
    ...
elif reply == NatronEngine.Natron.StandardButtonEnum.eStandardButtonYes:
    ...
../_images/questionDialog.png

More refined dialogs¶

To create dialogs that may request some information such as colors, frame range, coordinates or text input, you can create modal dialogs.

Basically you can add user parameters, and retrieve their value afterwards when the user pressed OK.

You can start adding user parameters using all the createXParam functions inherited from the UserParamHolder class. See the documentation of the PyModalDialog for more information:

dialog = app.createModalDialog() 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()

You can also add custom PySide widgets that can be inserted after any user parameter(s) using the addWidget(widget) and insertWidget(index,widget) functions.

label = QLabel("This is a PySide label")
dialog.addWidget(label)

To make the dialog show-up, use the exec() function on the dialog. This function will return once the user pressed either “OK” or “Canceled”:

if dialog.exec():
    #User pressed OK
../_images/customModalDialog.png

You can add a custom callback when a parameter changes, for instance to hide another parameter:

#Callback called when a parameter of  changes
#The variable paramName is declared by Natron; indicating the name of the parameter which just had its value changed
def paramChangedCallback():
    if paramName == "myBool":
        myInteger.setVisible(myBoolean.get())

dialog.setParamChangedCallback("paramChangedCallback")
Next Previous

© Copyright 2013-2020 The Natron documentation authors, licensed under CC BY-SA 4.0 Revision 513a2491.

Built with Sphinx using a theme provided by Read the Docs.
Read the Docs v: v2.3.15
Versions
master
v2.3.15
v2.3.14
v2.3.13
rb-2.3
Downloads
pdf
html
epub
On Read the Docs
Project Home
Builds

Free document hosting provided by Read the Docs.