IC Python API:Dialog Callbacks

From Reallusion Wiki!
Jump to: navigation, search
Main article: RL Python Samples.

This article will help you understand the RDialogCallback class at a deeper level. Even though this class only supports three event types, their interactions and initiation can be complex. For example, when the user docks a window, the Hide event is triggered followed by a Show. The following chart gives more details:

Action / Python Call Triggers Notes
Docking Hide -> Show
Undocking (Drag) Hide -> Show Show() command is ignored if the window is visible.
Undocking (Release) Hide -> Show
Closing ([X] button) Close -> Hide
Hide() command Hide Hide() command is ignored if the window is not shown.
Show() command Show
Close() command Close -> Hide Close() command can be executed even when the window is not show.

Notice that Hide always executes after a Close. Therefore, you should always put your script variable clean-up procedures under the Hide event. Under the condition that Hide event is never used, then your clean-up procedures can be housed under the Close event.

Testing Dialog Callbacks

Ic python api dialog callbacks 01.png

You can use the following script to test and trigger the Dialog Callback events. Try interacting with the buttons, docking, undocking, and closing the window while watching the Console Log feedback (Script > Console Log).

import RLPy
from PySide2 import QtWidgets
from PySide2.shiboken2 import wrapInstance


class DialogCallback(RLPy.RDialogCallback):

    def __init__(self):
        RLPy.RDialogCallback.__init__(self)

    def OnDialogHide(self):
        print("The dialog window is Hidden")

    def OnDialogShow(self):
        print("The dialog window is Shown")

    def OnDialogClose(self):
        print("The dialog window is Closed")
        return True


dock_window = RLPy.RUi.CreateRDockWidget()
dock_window.SetWindowTitle("Dialog Callback Examples")
dock_window.SetAllowedAreas(RLPy.EDockWidgetAreas_RightDockWidgetArea)

hide_button = QtWidgets.QPushButton(text="Hide", minimumHeight=24)
hide_button.clicked.connect(lambda: dock_window.Hide())

show_button = QtWidgets.QPushButton(text="Show", minimumHeight=24)
show_button.clicked.connect(lambda: dock_window.Show())

main_widget = QtWidgets.QWidget()
main_widget.setLayout(QtWidgets.QHBoxLayout())
main_widget.layout().addWidget(hide_button)
main_widget.layout().addWidget(show_button)

dock = wrapInstance(int(dock_window.GetWindow()), QtWidgets.QDockWidget)
dock.setFixedWidth(300)
dock.setWidget(main_widget)

dialog_callback = DialogCallback()
dock_window.RegisterEventCallback(dialog_callback)

dock_window.Show()

APIs Used

You can research the following references for the APIs deployed in this code.