Difference between revisions of "IC Python API:RLPy RDialogCallback"
Chuck (RL) (Talk | contribs) m (→Detailed Description) |
Chuck (RL) (Talk | contribs) m |
||
Line 1: | Line 1: | ||
{{TOC}} | {{TOC}} | ||
{{Parent|IC_Python_API:RL_Python_Modules|Modules}} | {{Parent|IC_Python_API:RL_Python_Modules|Modules}} | ||
− | == | + | {{last_modified}} |
− | This class inherits | + | |
− | + | == 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 [[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 RegisterEvenetCallback and a registration id will returned. This id can be used later to unregister the callback function. The corresponding callback function will be called when a dialog is shown, hidden, or closed. | |
− | <syntaxhighlight lang=" | + | |
+ | [[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): | |
− | + | RLPy.RDialogCallback.__init__(self) | |
− | + | def OnDialogHide(self): | |
− | + | print("Dialog Hide") | |
− | + | def OnDialogShow(self): | |
− | + | print("Dialog Show") | |
− | + | def OnDialogClose(self): | |
− | + | print("Dialog Close") | |
− | + | return True | |
− | mydialog = RUi.CreateRDialog() | + | |
+ | mydialog = RLPy.RUi.CreateRDialog() | ||
mycallback = MyDialogCallback() | mycallback = MyDialogCallback() | ||
− | mydialog. | + | |
+ | # 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 == | ||
− | === | + | |
− | <syntaxhighlight lang=" | + | === OnDialogHide ( self ) === |
− | RLPy.RDialogCallback. | + | |
+ | 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> | ||
− | + | ||
− | === | + | === 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. | |
− | + | ||
− | + | <syntaxhighlight lang="python" line='line'> | |
− | + | class MyDialogCallback(RLPy.RDialogCallback): | |
− | <syntaxhighlight lang=" | + | def __init__(self): |
− | RLPy.RDialogCallback. | + | 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> | ||
− | + | ||
− | + | === OnDialogClose ( self ) === | |
− | === | + | |
− | <syntaxhighlight lang=" | + | This event is called when this dialog is about to be closed and return whether it is trully closed as decided by the application. When a dialog's close button is pressed, OnDialogHide will be called first, followed by OnDialogClose. |
− | RLPy.RDialogCallback. | + | |
+ | ==== 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> | ||
− |
Revision as of 23:30, 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 RegisterEvenetCallback and a registration id will returned. This id can be used later to unregister the callback function. The corresponding callback function will be called when a dialog is shown, hidden, or closed.
RDialogCallbackcan 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 trully closed as decided 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"