Example #1
0
def setup(name, config, *args):
    """
    Applies the given data to a hotkey. Anything that will be overwritten is saved in
    the melDrop prefs file: melDrop.json located in your Maya versions pref folder.
    """
    label = makeKeyLabel(config)
    # remember current settings if there are any.
    # gather returns empty dict if not but we save that anyway to just delete
    # the hotkey when its deactivated
    current = gather(config['key'], ctl=config.get('ctl', False), alt=config.get('alt', False))
    fromLabel = ''
    if current:
        fromLabel = ' (from: %s)' % current['name']
    
        prefsDict = prefs.getPrefs()
        if 'hotkeyBackups' not in prefsDict:
            prefsDict['hotkeyBackups'] = {}
        
        if label not in prefsDict['hotkeyBackups']:
            prefsDict['hotkeyBackups'][label] = current
            prefs.setPrefs(prefsDict)
    
    # now just set it
    setHotkey(name, config)
    log.info('set: (%s) %s%s' % (label, name, fromLabel))
Example #2
0
def reset(name, config, keyLabel, *args):
    """
    I wish I could actually delete a hotkey completely! But there is no way!
    I can not even hack the userHotkeys.mel and userNamedCommands.mel prefs file!
    Because they might be overwritten anytime.
    """
    prefsDict = prefs.getPrefs()
    if keyLabel not in prefsDict['hotkeyBackups']:
        log.error('keyLabel "%s" could not be found to restore')
        return
    backup = prefsDict['hotkeyBackups'][keyLabel]
    if not backup:
        cmds.hotkey(k=config['key'], name="", alt=config.get('alt', False), ctl=config.get('ctl', False))
        log.info('removed: (%s)' % keyLabel)
    else:
        setHotkey(backup['name'], backup)
        log.info('restored: (%s) %s ' % (keyLabel, backup['name']))
    
    if cmds.runTimeCommand(name, ex=True) and not cmds.runTimeCommand(name, q=True, default=True):
        cmds.runTimeCommand(name, e=True, delete=True)

    prefsDict['hotkeyBackups'].pop(keyLabel)
    prefs.setPrefs(prefsDict)
Example #3
0
 def __init__(self):
     self.prefsDict = getPrefs()
     self.buildUi()
     self.root = dirname(dirname(dirname(__file__)))
     self.refresh()