Ejemplo n.º 1
0
    def instantiate(self, parent=None):
        if parent is None:
            parent = gui.wrap(self.parent)

        # initializes all the shelves
        if parent.selectTab:
            current_tab = parent.selectTab
            for child in parent.childArray:
                parent.selectTab = child

            parent.selectTab = current_tab

        for shelf in parent.controls:
            if shelf.key == self.key:
                break
        else:
            with parent.as_parent():
                shelf = self.proxy(self.key)
    
                # Needed so that we don't throw a weird maya error until the next restart.
                # Pulled this from the shelf editor mel script.
                if parent == 'ShelfLayout':
                    cmds.optionVar(stringValue=('shelfName{}'.format(parent.numberOfChildren), self.key))
                    cmds.optionVar(intValue=('shelfLoad{}'.format(parent.numberOfChildren), True))
                    cmds.optionVar(stringValue=('shelfFile{}'.format(parent.numberOfChildren), ''))

        for ctrl in self.controls:
            ctrl.instantiate(shelf)

        cmds.saveAllShelves(parent)
Ejemplo n.º 2
0
    def instantiate(self, parent=None):
        if parent is None:
            parent = gui.wrap(self.parent)

        # initializes all the shelves
        current_tab = parent.selectTab
        for child in parent.childArray:
            parent.selectTab = child

        parent.selectTab = current_tab

        for shelf in parent.controls:
            if shelf.key == self.key:
                break
        else:
            with parent.as_parent():
                shelf = self.proxy(self.key)
                # Needed so that we don't throw a weird maya error until the next restart.
                # Pulled this from the shelf editor mel script.
                cmds.optionVar(
                    stringValue=('shelfName{}'.format(parent.numberOfChildren),
                                 self.key))
                cmds.optionVar(
                    intValue=('shelfLoad{}'.format(parent.numberOfChildren),
                              True))
                cmds.optionVar(
                    stringValue=('shelfFile{}'.format(parent.numberOfChildren),
                                 ''))

        for ctrl in self.controls:
            ctrl.instantiate(shelf)

        cmds.saveAllShelves(parent)
Ejemplo n.º 3
0
def removeShelf(shelfName='iQA'):
    """"""
    test = cmds.shelfLayout(shelfName, exists=True)
    if test:
        mel.eval('deleteShelfTab %s' % shelfName)
        gShelfTopLevel = mel.eval('$tempVar=$gShelfTopLevel')
        cmds.saveAllShelves(gShelfTopLevel)
Ejemplo n.º 4
0
def removeShelf():
    # sample code
    shelfName = 'My_Shelf'
    test = cmds.shelfLayout(shelfName, ex=True)
    if test:
        mel.eval('deleteShelfTab %s' % shelfName)
        gShelfTopLevel = mel.eval('$tmpVar=$gShelfTopLevel')
        cmds.saveAllShelves(gShelfTopLevel)
    else:
        return
Ejemplo n.º 5
0
def createShelf():
     iconPath = os.path.abspath(os.path.join(os.path.dirname(CM_Tools.__file__),".."))+"/Icons/"
     gShelfTopLevel = maya.mel.eval('global string $gShelfTopLevel; $temp = $gShelfTopLevel;')
     cmShelf = gShelfTopLevel + '|TurboSquid'
     if cmds.shelfLayout(cmShelf, exists=True):
          cmds.deleteUI(cmShelf)
     if not cmds.shelfLayout(cmShelf, exists=True):
        cmds.setParent(gShelfTopLevel)
        cmds.shelfLayout('TurboSquid')
     else:
        cmds.setParent(cmShelf)
     if not cmds.shelfButton('CheckMate', exists=True):
        checkMateButton = cmds.shelfButton('CheckMate',
            label='CheckMate',
             parent = 'TurboSquid',
            annotation='Run the CheckMate tools on the current scene',
            image1 = iconPath + 'CheckMatePro.png',
            command='from CM_Tools import SystemFile;reload(SystemFile);SystemFile.SystemClass()'
                    )
        print checkMateButton
     cmds.shelfTabLayout(gShelfTopLevel, e=True, st='TurboSquid')
     cmds.saveAllShelves(gShelfTopLevel)
