IC Python API:Dialog Callbacks

From Reallusion Wiki!
Revision as of 01:56, 25 September 2019 by Chuck (RL) (Talk | contribs) (Testing Dialog Callbacks)

Jump to: navigation, search
Main article: RL Python Samples.

This article will help you deeply understand the RDialogCallback class. Even though this class only supports three event types, their interactions and initiation can be complex. The following chart goes into more detail.

Action Calls Notes
Docking Hide -> Show
Undocking (Drag) Hide -> Show Show() command is ignored if the window is visible.
Undocking (Release) Hide -> Show
Closing 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

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()