Skip to content

Instantly share code, notes, and snippets.

@csaez
Last active August 29, 2015 14:04
Show Gist options
  • Save csaez/5f5a41bbf2a68b7bad95 to your computer and use it in GitHub Desktop.
Save csaez/5f5a41bbf2a68b7bad95 to your computer and use it in GitHub Desktop.
Hard reloader for maya (reload python modules)
import sys
from PySide import QtGui, QtCore
from shiboken import wrapInstance
from maya import OpenMayaUI
class HardReload(QtGui.QDialog):
def __init__(self, *args, **kwds):
super(HardReload, self).__init__(*args, **kwds)
self.setAttribute(QtCore.Qt.WA_DeleteOnClose, True)
self.initUI()
def initUI(self):
self.ui_lineEdit = QtGui.QLineEdit(self)
ui_completer = QtGui.QCompleter(
[i.split(".")[0] for i in sys.modules.keys()], self)
ui_completer.setCompletionMode(QtGui.QCompleter.InlineCompletion)
ui_completer.setCaseSensitivity(QtCore.Qt.CaseInsensitive)
self.ui_lineEdit.setCompleter(ui_completer)
hbox = QtGui.QHBoxLayout()
hbox.addWidget(self.ui_lineEdit)
self.setLayout(hbox)
self.setWindowTitle("Hard Reload")
self.ui_lineEdit.returnPressed.connect(self.accept)
def accept(self, *args, **kwds):
module = str(self.ui_lineEdit.text())
if len(module):
for k in sys.modules.keys():
if k.startswith(module):
del sys.modules[k]
super(HardReload, self).close(*args, **kwds)
def get_parent():
ptr = OpenMayaUI.MQtUtil.mainWindow()
return wrapInstance(long(ptr), QtGui.QMainWindow)
def show():
HardReload(get_parent()).exec_()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment