Difference between revisions of "IC Python API:RLPy RDialogCallback"
Chuck (RL) (Talk | contribs) m |
Chuck (RL) (Talk | contribs) m |
||
Line 7: | Line 7: | ||
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. | 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. | ||
− | [[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. | + | [[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 === | === Inheritance === |
Latest revision as of 23:37, 29 April 2020
- Main article: Modules.
- Last modified: 04/29/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"