示例#1
0
 def cycleKeySet(self,backwards=False):
     ## this should cycle between hotkey sets
     
     #first make a list of all hotkey sets
     #sort it alphabetically and make an index for each one
     #get the index of our current set
     # if there is a next index, switch to it
     # else we are last index, switch to index 0
     sets = pm.hotkeySet( query=True, hotkeySetArray=True)
     sets.sort()
     currentSet = pm.hotkeySet( current=True, query=True )
     #print( sets )
     #print( currentSet )
     
     index = sets.index(currentSet)
     
     if not backwards:
         index += 1
         if index >= len(sets):
             index=0
     else:
         index -= 1
         if index < 0:
             index = len(sets)-1
             
     newKeySet = sets[index]
     om.MGlobal.displayInfo( newKeySet + "  Hotkey Set Activated" );
     pm.hotkeySet( newKeySet, current=True, edit=True )
示例#2
0
 def createHotkeySet(self, keySetFullName, sourceSetName = "Maya_Default", ):
     isDeleted = False
     isExisting = pm.hotkeySet( keySetFullName, query=True, exists=True)
     if isExisting==True:
         print( "deleting")
         isDeleted = pm.hotkeySet( keySetFullName, edit=True, delete=True)
     else:
         print( "not deleting, did not already exist")
     
     result = pm.hotkeySet( keySetFullName, source = sourceSetName )  ## create=True is implied but can't be specified without maya error        
示例#3
0
    def __init__(self, parent):
        """
        Initialize Everything and Setup The Hotkeys manager so it can be called later.
        The calling object should be passed as a parent when this class is created.
        """
        ## Setup initial references to the main MmmmTools system and its importand parts such as configuration
        self.parent = parent
        self.mmmm = self.parent
        self.keySetPrefix = "Mmmm_"
        self.entryListsByKeySet = {}
        self.initModulesForDefinitions()
        ## self.initEntriesForDefault()
        
        #keySetFullName = self.keySetPrefix + keySetShortName
        for entryListName, entryList   in   self.entryListsByKeySet.items():
            self.createHotkeySet( entryListName )
            for entry in entryList:
                entry['set'] = entryListName
                self.createHotkeyAndRequiredFromEntry( entry )
        
        if  pm.hotkeySet( current=True, query=True ).startswith( "Mmmm_" ):
            pm.hotkeySet( "Maya_Default", current=True, edit=True )

        commander = self.mmmm.commander     
        commander.addCommand(
            'Hotkeys/HotkeysUi',
            self.createUi    
        )
        
        commander.addCommand(
            'Hotkeys/NextKeySet',
            self.nextKeySet
        )
        commander.addCommand(
            'Hotkeys/PrevKeySet',
            self.prevKeySet
        )
示例#4
0
 def onDropDownChange(self,selected):
     pm.hotkeySet( selected, current=True, edit=True )
     om.MGlobal.displayInfo( selected + "  Hotkey Set Activated" );
示例#5
0
    def __init__(self, parentRef, parentWidget=None, mmmm=None ):
        self.parentRef = parentRef
        self.buttons = []
        self.widgets = {}
        
        self.mmmm = mmmm
        

        if parentWidget==None:
            parentWidget = self.widgets['parentWidget'] = pm.Window(
                sizeable = True, title = "Mmmm Hotkeys Manager", titleBar=True
            )
        else:
            self.widgets['parentWidget'] = parentWidget

        with parentWidget:
            self.layout = pm.columnLayout()
            with self.layout:
            
                self.widgets['editorBtn'] =  pm.button( "Maya Hotkey Editor Window...",
                    annotation=
                        "Open the Maya's default builtin hotkey editor window. "
                        +
                        " There is nothing MmmmTools specific about this, it's just a shortcut.",
                    command='pm.mel.eval("HotkeyPreferencesWindow;")',
                )
                
                self.widgets['infoText'] = pm.text("\nInstructions (read tooltip, hover here)\n",
                                    annotation = 
                      "Note that users should avoid editing the hotkey sets \n"
                    + "starting with Mmmm. If you wish to modify them, \n"
                    + "you should duplicate the Mmmm keyset you want to modify, \n"
                    + "rename, so it does not start with Mmmm, and make change to your own copy. \n\n"
                    + "Changing the Mmmm keySets themselves requires writing/altering python code. \n"
                    + "Our recommendation is that for your own hotkeys, you make your own hotkey sets, \n"
                    + "and switch to them as necessary. (See other button tooltips for more info.)"
                )
                
                                
                self.widgets['nextKeySetBtn'] = pm.button( "Next Hotkey Set",
                    command = lambda x: self.parentRef.nextKeySet(),
                    annotation="Go to the next keyset, in alphabetical order. \n\n "
                    + "In case you want to add it to a shelf/button: \n"
                    + "The mel command to do this is: MmmmCmds__Hotkeys__NextKeySet",
                )
                self.widgets['prevKeySetBtn'] = pm.button( "Prev Hotkey Set",
                    command = lambda x: self.parentRef.prevKeySet(),
                    annotation="Go to the previous keyset, in alphabetical order. \n\n "
                    + "In case you want to add it to a shelf/button: \n"
                    + "The mel command to do this is: MmmmCmds__Hotkeys__PrevKeySet",
                )
                
                #self.widgets['refreshListBtn'] = pm.button( "Refresh Hotkey Set Dropdown List" )
                self.widgets['dropdownLabel'] =  pm.text("\n Choose active hotkey set:",
                    annotation="You may need to either click the refresh button, "
                    +"or if that is unavailable, close and reopen this window, to refresh the list."
                )
                
                self.widgets['dropdown'] = pm.optionMenu( "MmmmKeySetDropdownMenu", 
                    changeCommand = self.onDropDownChange,
                )
                keySets = pm.hotkeySet( query=True, hotkeySetArray=True)
                keySets.sort()
                for keySet in keySets :
                    pm.menuItem( keySet )
