Profile Picture

Equivalent to initialize_plugin() called on exit?

Posted By will.cowling.uk 5 Years Ago
You don't have permission to rate!
Author
Message
will.cowling.uk
will.cowling.uk
Posted 5 Years Ago
View Quick Profile
Junior Member

Junior Member (243 reputation)Junior Member (243 reputation)Junior Member (243 reputation)Junior Member (243 reputation)Junior Member (243 reputation)Junior Member (243 reputation)Junior Member (243 reputation)Junior Member (243 reputation)Junior Member (243 reputation)

Group: Forum Members
Last Active: 2 Years Ago
Posts: 11, Visits: 115
Hi,

If I'm writing a iClone plugin using the python API, then in my main.py the function initialize_plugin() is called when it starts up.  What, if anything is called when the plugin/application exits?
I've tried uninitialize_plugin, destroy_plugin, shutdown_plugin.  Is there something like this available?  Is so, what should the function be called?

Thanks,
Will

jlittle
jlittle
Posted 5 Years Ago
View Quick Profile
Distinguished Member

Distinguished Member (6.7K reputation)Distinguished Member (6.7K reputation)Distinguished Member (6.7K reputation)Distinguished Member (6.7K reputation)Distinguished Member (6.7K reputation)Distinguished Member (6.7K reputation)Distinguished Member (6.7K reputation)Distinguished Member (6.7K reputation)Distinguished Member (6.7K reputation)

Group: Forum Members
Last Active: Yesterday
Posts: 1.9K, Visits: 17.1K
Here is what I have done:
Create a procedure to be executed upon exit:
def onExitProc(result):
In this procedure unregister any event callbacks, etc.

Then, in the initialization procedure where you create your app dialog window, connect the exit procedure to the dialogs finished event.
myDialog = create_dialog()
# setup exit proc
myDialog.finished.connect(onExitProc)

Then when you dialog closes it will execute your exit procedure.

The procedure create_dialog() is my routine that creates my apps window, loads the Qt info, and connects all the buttons events, etc.

Hope that helps.
Jeff





Get my Plugin Manager and TaskNotes plugins for iClone.
Check out EZColors and Other products for CTA/CA. EZColors: the easy way to change Render Styled (RS) colors!
See my CTA Tutorials on the YouTube channel CTAStepByStep

Edited
5 Years Ago by jlittle
will.cowling.uk
will.cowling.uk
Posted 5 Years Ago
View Quick Profile
Junior Member

Junior Member (243 reputation)Junior Member (243 reputation)Junior Member (243 reputation)Junior Member (243 reputation)Junior Member (243 reputation)Junior Member (243 reputation)Junior Member (243 reputation)Junior Member (243 reputation)Junior Member (243 reputation)

Group: Forum Members
Last Active: 2 Years Ago
Posts: 11, Visits: 115
Many thanks for the info.  Could you clarify what type myDialog is in your example?  Is it an RlDialog created with RUi.CreateRDialog?  Or something else?
Thanks,
Will

Edited
5 Years Ago by will.cowling.uk
jlittle
jlittle
Posted 5 Years Ago
View Quick Profile
Distinguished Member

Distinguished Member (6.7K reputation)Distinguished Member (6.7K reputation)Distinguished Member (6.7K reputation)Distinguished Member (6.7K reputation)Distinguished Member (6.7K reputation)Distinguished Member (6.7K reputation)Distinguished Member (6.7K reputation)Distinguished Member (6.7K reputation)Distinguished Member (6.7K reputation)

Group: Forum Members
Last Active: Yesterday
Posts: 1.9K, Visits: 17.1K
Will,
Here is a striped down version of one of my programs:
import PySide2, RLPy, os
from PySide2 import *
from PySide2.QtCore import *
from PySide2.QtCore import QResource
from PySide2.QtCore import QFile
from PySide2.QtCore import QIODevice
from PySide2.QtGui import *
from PySide2.QtUiTools import QUiLoader
from PySide2.QtWidgets import *
from PySide2.shiboken2 import wrapInstance
import csv


myDialog = None

eventCallback = None
eventCallbackId = None

#---------------------------------------
# event callback class
#---------------------------------------
class MyEventCallback(RLPy.REventCallback):
def __init__(self):
RLPy.REventCallback.__init__(self)
def OnObjectSelectionChanged(self):
icpropSelectionChanged()


#---------------------------------------
# on exit cleanup procedure
#---------------------------------------
def onExitProc(result):
global eventCallbackId
# unregister event handler
status = RLPy.REventHandler.UnregisterCallback(eventCallbackId)


#---------------------------------------
# initialize
#---------------------------------------
def initialize_script():
global myDialog
# register RL event callback
eventCallback = MyEventCallback()
eventCallbackId = RLPy.REventHandler.RegisterCallback(eventCallback)

if myDialog is None:
myDialog = create_dialog()
# setup exit proc
myDialog.finished.connect(onExitProc)

myDialog.show()


#---------------------------------------
# create the main dialog window
#---------------------------------------
def create_dialog():
global myDialog

main_widget = wrapInstance(int(RLPy.RUi.GetMainWindow()), PySide2.QtWidgets.QWidget)

dlg = PySide2.QtWidgets.QDialog(main_widget) # set parent to main window

# Load Qt Ui file into ui_widget
ui_file = QtCore.QFile(os.path.dirname(__file__) + "/uiLayoutFile.ui")
ui_file.open(QtCore.QFile.ReadOnly)
ui_widget = QtUiTools.QUiLoader().load(ui_file)
ui_file.close()

# Make the RL Dialog
ui_dialog = RLPy.RUi.CreateRDialog()
# Wrap to PySide Dialog
pyside_dialog = wrapInstance(int(ui_dialog.GetWindow()), QtWidgets.QDialog)
ui_layout = pyside_dialog.layout()
ui_widget.hide
ui_layout.addWidget(ui_widget)
dlg.setLayout(ui_layout)

return dlg


#################################################

#---------------------------------------
# Start Script
#---------------------------------------
def run_script():
initialize_script()


Jeff



Get my Plugin Manager and TaskNotes plugins for iClone.
Check out EZColors and Other products for CTA/CA. EZColors: the easy way to change Render Styled (RS) colors!
See my CTA Tutorials on the YouTube channel CTAStepByStep

will.cowling.uk
will.cowling.uk
Posted 5 Years Ago
View Quick Profile
Junior Member

Junior Member (243 reputation)Junior Member (243 reputation)Junior Member (243 reputation)Junior Member (243 reputation)Junior Member (243 reputation)Junior Member (243 reputation)Junior Member (243 reputation)Junior Member (243 reputation)Junior Member (243 reputation)

Group: Forum Members
Last Active: 2 Years Ago
Posts: 11, Visits: 115
Awesome, many thanks.
Thanks for posting the code.  It's much clearer now.
Cheers,
Will





Reading This Topic