Ejemplo n.º 6
0
def load(shelf_path=None):

    # Default to the Maya shelf path.
    if shelf_path is None:
        shelf_path = os.environ.get('MAYA_SHELF_PATH')
        shelf_path = shelf_path.split(':') if shelf_path else []

    # Single strings should be a list.
    if isinstance(shelf_path, basestring):
        shelf_path = [shelf_path]

    # Clear out the button memory.
    _uuid_to_buttons.clear()

    # Lookup the tab shelf that we will attach to.
    layout = mel.eval('$tmp=$gShelfTopLevel')

    # Store shelf options for restoring later.
    existing_options = {}
    for i, name in enumerate(
            cmds.shelfTabLayout(layout, q=True, childArray=True)):
        if name in existing_options:
            cmds.warning(
                'Multiple shelves with name "%s"? This may cause problems.' %
                name)
        existing_options[name] = opts = {}
        for key in 'Name', 'File', 'Load':
            opts[key] = cmds.optionVar(q="shelf%s%d" % (key, i + 1))

    new_shelves = set()

    for shelf_dir in shelf_path:
        try:
            file_names = sorted(os.listdir(shelf_dir))
        except IOError:
            continue
        for file_name in file_names:
            if file_name.startswith('.') or file_name.startswith(
                    '_') or not file_name.endswith('.yml'):
                continue

            shelf_name = file_name[:-4]
            new_shelves.add(shelf_name)
            print '# %s: %s' % (__name__, shelf_name)

            # Delete buttons on existing shelves, and create shelves that don't
            # already exist.
            if cmds.shelfLayout(shelf_name, q=True, exists=True):
                # Returns None if not loaded yet, so be careful.
                for existing_button in cmds.shelfLayout(
                        shelf_name, q=True, childArray=True) or []:
                    cmds.deleteUI(existing_button)
                cmds.setParent(layout + '|' + shelf_name)
            else:
                cmds.setParent(layout)
                cmds.shelfLayout(shelf_name)

            for b_i, button in enumerate(
                    _iter_buttons(os.path.join(shelf_dir, file_name))):

                button_definition = copy.deepcopy(button)

                # Defaults and basic setup.
                button.setdefault('width', 34)
                button.setdefault('height', 34)

                # Extract keys to remember buttons.
                uuids = [button.get('entrypoint'), button.pop('uuid', None)]

                # Extract other commands.
                doubleclick = button.pop('doubleclick', None)
                popup_menu = button.pop('popup_menu', None)
                context_menu = button.pop('context_menu', None)

                convert_entrypoints(button)

                # Create the button!
                try:
                    button_definition['name'] = button_name = cmds.shelfButton(
                        **button)
                except TypeError:
                    print button
                    raise

                # Save the button for later.
                for uuid in uuids:
                    if uuid:
                        _uuid_to_buttons.setdefault(
                            uuid, []).append(button_definition)

                # Add a doubleclick action if requested.
                if doubleclick:

                    convert_entrypoints(doubleclick)

                    # Only pass through the two keywords that are allowed.
                    doubleclick = dict((k, v)
                                       for k, v in doubleclick.iteritems()
                                       if k in ('command', 'sourceType'))

                    # Adapt to a doubleclick.
                    doubleclick['doubleClickCommand'] = doubleclick.pop(
                        'command')

                    cmds.shelfButton(button_name, edit=True, **doubleclick)

                # Add a popup menu if requested.
                if popup_menu:
                    setup_menu(shelf_button=button_name,
                               button=1,
                               **popup_menu)
                if context_menu:
                    setup_menu(shelf_button=button_name,
                               button=3,
                               **context_menu)

    # Clean up persistant shelf options; Maya (and plugins) will freak out at us if we don't.
    for i, name in enumerate(
            cmds.shelfTabLayout(layout, q=True, childArray=True)):
        if name in new_shelves:
            cmds.optionVar(stringValue=(("shelfName%d" % (i + 1)), name))
            cmds.optionVar(stringValue=(("shelfFile%d" % (i + 1)), ''))
            cmds.optionVar(intValue=(("shelfLoad%d" % (i + 1)),
                                     1))  # Signal that it is loaded.
            continue
        opts = existing_options.get(name)
        if opts:
            cmds.optionVar(stringValue=(("shelfName%d" % (i + 1)),
                                        opts['Name']))
            cmds.optionVar(stringValue=(("shelfFile%d" % (i + 1)),
                                        opts['File']))
            cmds.optionVar(intValue=(("shelfLoad%d" % (i + 1)), opts['Load']))
            continue
        cmds.warning('New shelf "%s" appeared.' % name)

    cmds.optionVar(intValue=('numShelves', i + 1))

    # Finally, we need to save them all to the users' home. If we don't, and
    # another plugin (e.g. RenderMan) saves its own shelf, then on reload that
    # will be the only shelf which exists.
    cmds.saveAllShelves(layout)
