import maya.cmds as cmds
def krax_NS_GetNodes(sortToType=True):
    nds = cmds.ls(long=True, selection=False)
    ln = len(nds)
    nl_c = []
    for i in range(ln):
        if sortToType:
            nl_c.append(cmds.nodeType(nds[i]) + "\0" + nds[i])
        else:
            nl_c.append( nds[i] + "\0" + cmds.nodeType(nds[i]))
    nl_c.sort()
    wnd = cmds.window(title="All Maya Nodes",s=True, h=600)
    cmds.scrollLayout(horizontalScrollBarThickness=10)
    cmds.rowColumnLayout(numberOfColumns=1)
    if sortToType:
        cmds.button("Refresh", command='cmds.deleteUI("'+ wnd +'"), krax_NS_GetNodes(True)')
        cmds.button("Switch to alphabetical mode", command='cmds.deleteUI("'+ wnd +'"), krax_NS_GetNodes(False)')
    else:
        cmds.button("Refresh", command='cmds.deleteUI("'+ wnd +'"), krax_NS_GetNodes(False)')
        cmds.button("Switch to grouped mode", command='cmds.deleteUI("'+ wnd +'"), krax_NS_GetNodes(True)')
        cmds.separator(h=20, style="none")
    lastCLS=""
    for i in range(ln):
        n = (nl_c[i].split("\0"))
        if lastCLS != n[0]:
            lastCLS = n[0]
            if sortToType:
                cmds.separator(h=20, style="none")
                cmds.text(label=lastCLS, font="boldLabelFont")
                cmds.separator(h=5, style="none")
        if not sortToType:
            cmds.separator(h=10, style="none")
            cmds.button(label=n[0]+" ["+n[1]+"]", command='cmds.select("' + n[0] + '")')
        else:
            cmds.button(label=n[1], command='cmds.select("' + n[1] + '")')
           
    cmds.showWindow(wnd)
    return nl_c
    
krax_NS_GetNodes(True)