示例#6
0
    def createHotkeyAndRequiredFromEntry(self, entry ):
        hotkeySetAtFunctionStart = pm.hotkeySet( current=True, query=True )

        i = entry                  
        pm.hotkeySet( i['set'], current=True, edit=True )


        ## Determine which modifiers are being used. (Because Maya is already naturally
        ## sensitive to shift, by using capitals or symbols, we don't test for shift.
        try:
            try:
                isCtl=i['ctl']
            except:
                isCtl=False
            try:
                isAlt=i['alt']
            except:
                isAlt=False
        except:
            pass
        ## Based on the above logic, generate strings to be used while creating the hotkeys.    
        if isAlt == True:
            AltString = " Alt + "
        else:
            AltString = " "        
        if isCtl == True:
            CtlString = " Ctrl + "
        else:
            CtlString = " "

        if not i.get('doRelease',False):
            ## Create a printout of the command being made and the hotkey that will use it.
            print(  "About to add runTimeCommand and nameCommand named "\
                + i['name'] + "         Pushing: " + CtlString + AltString + i['key']  )
            try:
                if cmds.runTimeCommand( i['name'], q=True, exists=True ):
                    cmds.runTimeCommand( i['name'], e=True, delete=True )
                    
                cmds.runTimeCommand(
                    i['name'],
                    annotation=i['annotation'],
                    category="Custom Scripts",
                    commandLanguage="mel",
                    hotkeyCtx="",
                    command=i['mel']
                )
            except:
                print( "Error Creating Runtime Command" )                            
                print( traceback.format_exc()  )
                
            try:
                cmds.nameCommand(
                    i['name']+"NameCommand",
                    annotation=i['annotation'],
                    sourceType='mel',
                    command=i['name']
                )
            except:
                print( "Error Creating Named Command" )
            ## Add the actual hotkey to Maya.
            try:                    
                cmds.hotkey( k=i['key'], name=i['name']+"NameCommand", ctl=isCtl, alt=isAlt)
            except:
                print( "Error Binding Hotkey" )
                print( traceback.format_exc()  )


        
        if i.get('doRelease',False):
            ## Create a printout of the command being made and the hotkey that will use it.
            print(  "About to add nameCommandRelease named " + i['name'] + "         Releasing: " + CtlString + AltString + i['key']  )
            
        try:
            if cmds.runTimeCommand( i['name']+"Release", q=True, exists=True ):
                cmds.runTimeCommand( i['name']+"Release", e=True, delete=True )
                
            cmds.runTimeCommand(
                i['name']+"Release",
                annotation=i['annotation'],
                category="Custom Scripts",
                commandLanguage="mel",
                hotkeyCtx="",
                command=i['mel']
            )
        except:
            print( "Error Creating Runtime Command" )                            
            print( traceback.format_exc()  )            
            
            try:
                cmds.nameCommand( i['name']+"Release", annotation=i['annotation']+"Release", command=i['mel']+"Release" )
            except:
                print( "Error Creating Named Command" )

            ## Add the actual hotkey to Maya.                
            try:
                ##Its very important that Release is added to name string below.
                cmds.hotkey( k=i['key'], ctl=isCtl, alt=isAlt ,releaseName=i['name']+"Release" )
            except:
                print( "Error Binding Hotkey" )                    

        pm.hotkeySet( hotkeySetAtFunctionStart, current=True, edit=True )
示例#7
0
 def switchToHotkeySet( self, keySetFullName ):
     pm.hotkeySet( keySetFullName, edit=True, current=True)
示例#8
0
 def switchToHotkeySet( self, keySetNameNoPrefix ):
     self.switchToHotkeySet( self.keySetPrefix)
     pm.hotkeySet( keySetFullName, edit=True, current=True)
示例#9
0
 def listHotkeySets(self):
     sets = pm.hotkeySet( query=True, hotkeySetArray=True)
     print(sets)
     return sets