Difference between revisions of "IC Python API:RLPy RDialogCallback"

From Reallusion Wiki!
Jump to: navigation, search
m (Detailed Description)
m
 
(2 intermediate revisions by the same user not shown)
Line 1: Line 1:
 
{{TOC}}
 
{{TOC}}
 
{{Parent|IC_Python_API:RL_Python_Modules|Modules}}
 
{{Parent|IC_Python_API:RL_Python_Modules|Modules}}
==Inheritance==
+
{{last_modified}}
This class inherits public member functions from:
+
 
*[[IC_Python_API:RLPy_RCallback|RLPy.RCallback]]
+
== Description ==
== Detailed Description ==
+
 
This class is used to register callbacks for dialog events.
+
This class is used to monitor dialog related events, i.e. hide, show, close, etc. A dialog callback class must be made that inherits from [[IC_Python_API:RLPy_RDialogCallback|RDialogCallback]], then the internal callback functions can be overwritten. This dialog callback instance can then be registered to a dialog window or dock widget with [[IC_Python_API:RLPy_REventCallback#RegisterEventCallback|RLPy.REventCallback.RegisterEventCallback()]] and a registration id will returned. This id can be used later, to unregister the callback function that it belongs to. The corresponding callback function will be called when a dialog is shown, hidden, or closed.
<syntaxhighlight lang="Python">
+
 
 +
[[IC_Python_API:RLPy_RDialogCallback|RDialogCallback]] can not be created as a local variable, otherwise the application will crash. Errors in the callback function can also cause the application to crash without warning, therefore, one should consider using Python's '''try except''' for fool-proof implementation.
 +
 
 +
=== Inheritance ===
 +
 
 +
[[IC_Python_API:RLPy_RCallback|RCallback]]> [[IC_Python_API:RLPy_RDialogCallback|RDialogCallback]]
 +
 
 +
=== Examples ===
 +
 
 +
The following is an example of registering and unregistering [[IC_Python_API:RLPy_RDialogCallback|RDialogCallback]] to and from [[IC_Python_API:RLPy_RIDialog|RIDialog]].
 +
 
 +
<syntaxhighlight lang="python" line='line'>
 
class MyDialogCallback(RLPy.RDialogCallback):
 
class MyDialogCallback(RLPy.RDialogCallback):
def __init__(self):
+
  def __init__(self):
   RLPy.RDialogCallback.__init__(self)
+
      RLPy.RDialogCallback.__init__(self)
def OnDialogHide(self):
+
  def OnDialogHide(self):
   print("Dialog is be Hide")
+
      print("Dialog Hide")
def OnDialogShow(self):
+
  def OnDialogShow(self):
   print("Dialog is be Show")
+
      print("Dialog Show")
def OnDialogClose(self):
+
  def OnDialogClose(self):
   print("Dialog is be Close")
+
      print("Dialog Close")
+
      return True
mydialog = RUi.CreateRDialog()
+
 
 +
mydialog = RLPy.RUi.CreateRDialog()
 
mycallback = MyDialogCallback()
 
mycallback = MyDialogCallback()
mydialog.RegisterEventCallback(mycallback)
+
 
 +
# register dialog event
 +
dialog_register_id = mydialog.RegisterEventCallBack(mycallback)
 +
mydialog.Show() #print "Dialog Show"
 +
 
 +
# use id to unregister
 +
status = mydialog.UnregisterEventCallback(dialog_register_id )
 
</syntaxhighlight>
 
</syntaxhighlight>
 +
 +
See Also: [[IC_Python_API:RLPy_RIDialog|RIDialog]], [[IC_Python_API:RLPy_RIDockWidget|RIDockWidget]]
  
 
== Member Functions ==
 
== Member Functions ==
=== OnDialogClose ===
+
 
<syntaxhighlight lang="Python">
+
=== OnDialogHide ( self ) ===
RLPy.RDialogCallback.OnDialogClose ( self )
+
 
 +
This event is called when this dialog is hidden. When a dialog's close button is pressed, OnDialogHide will be called first, followed by OnDialogClose. When a docakable window is docked within the main window, OnDialogHide will be callsed first, followed by OnDialogShow.
 +
 
 +
<syntaxhighlight lang="python" line='line'>
 +
class MyDialogCallback(RLPy.RDialogCallback):
 +
  def __init__(self):
 +
      RLPy.RDialogCallback.__init__(self)
 +
  def OnDialogHide(self):
 +
      print("Dialog Hide")
 +
 
 +
mydialog = RLPy.RUi.CreateRDialog()
 +
mycallback = MyDialogCallback()
 +
 
 +
# register dialog event
 +
dialog_register_id = mydialog.RegisterEventCallBack(mycallback)
 +
mydialog.Hide() #print "Dialog Hide"
 
</syntaxhighlight>
 
</syntaxhighlight>
Callback for dialog close.
+
 
==== Returns ====
+
=== OnDialogShow ( self ) ===
<div style="margin-left: 2em;">
+
 
Dialog closed - bool
+
This event is called when this dialog is shown. Initialization protocals is most suited for execution at this time. When dockable window is docked within the main window, OnDialogHide will be called first, followed by OnDialogShow.
</div>
+
 
-----
+
<syntaxhighlight lang="python" line='line'>
=== OnDialogHide ===
+
class MyDialogCallback(RLPy.RDialogCallback):
<syntaxhighlight lang="Python">
+
  def __init__(self):
RLPy.RDialogCallback.OnDialogHide ( self )
+
      RLPy.RDialogCallback.__init__(self)
 +
  def OnDialogShow(self):
 +
      print("Dialog Show")
 +
 
 +
mydialog = RLPy.RUi.CreateRDialog()
 +
mycallback = MyDialogCallback()
 +
 
 +
# register dialog event
 +
dialog_register_id = mydialog.RegisterEventCallBack(mycallback)
 +
mydialog.Show() #print "Dialog Show"
 
</syntaxhighlight>
 
</syntaxhighlight>
Callback for dialog hide.
+
 
-----
+
=== OnDialogClose ( self ) ===
=== OnDialogShow ===
+
 
<syntaxhighlight lang="Python">
+
This event is called when this dialog is about to be closed and return whether it is truly closed as confirmed by the application. When a dialog's close button is pressed, OnDialogHide will be called first, followed by OnDialogClose.
RLPy.RDialogCallback.OnDialogShow ( self )
+
 
 +
==== Returns ====
 +
:Whether the dialog is truly closed according to the application - boolean
 +
 
 +
<syntaxhighlight lang="python" line='line'>
 +
class MyDialogCallback(RLPy.RDialogCallback):
 +
  def __init__(self):
 +
      RLPy.RDialogCallback.__init__(self)
 +
  def OnDialogClose(self):
 +
      print("Dialog Close")
 +
      return true
 +
 
 +
mydialog = RLPy.RUi.CreateRDialog()
 +
mycallback = MyDialogCallback()
 +
 
 +
# register dialog event
 +
dialog_register_id = mydialog.RegisterEventCallBack(mycallback)
 +
mydialog.Close() #print "Dialog Close"
 
</syntaxhighlight>
 
</syntaxhighlight>
Callback for dialog show.
 

Latest revision as of 00:37, 30 April 2020

Main article: Modules.
Last modified: 04/30/2020

Description

This class is used to monitor dialog related events, i.e. hide, show, close, etc. A dialog callback class must be made that inherits from RDialogCallback, then the internal callback functions can be overwritten. This dialog callback instance can then be registered to a dialog window or dock widget with RLPy.REventCallback.RegisterEventCallback() and a registration id will returned. This id can be used later, to unregister the callback function that it belongs to. The corresponding callback function will be called when a dialog is shown, hidden, or closed.

RDialogCallback can not be created as a local variable, otherwise the application will crash. Errors in the callback function can also cause the application to crash without warning, therefore, one should consider using Python's try except for fool-proof implementation.

Inheritance

RCallback> RDialogCallback

Examples

The following is an example of registering and unregistering RDialogCallback to and from RIDialog.

 1 class MyDialogCallback(RLPy.RDialogCallback):
 2    def __init__(self):
 3        RLPy.RDialogCallback.__init__(self)
 4    def OnDialogHide(self):
 5        print("Dialog Hide")
 6    def OnDialogShow(self):
 7        print("Dialog Show")
 8    def OnDialogClose(self):
 9        print("Dialog Close")
10        return True
11 
12 mydialog = RLPy.RUi.CreateRDialog()
13 mycallback = MyDialogCallback()
14 
15 # register dialog event
16 dialog_register_id = mydialog.RegisterEventCallBack(mycallback)
17 mydialog.Show() #print "Dialog Show"
18 
19 # use id to unregister
20 status = mydialog.UnregisterEventCallback(dialog_register_id )

See Also: RIDialog, RIDockWidget

Member Functions

OnDialogHide ( self )

This event is called when this dialog is hidden. When a dialog's close button is pressed, OnDialogHide will be called first, followed by OnDialogClose. When a docakable window is docked within the main window, OnDialogHide will be callsed first, followed by OnDialogShow.

 1 class MyDialogCallback(RLPy.RDialogCallback):
 2    def __init__(self):
 3        RLPy.RDialogCallback.__init__(self)
 4    def OnDialogHide(self):
 5        print("Dialog Hide")
 6 
 7 mydialog = RLPy.RUi.CreateRDialog()
 8 mycallback = MyDialogCallback()
 9 
10 # register dialog event
11 dialog_register_id = mydialog.RegisterEventCallBack(mycallback)
12 mydialog.Hide() #print "Dialog Hide"

OnDialogShow ( self )

This event is called when this dialog is shown. Initialization protocals is most suited for execution at this time. When dockable window is docked within the main window, OnDialogHide will be called first, followed by OnDialogShow.

 1 class MyDialogCallback(RLPy.RDialogCallback):
 2    def __init__(self):
 3        RLPy.RDialogCallback.__init__(self)
 4    def OnDialogShow(self):
 5        print("Dialog Show")
 6 
 7 mydialog = RLPy.RUi.CreateRDialog()
 8 mycallback = MyDialogCallback()
 9 
10 # register dialog event
11 dialog_register_id = mydialog.RegisterEventCallBack(mycallback)
12 mydialog.Show() #print "Dialog Show"

OnDialogClose ( self )

This event is called when this dialog is about to be closed and return whether it is truly closed as confirmed by the application. When a dialog's close button is pressed, OnDialogHide will be called first, followed by OnDialogClose.

Returns

Whether the dialog is truly closed according to the application - boolean
 1 class MyDialogCallback(RLPy.RDialogCallback):
 2    def __init__(self):
 3        RLPy.RDialogCallback.__init__(self)
 4    def OnDialogClose(self):
 5        print("Dialog Close")
 6        return true
 7 
 8 mydialog = RLPy.RUi.CreateRDialog()
 9 mycallback = MyDialogCallback()
10 
11 # register dialog event
12 dialog_register_id = mydialog.RegisterEventCallBack(mycallback)
13 mydialog.Close() #print "Dialog Close"