Ejemplo n.º 7
0
def load(shelf_path=None):
    
    # Default to the Maya shelf path.
    if shelf_path is None:
        shelf_path = os.environ.get('MAYA_SHELF_PATH')
        shelf_path = shelf_path.split(':') if shelf_path else []
    
    # Single strings should be a list.
    if isinstance(shelf_path, basestring):
        shelf_path = [shelf_path]
    
    # Clear out the button memory.
    _uuid_to_buttons.clear()
    
    # Lookup the tab shelf that we will attach to.
    layout = mel.eval('$tmp=$gShelfTopLevel')
    
    # Store shelf options for restoring later.
    existing_options = {}
    for i, name in enumerate(cmds.shelfTabLayout(layout, q=True, childArray=True)):
        if name in existing_options:
            cmds.warning('Multiple shelves with name "%s"? This may cause problems.' % name)
        existing_options[name] = opts = {}
        for key in 'Name', 'File', 'Load':
            opts[key] = cmds.optionVar(q="shelf%s%d" % (key, i + 1))

    new_shelves = set()
    
    for shelf_dir in shelf_path:
        try:
            file_names = sorted(os.listdir(shelf_dir))
        except IOError:
            continue
        for file_name in file_names:
            if file_name.startswith('.') or file_name.startswith('_') or not file_name.endswith('.yml'):
                continue
            
            shelf_name = file_name[:-4]
            new_shelves.add(shelf_name)
            print '# %s: %s' % (__name__, shelf_name)
        
            # Delete buttons on existing shelves, and create shelves that don't
            # already exist.
            if cmds.shelfLayout(shelf_name, q=True, exists=True):
                # Returns None if not loaded yet, so be careful.
                for existing_button in cmds.shelfLayout(shelf_name, q=True, childArray=True) or []:
                    cmds.deleteUI(existing_button)
                cmds.setParent(layout + '|' + shelf_name)
            else:
                cmds.setParent(layout)
                cmds.shelfLayout(shelf_name)
        
            for b_i, button in enumerate(_iter_buttons(os.path.join(shelf_dir, file_name))):
            
                button_definition = copy.deepcopy(button)
            
                # Defaults and basic setup.
                button.setdefault('width', 34)
                button.setdefault('height', 34)
            
                # Extract keys to remember buttons.
                uuids = [button.get('entrypoint'), button.pop('uuid', None)]
                
                # Extract other commands.
                doubleclick = button.pop('doubleclick', None)
                popup_menu = button.pop('popup_menu', None)
                context_menu = button.pop('context_menu', None)
                
                convert_entrypoints(button)
            
                # Create the button!
                try:
                    button_definition['name'] = button_name = cmds.shelfButton(**button)
                except TypeError:
                    print button
                    raise
            
                # Save the button for later.
                for uuid in uuids:
                    if uuid:
                        _uuid_to_buttons.setdefault(uuid, []).append(button_definition)
                
                # Add a doubleclick action if requested.
                if doubleclick:
                    
                    convert_entrypoints(doubleclick)
                    
                    # Only pass through the two keywords that are allowed.
                    doubleclick = dict((k, v) for k, v in doubleclick.iteritems() if k in ('command', 'sourceType'))
                    
                    # Adapt to a doubleclick.
                    doubleclick['doubleClickCommand'] = doubleclick.pop('command')
                    
                    cmds.shelfButton(button_name, edit=True, **doubleclick)
                
                # Add a popup menu if requested.
                if popup_menu:
                    setup_menu(shelf_button=button_name, button=1, **popup_menu)
                if context_menu:
                    setup_menu(shelf_button=button_name, button=3, **context_menu)
    
    # Clean up persistant shelf options; Maya (and plugins) will freak out at us if we don't.
    for i, name in enumerate(cmds.shelfTabLayout(layout, q=True, childArray=True)):
        if name in new_shelves:
            cmds.optionVar(stringValue=(("shelfName%d" % (i + 1)), name))
            cmds.optionVar(stringValue=(("shelfFile%d" % (i + 1)), ''))
            cmds.optionVar(intValue=(("shelfLoad%d" % (i + 1)), 1)) # Signal that it is loaded.
            continue
        opts = existing_options.get(name)
        if opts:
            cmds.optionVar(stringValue=(("shelfName%d" % (i + 1)), opts['Name']))
            cmds.optionVar(stringValue=(("shelfFile%d" % (i + 1)), opts['File']))
            cmds.optionVar(intValue=(("shelfLoad%d" % (i + 1)), opts['Load']))
            continue
        cmds.warning('New shelf "%s" appeared.' % name)

    cmds.optionVar(intValue=('numShelves', i + 1))

    # Finally, we need to save them all to the users' home. If we don't, and
    # another plugin (e.g. RenderMan) saves its own shelf, then on reload that
    # will be the only shelf which exists.
    cmds.saveAllShelves(layout)
