Difference between revisions of "IC Python API:Dialog Callbacks"
Chuck (RL) (Talk | contribs) m |
Chuck (RL) (Talk | contribs) m |
||
(11 intermediate revisions by the same user not shown) | |||
Line 2: | Line 2: | ||
{{Parent|IC_Python_API:RL_Python_Samples|RL Python Samples}} | {{Parent|IC_Python_API:RL_Python_Samples|RL Python Samples}} | ||
− | This article will help you | + | 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: |
{|class="wikitable" | {|class="wikitable" | ||
− | !Action | + | !Action / Python Call |
− | ! | + | !Triggers |
!Notes | !Notes | ||
|- | |- | ||
Line 20: | Line 20: | ||
| | | | ||
|- | |- | ||
− | |Closing | + | |Closing ([X] button) |
|Close -> Hide | |Close -> Hide | ||
| | | | ||
Line 37: | Line 37: | ||
|} | |} | ||
− | Notice that '''Hide''' always executes after a '''Close'''. Therefore, you should always put your script variable clean-up | + | 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 == | == Testing Dialog Callbacks == | ||
− | You can use the following script to test and trigger the Dialog Callback events. | + | [[File:Ic_python_api_dialog_callbacks_01.png|right]] |
+ | |||
+ | 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'''). | ||
<syntaxhighlight lang="python"> | <syntaxhighlight lang="python"> | ||
+ | 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() | ||
</syntaxhighlight> | </syntaxhighlight> | ||
+ | |||
+ | == APIs Used == | ||
+ | |||
+ | You can research the following references for the APIs deployed in this code. | ||
+ | |||
+ | <div style="column-count:4; -moz-column-count:4; -webkit-column-count:4"> | ||
+ | * [[ IC_Python_API:RLPy_RDialogCallback#__init__ | RLPy.RDialogCallback.__init__() ]] | ||
+ | * [[ IC_Python_API:RLPy_RUi#CreateRDockWidget | RLPy.RUi.CreateRDockWidget() ]] | ||
+ | </div> |
Latest revision as of 19:08, 26 February 2020
Contents
- 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
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.