def loadHotkeys(self, defaults=False): allHotkeys = hotkeys.getHotkeys() hotkeysDict = [] for n, loopHotkey in enumerate(allHotkeys): for loopItem in loopHotkey: hotkeysDict.append(loopItem) for loopIndex, loopCommand in enumerate(hotkeysDict): command = loopCommand["command"] name = loopCommand["name"] key = loopCommand["hotkey"] alt = loopCommand["alt"] ctl = loopCommand["ctl"] toolTip = loopCommand["toolTip"] if not defaults: hotkeyData = aToolsMod.loadInfoWithUser("hotkeys", name) if hotkeyData != None: key = hotkeyData[0] alt = hotkeyData[1] ctl = hotkeyData[2] cmds.checkBox('ctl%s'%name, edit=True, value=ctl) cmds.checkBox('alt%s'%name, edit=True, value=alt) cmds.scrollField('key%s'%name, edit=True, text=key) self.updateHotkeyCheck(name)
def reassignCommandsAtStartup(self): allHotkeys = hotkeys.getHotkeys() hotkeysDict = [] for n, loopHotkey in enumerate(allHotkeys): for loopItem in loopHotkey: hotkeysDict.append(loopItem) for loopCommand in hotkeysDict: command = loopCommand["command"] name = loopCommand["name"] key = loopCommand["hotkey"] alt = loopCommand["alt"] ctl = loopCommand["ctl"] #toolTip = loopCommand["toolTip"] label = self.hotkeyCheck(key, ctl, alt) if label == name: cmds.nameCommand(name, command='python("%s");'%command, annotation=name)
def openGui(self, *args): winName = "commandsWindow" height = 26 commands = [] names = [] hotkeysDict = [[]] allHotkeys = hotkeys.getHotkeys() totalItems = sum(len(x) for x in allHotkeys) itemsCount = 0 aB = 0 totalColums = 2 for n, loopHotkey in enumerate(allHotkeys): if itemsCount > (totalItems/totalColums) * (aB+1): aB += 1 hotkeysDict.append([]) itemsCount += len(loopHotkey) for loopItem in loopHotkey: hotkeysDict[aB].append(loopItem) hotkeysDict[aB][-1]["colorValue"] = self.colorValues[self.allColors[n]] if cmds.window(winName, query=True, exists=True): cmds.deleteUI(winName) window = cmds.window( winName, title = "Commands and Hotkeys") mainLayout = cmds.columnLayout(adjustableColumn=True) columnsLayout = cmds.rowColumnLayout(numberOfColumns=totalColums) for loopColumn in xrange(totalColums): parent = cmds.rowColumnLayout(numberOfColumns=7, columnSpacing=([2,5], [3,3], [4,3], [5,1], [6,5], [7,5]), parent=columnsLayout) cmds.text(label='Command', h=height) cmds.text(label='Ctl', h=height) cmds.text(label='Alt', h=height) cmds.text(label='Key', h=height) cmds.text(label='', h=height) cmds.text(label='Set Hotkey', h=height) cmds.text(label='Assigned to', align="left", h=height) for loopIndex, loopCommand in enumerate(hotkeysDict[loopColumn]): command = loopCommand["command"] name = loopCommand["name"] key = loopCommand["hotkey"] alt = loopCommand["alt"] ctl = loopCommand["ctl"] toolTip = loopCommand["toolTip"] color = loopCommand["colorValue"] hotkeyData = aToolsMod.loadInfoWithUser("hotkeys", name) if hotkeyData != None: key = hotkeyData[0] alt = hotkeyData[1] ctl = hotkeyData[2] cmds.button("command%s"%name, label=utilMod.toTitle(name), command=command, annotation=toolTip, h=height, bgc=color, parent=parent) cmds.checkBox('ctl%s'%name, label='', value=ctl, changeCommand=lambda x, name=name, *args:self.updateHotkeyCheck(name), h=height, parent=parent) cmds.checkBox('alt%s'%name, label='', value=alt, changeCommand=lambda x, name=name, *args:self.updateHotkeyCheck(name), h=height, parent=parent) cmds.scrollField('key%s'%name, w=80, text=key, keyPressCommand=lambda x, name=name, *args:self.updateHotkeyCheck(name), h=height, parent=parent) cmds.button(label=" ", h=height, parent=parent) self.popSpecialHotkeys(name) cmds.button(label='>', command=lambda x, name=name, command=command, *args: self.setHotkey(self.getHotkeyDict([name], [command])), h=height, parent=parent) cmds.text("query%s"%name, align="left", label=self.hotkeyCheck(key, ctl, alt), font="plainLabelFont", h=height, parent=parent) commands.append(command) names.append(name) #cmds.button(label="Set Hotkey", command=lambda *args: getHotkeyDict([name], [command], [key], [alt], [ctl], [cmd])) self.updateHotkeyCheck(name) #cmds.rowLayout(numberOfColumns=2, columnAttach=([1, 'left', 0],[2, 'right', 0]), adjustableColumn=2) cmds.button(label="Load Defaults", command=lambda *args: self.loadHotkeys(True), parent=mainLayout) cmds.button(label="Set All Hotkeys", command=lambda *args: self.setHotkey(self.getHotkeyDict(names, commands)), parent=mainLayout) cmds.showWindow( window )