Ejemplo n.º 8
0
def load(shelf_dirs=None, image_dirs=None):

    # Default to $MAYA_SHELF_PATH.
    if shelf_dirs is None:
        shelf_dirs = os.environ.get('MAYA_SHELF_PATH')
        shelf_dirs = shelf_dirs.split(':') if shelf_dirs else []

    # Single strings should be a list.
    if isinstance(shelf_dirs, basestring):
        shelf_dirs = [shelf_dirs]

    # Clear out the button memory.
    _uuid_to_buttons.clear()

    # Lookup the tab shelf that we will attach to.
    layout = get_top_shelf_layout()

    # Store shelf options for restoring later.
    existing_options = {}
    for i, name in enumerate(
            cmds.shelfTabLayout(layout, q=True, childArray=True)):
        if name in existing_options:
            cmds.warning(
                'Multiple shelves with name "%s"? This may cause problems.' %
                name)
        existing_options[name] = opts = {}
        for key in 'Name', 'File', 'Load':
            opts[key] = cmds.optionVar(q="shelf%s%d" % (key, i + 1))

    new_shelves = set()
    image_dirs = image_dirs or ()

    # Collect all shelves, and sort them by basename so no shelf directory
    # gets priority.
    shelf_paths = []
    for shelf_dir in shelf_dirs:
        try:
            file_names = os.listdir(shelf_dir)
        except IOError:
            continue
        for file_name in file_names:
            if file_name.startswith('.') or file_name.startswith(
                    '_') or not file_name.endswith('.yml'):
                continue
            shelf_paths.append(os.path.join(shelf_dir, file_name))
    shelf_paths.sort(key=os.path.basename)

    for shelf_path in shelf_paths:

        shelf_dir, file_name = os.path.split(shelf_path)
        shelf_name, ext = os.path.splitext(file_name)

        if shelf_name in new_shelves:
            continue

        new_shelves.add(shelf_name)
        print '# %s: %s' % (__name__, shelf_name)

        _load_shelf(shelf_path, shelf_dirs, image_dirs)

    # Clean up persistant shelf options; Maya (and plugins) will freak out at us if we don't.
    for i, name in enumerate(
            cmds.shelfTabLayout(layout, q=True, childArray=True)):
        if name in new_shelves:
            cmds.optionVar(stringValue=(("shelfName%d" % (i + 1)), name))
            cmds.optionVar(stringValue=(("shelfFile%d" % (i + 1)), ''))
            cmds.optionVar(intValue=(("shelfLoad%d" % (i + 1)),
                                     1))  # Signal that it is loaded.
            continue
        opts = existing_options.get(name)
        if opts:
            cmds.optionVar(stringValue=(("shelfName%d" % (i + 1)),
                                        opts['Name']))
            cmds.optionVar(stringValue=(("shelfFile%d" % (i + 1)),
                                        opts['File']))
            cmds.optionVar(intValue=(("shelfLoad%d" % (i + 1)), opts['Load']))
            continue
        cmds.warning('New shelf "%s" appeared.' % name)

    cmds.optionVar(intValue=('numShelves', i + 1))

    # Finally, we need to save them all to the users' home. If we don't, and
    # another plugin (e.g. RenderMan) saves its own shelf, then on reload that
    # will be the only shelf which exists.
    cmds.saveAllShelves(layout)