So your best case it to keep a reference to the dialog somewhere, and check to see if it already exists.
So this should work in the script editor, and at the module level in an imported file. This won't work if you wrap it in a function though, as the function namespace isn't retained between executions.
And is fairly similar to the usual, if window exists, delete window idiom.
from PySide import QtCore, QtGui
from shiboken import wrapInstance
import maya.OpenMayaUI as omui
main_window_ptr = omui.MQtUtil.mainWindow()
return wrapInstance(long(main_window_ptr), QtGui.QWidget)
def __init__(self, parent=None):
except NameError as e:
myWin = ControlMainWindow(parent=maya_main_window())
Usually the better option is to keep a reference to your dialog somewhere, say an instance variable on a tool, and just check that to see if the dialog is already initialized and visible. Though that can get tricky if you're reloading the tool each time you launch it.