n = m.addMenu("Snap") n.addCommand("Match selection position", "nukescripts.snap3d.translateToPoints(nuke.selectedNode())") n.addCommand( "Match selection position, orientation", "nukescripts.snap3d.translateRotateToPoints(nuke.selectedNode())") n.addCommand( "Match selection position, orientation, size", "nukescripts.snap3d.translateRotateScaleToPoints(nuke.selectedNode())") del m del n del isLinux ################################################################ # non-menu stuff: # # The stuff that lives here can't run in render mode or is # pointless to run in render mode, so this way it only gets run # if the GUI is starting up. # Restore the default layout (number 1) nuke.restoreWindowLayout(1) # back-compatibility handling of autolabel. Load any autolabel.py we # find and then register it so nuke.autolabel() calls it. User can # override this by defining another version somewhere # earlier in your NUKE_PATH, for instance $HOME/.nuke/menu.py. from autolabel import autolabel nuke.addAutolabel(autolabel)
def restoreWindowLayout(self, layout=1): nuke.restoreWindowLayout(layout)
def knobChanged(self, knob): # refresh & execute if knob == self.cmdGo: global package global module global function package = self.package.value() module = self.module.value() function = self.function.value() if function == "Panel? (Leave this if it is)": #userInput = nuke.getInput('For a panel refresh, the whole window layout has to be updated.\nEnter the number of the window layout you want to restore', '1') #layoutToRestore = int(userInput) layoutToRestore = self.restoreLayout.value() if layoutToRestore > 0: moduleUpdate(module, function, package, True) #nuke.getPaneFor("uk.co.thefoundry.moduleUpdater").destroy() nuke.restoreWindowLayout(layoutToRestore) else: moduleUpdate(module, function, package) # print source of module elif knob == self.cmdPrint: try: print inspect.getsource(sys.modules.get(self.module.value())) except: nuke.message("Sorry, didn't work") # copy source of module to clipboard elif knob == self.cmdClipboard: allmodules = sys.modules iter = allmodules.itervalues() while True: try: strCurrModule = str(iter.next()) if module in strCurrModule: pyfile = strCurrModule.replace("\\", "\\\\").replace( "/", "\\\\") pyfile = pyfile[pyfile.find("from") + 6:(pyfile.find(".py") + 3)] try: subprocess.Popen('cmd /c start ' + pyfile) #srcModule = inspect.getsource(sys.modules.get(self.module.value())) #clipboard = QtGui.QApplication.clipboard() #clipboard.setText(srcModule) # set clipboard break except: nuke.message("Sorry, didn't work") #print strCurrModule except: break # update list of modules elif knob == self.cmdUpdate: if self.path.value() == "": nuke.message( "Module/function list require a path to work. You can still enter the name of your module with the function to execute manually though." ) self.moduleList.setValues([]) self.module.setValue("") self.functionList.setValues([]) self.function.setValue("") return # update module list AND call callback for it to refresh function list as well self.updateModuleList() self.knobChanged(self.moduleList) # transfer selected function to text field elif knob == self.functionList: self.function.setValue(self.functionList.value()) # transfer selected module to text field (and update function list) elif knob == self.moduleList: module = self.moduleList.value() if module != "": self.module.setValue(module) # reset current function name self.function.setValue("") # get function list for currently selected module strFunctions = [] functions = inspect.getmembers(sys.modules.get(module), inspect.isfunction) for function in functions: strFunctions.append(function[0]) self.functionList.setValues(strFunctions) # attempt to find out whether module is a panel try: moduleSource = inspect.getsource(sys.modules.get(module)) except: nuke.message( "Could not read the module. Please check whether the python file still exists or restart Nuke (Module Updater always shows the currently loaded modules)." ) return if "PythonPanel" in moduleSource or "QWidget" in moduleSource: self.function.setValue("Panel? (Leave this if it is)") elif len(strFunctions) == 1: self.function.setValue(strFunctions[0]) elif strFunctions == []: self.function.setValue("No executable function found") # reset currently selected function list item to first one self.functionList.setValue(0) self.saveSettings()