One thing I would worry about with that method is what happens in the case of an exception somewhere in the UI's __init__ after creating the scriptJob. This is overkill in this case (try/except would probably be just fine), but I'm a fan of contextManagers for this type of 'i really need to make sure something happens' behavior. Maybe something like this:
from __future__ import with_statement
import maya.cmds as MC
from PyQt4 import QtGui, QtCore
class ScriptJobCreator(object):
"""A context manager for creating script jobs"""
def __init__(self):
self.id = None
def createJob(self, *args, **kwargs):
self.id = MC.scriptJob(*args, **kwargs)
return
self.id
def killJob(self):
if
self.id:
MC.scriptJob(kill=
self.id)
self.id = None
def __enter__(self):
return self
def __exit__(self, exc_type, exc_val, exc_tb):
if exc_type is not None:
self.killJob()
class DummyDialog(QtGui.QDialog):
def __init__(self, parent=None):
super(DummyDialog, self).__init__(parent=parent)
with ScriptJobCreator() as sjc:
self.id = sjc.createJob(e=['SelectionChanged', self.updateUI])
#THISWILLHOSEIT if uncommented. Give it a shot.
layout = QtGui.QGridLayout()
dummyObj = QtGui.QPushButton("Dummy")
layout.addWidget(dummyObj,0,0)
self.setLayout(layout)
def updateUI(self):
print "I'm Updaing!"
def closeEvent(self, e):
MC.scriptJob(kill=
self.id)
super(DummyDialog, self).closeEvent(e)
def initUI():
dialog = DummyDialog()
dialog.show()
initUI()