Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- """ Version: 0.1 Alpha , July 2016:
- Maya Script Loader , Kevin Flynn, [email protected]
- Features:
- - Simple Install + Setup
- - Mac / PC in-dependant.
- - Flexible, 1)Button text, 2)Icon, or 3)dock-able , 4)mini mode.
- - Will display the icon for a script if its named the same.
- - Alternate r-click command if a script doesnt work.
- """
- ##################################################################################################
- # To run me, edit the below path to the location of this script, then copy and paste the below 2 lines
- # into a Maya python command window.
- """
- filepath = "C:\Users\kflynn\Documents\maya\scripts\MayaPythonTools\ScriptLoaderSystem" ## << change this path.
- paths = sys.path ; sys.path.append(filepath) ; exec 'import ' + 'ScriptLoaderSystem' in globals(); exec( 'reload( ' + 'ScriptLoaderSystem' + ' )' ) in globals();
- """
- ##################################################################################################
- #
- #
- ##################################################################################################
- ## proc imports here: ##
- import maya.cmds as cmds
- import maya.mel as mel
- import os
- import posixpath
- import shutil
- import sys
- ## proc imports here: ##
- ##################################################################################################
- _scriptLoader_window_Icons = [None , None] ## ui elements: iconmode icon and dockmode icon.
- ## Global Values here: ##
- _ignoredFiles = ['init' , 'hidden' , 'ignore' , 'hide' , '.git' , '.pyc' ] ## Keep lower case:
- _iconTypes = ['.bmp' , '.icon' , '.png' , '.jpg' , '.tiff' , '.tga' ] ## Keep lower case:
- ## Global Values here: ##
- Scrpt_Ldr_Win_W_H = [190 , 180] # Window UI Settings
- ## Global Values here: ##
- def variables( varType ):
- scriptPrefsPathFolder = cmds.internalVar(uad=True) ## will always be this location, dynamic for each machine but should never change internal to Maya
- scriptPrefsPath = cmds.internalVar(uad=True) + 'ScriptLoader.path' ## will always be this location, dynamic for each machine but should never change internal to Maya
- toolID = __name__ # if loaded from a script, will be that name else "__main__"
- userID = os.environ['USER'] # returns username, works mac 2013+ and PC 2015+
- # fileID = __file__ # file location including name if loaded via import* doesnt play nicely if script wasnt from file
- docID = __doc__ # returns any documentation or docs on objects.. doc strings are """ text lines text """
- if toolID in globals(): ## is imported or copied into script window?
- ## also check out sys.modules??
- importID = True
- else:
- importID = False
- platformID = sys.platform ## on mac or pc? (win32 = pc , posix maybe for mac?)
- returnData = eval(varType)
- return returnData
- def cmdMessage( _textToSay ): # message printer for Maya warning tab. #
- if _textToSay:
- sys.stdout.write('# ' + ' - ' + _textToSay + ' - ' + ' #\n')
- class ScriptClass_FileScript:
- """ Class object for a Maya script to be loaded in. """
- def __init__(self,ScriptName,ScriptPath,ScriptType,ScriptCategory,ScriptIcon,ScriptCommandString):
- self.Name = ScriptName
- self.Path = ScriptPath
- self.Type = ScriptType
- self.Category = ScriptCategory
- self.Icon = ScriptIcon
- self.Command = [ScriptCommandString[0] , ScriptCommandString[1]]
- class ScriptClass_ScriptLoaderGlobalSettings:
- """ Class object detailing the info needed by scriptloader and current states """
- def __init__(self):
- ## everything below to be saved to prefs file
- self._ScriptsPath = None
- self._UI_Position = [10,10] ## Last known actual window position (edited at docking/undocking)
- self._UI_WidthHeight = Scrpt_Ldr_Win_W_H ## users prefs [190 - 180] by default
- self._IsIconMode = 'False' ## is in Icon state?
- self._UI_MelColour = [.56 , .33 , .33] ## base color for all scripts
- self._UI_PyColour = [.33 , .56 , .33] ## base color for all scripts
- ## everything below wont be saved to file
- self.window_UI_Name = None
- self.window_UI_PathBtn = None
- self.window_UI_PaneAttach = None ## the Ui element the Scrollattach is a child of.
- self.window_UI_ScrollAttach = None ## direct name for attaching?
- self.window_UI_DockedMode = False ## true or false on current state, either False or DockLocation
- self.window_UI_DockUI = None ## Docked UI element the script is a child of.
- self.window_UI_CategoryOpen = []
- self.window_UI_ScrollBarLocation = [0,0]
- self.AllScriptClasses = []
- self.AllScriptCategorySize = []
- def WriteToPrefsFile():
- ScriptLoaderPrefs_Text = ["SCRIPTSPATH=" , "UI_POSITION=" , "UI_WIDTHHEIGHT=" , "IS_ICONMODE=" , "MEL_COLOUR=" , "PY_COLOUR=" ]
- f = open( variables("scriptPrefsPath") , 'w')
- if( ScriptLoader_GlobalSettings.window_UI_Name is not None):
- if( ScriptLoader_GlobalSettings.window_UI_DockedMode is False):
- ScriptLoader_GlobalSettings._UI_Position = cmds.window( ScriptLoader_GlobalSettings.window_UI_Name , query = True , tlc = True )
- ScriptLoader_GlobalSettings._UI_WidthHeight = cmds.window( ScriptLoader_GlobalSettings.window_UI_Name , query = True , widthHeight = True )
- filetext = [
- (ScriptLoaderPrefs_Text[0] + str(ScriptLoader_GlobalSettings._ScriptsPath) +'\n'),
- (ScriptLoaderPrefs_Text[1] + str(ScriptLoader_GlobalSettings._UI_Position) +'\n'),
- (ScriptLoaderPrefs_Text[2] + str(ScriptLoader_GlobalSettings._UI_WidthHeight) +'\n'),
- (ScriptLoaderPrefs_Text[3] + str(ScriptLoader_GlobalSettings._IsIconMode) +'\n'),
- (ScriptLoaderPrefs_Text[4] + str(ScriptLoader_GlobalSettings._UI_MelColour) +'\n'),
- (ScriptLoaderPrefs_Text[5] + str(ScriptLoader_GlobalSettings._UI_PyColour) +'\n'),
- ]
- for x in filetext:
- f.write( str(x) )
- f.close()
- def LoadPrefsFile():
- def GetValidScriptPath():
- newPath = cmds.fileDialog2( dialogStyle = 1 , fm = 3 )
- if newPath is None:
- cmdMessage("User cancelled script path. \n User preference file will not be created.")
- else:
- return newPath[0]
- def GetLineValue(_line):
- tmp = _line.split('=')
- if("UI_" in _line): ## these are meant to be numerics, cleanup
- tmpCleanup = tmp[1].replace("[" , "")
- tmpCleanup = tmpCleanup.replace("]" , "")
- return map(int, tmpCleanup.split(',') )
- if("_COLOUR" in _line): ## these are meant to be numerics, cleanup
- tmpCleanup = tmp[1].replace("[" , "")
- tmpCleanup = tmpCleanup.replace("]" , "")
- return map(float, tmpCleanup.split(',') )
- else:
- return tmp[1]
- if os.access( variables("scriptPrefsPath") ,os.R_OK): ## If file exists, read in variables!
- f = open( variables("scriptPrefsPath") , 'r')
- lines = [x.strip() for x in f.readlines()]
- f.close()
- ScriptLoader_GlobalSettings._ScriptsPath = GetLineValue(lines[0])
- ScriptLoader_GlobalSettings._UI_Position = GetLineValue(lines[1])
- ScriptLoader_GlobalSettings._UI_WidthHeight = GetLineValue(lines[2])
- ScriptLoader_GlobalSettings._IsIconMode = GetLineValue(lines[3])
- ScriptLoader_GlobalSettings._UI_MelColour = GetLineValue(lines[4])
- ScriptLoader_GlobalSettings._UI_PyColour = GetLineValue(lines[5])
- else: ## file doesnt exist / create new default
- tmp = GetValidScriptPath() ## basic vanilla setup
- if (tmp is not None):
- ScriptLoader_GlobalSettings._ScriptsPath = tmp
- WriteToPrefsFile()
- def PopulateScriptClasses():
- _filesFound = [] ## all files
- _filesFoundClean = [] ## files found , duplicates removed
- _scriptsClasses = [] ## class holder
- def splitNice(_filelocation):
- tmp = _filelocation.split(".")
- tmp2 = tmp[0].split("/")
- return tmp2[-1].lower()
- def getIcon( _filelocation ):
- tmpLocation = _filelocation.split('/')
- _filename = tmpLocation[-1].split('.')
- del tmpLocation[-1]
- tmpLocation2 = '/'.join(tmpLocation)
- tmpFileInArea = getFiles(tmpLocation2)
- for tempFile in tmpFileInArea:
- for _type in _iconTypes:
- if( (_filename[0] + _type) in tempFile ):
- return tempFile
- ## grab all the script files found! ##
- def getFiles(_FileLocation):
- _tmp_filesFound = []
- for root, directories, filenames in os.walk(_FileLocation):
- for filename in filenames:
- nameCleaned = os.path.join(root,filename).replace("\\","/")
- _tmp_filesFound.append(nameCleaned)
- return _tmp_filesFound
- _filesFound = getFiles( ScriptLoader_GlobalSettings._ScriptsPath )
- ## clean up process on folders ##
- for fileclean in _filesFound:
- stringTest = False
- for ignoredType in _ignoredFiles:
- if ignoredType in fileclean.lower():
- stringTest = True
- break
- if stringTest is False:
- _filesFoundClean.append(fileclean)
- tempListCategory = []
- ## begin populating script classes! ##
- for x in _filesFoundClean:
- if (".mel" in x or ".py" in x):
- name = splitNice(x)
- location = x
- tmpType = x.split('.')
- scriptType = tmpType[1]
- tmpCategory = x.split('/')
- scriptCategory = tmpCategory[-2]
- tempListCategory.append( scriptCategory )
- scriptIcon = getIcon(x)
- scriptCommand = ScriptLoaderSystem_btn_command(location)
- tmpClass = ScriptClass_FileScript( name , location , scriptType , scriptCategory, scriptIcon, scriptCommand )
- _scriptsClasses.append(tmpClass)
- ## sort list by category: ##
- _scriptsClasses.sort(key=lambda x: x.Category, reverse=False)
- ScriptLoader_GlobalSettings.AllScriptClasses = _scriptsClasses
- ScriptLoader_GlobalSettings.AllScriptCategorySize = dict((i, tempListCategory.count(i)) for i in tempListCategory)
- def ScriptLoaderSystem_Refresh():
- WriteToPrefsFile()
- ScriptLoader_GlobalSettings.window_UI_ScrollBarLocation = cmds.scrollLayout( ScriptLoader_GlobalSettings.window_UI_ScrollAttach , query=True, scrollAreaValue=True)
- PopulateScriptClasses() ## find all scripts and setup the list of classes/container
- cmdMessage("Refreshing scripts loaded from disk: " + str(len(ScriptLoader_GlobalSettings.AllScriptClasses)) + " Scripts found." )
- ScriptLoaderSystem_UI_PopulateScripts() ## use created classes to create the buttons on window
- def ScriptLoaderSystem_UI_newFilePath(): #edits the path button
- if(ScriptLoader_GlobalSettings._ScriptsPath is not None):
- newPath = cmds.fileDialog2( dialogStyle = 1 , fm = 3 , dir = ScriptLoader_GlobalSettings._ScriptsPath)
- else:
- newPath = cmds.fileDialog2( dialogStyle = 1 , fm = 3 )
- if newPath is None:
- cmdMessage("User cancelled script path")
- else:
- ScriptLoader_GlobalSettings._ScriptsPath = newPath[0]
- cmds.button( ScriptLoader_GlobalSettings.window_UI_PathBtn , parent = 'master_Scrpt_Ldr_Win_ColsHeader_Left' , edit = True , label = ScriptLoader_GlobalSettings._ScriptsPath[0:15] , width = ( 190 / 2 ) , ann = ScriptLoader_GlobalSettings._ScriptsPath )
- print ( 'User chosen Path: \n' + ScriptLoader_GlobalSettings._ScriptsPath + '\n' )
- ScriptLoaderSystem_Refresh()
- def ScriptLoaderSystem_btn_command( script_path ): # given a location will feed back the command string to use to initialise.
- testNetwork = script_path.startswith('\\')
- paths = sys.path
- Additional = ''
- if testNetwork is True:
- Additional = ( '//' ) # adding network prefix..
- tmp = script_path.split( '\\' )
- tmp2 = posixpath.join( *tmp ) # using the Unix style pathing that's what Maya uses, even on windows..
- Command_String = []
- if '.mel' in script_path:
- Command_String.append ( 'mel.eval(\'source \"' + Additional + tmp2 + '\" ;\')' )
- Command_String.append ( 'mel.eval(\'source \"' + Additional + tmp2 + '\" ;\')' )
- else:
- tmp3 = tmp2.split( '.')
- tmp4 = os.path.split(tmp3[0])
- sys.path.append( os.path.dirname( tmp3[0] ) )
- Command_String.append ( "exec ('import ' + '$module$') in globals() ;exec( 'reload( ' + '$module$' + ' )' ) in globals()".replace( "$module$" , tmp4[1] ) )
- Command_String.append ( 'execfile( (\'' + Additional + tmp2 + '\'))' ) ## old way of forcing a script load..
- return Command_String
- def ScriptLoaderSystem_UI_PopulateScripts(): ## deletes the Ui shelf and re-populates note: this doesnt refresh the scripts class or relook at the files on disk.
- tmp_WindowWidth = 190
- if(ScriptLoader_GlobalSettings.window_UI_Name is not None):
- if cmds.window(ScriptLoader_GlobalSettings.window_UI_Name, exists = True ):
- tmp_WindowWidth = cmds.window( ScriptLoader_GlobalSettings.window_UI_Name , w = True , query = True ) # grab current width of control to judge character limit.
- tmp_Category = ''
- tmp_Name = ''
- tmp_Count = 0
- def DeleteOldUi():
- cmds.deleteUI( ScriptLoader_GlobalSettings.window_UI_ScrollAttach )
- ScriptLoader_GlobalSettings.window_UI_ScrollAttach = cmds.scrollLayout( parent = ScriptLoader_GlobalSettings.window_UI_PaneAttach , cr = True , vst = 10 ) #all script catogories nested to this
- if ScriptLoader_GlobalSettings._IsIconMode == 'True': # Make Icon Only :
- cmds.button( _scriptLoader_window_Icons[0] , edit = True , label = '#' )
- else: # Make Text Only :
- cmds.button( _scriptLoader_window_Icons[0] , edit = True , label = '=' )
- if ScriptLoader_GlobalSettings.window_UI_DockedMode is True: # Make Icon Only :
- cmds.button( _scriptLoader_window_Icons[1] , edit = True , label = '||' )
- else:
- cmds.button( _scriptLoader_window_Icons[1] , edit = True , label = '[]' )
- def NiceName( nameString , columns ): # given a string, will return a version that should just fit the current window layout
- character_WindowLength = 4 # amount of pixels a character takes avg.
- frameLayoutIcon = 15 ; scrollBarLayoutIcon = 6 # size in characters, avg.
- charMaxLength = ( ( ( tmp_WindowWidth ) / character_WindowLength) - ( frameLayoutIcon + scrollBarLayoutIcon ) ) # area to play with after removing scrollbars width, icons from windows total width.
- if charMaxLength < len( nameString ):
- newCleanName = ( nameString[0: ( charMaxLength -3 )] + '..' )
- else:
- newCleanName = nameString[0:int(charMaxLength)]
- if columns > 1:
- newCleanName = newCleanName[0:( int( charMaxLength * .9) / columns )]
- return newCleanName
- def NiceColor( scriptType , scriptNumber): # given a list of files/scripts, and a number feeds back a colour array.. colour[x ,x ,x]
- tmpBtn_Color = None ; tmpBtn_Color = [0,0,0]
- if 'mel' in scriptType:
- btn_scriptType = ScriptLoader_GlobalSettings._UI_MelColour
- else:
- btn_scriptType = ScriptLoader_GlobalSettings._UI_PyColour
- divisable = .9
- if scriptNumber%2==0:
- divisable = .966
- scriptNumber = scriptNumber/10.0 ## staggering color gradient here..
- if(scriptNumber > 0.1):
- scriptNumber = scriptNumber/10.0
- if(scriptNumber > 0.1):
- scriptNumber = scriptNumber/10.0
- tmpBtn_Color[0] = btn_scriptType[0] * divisable - scriptNumber
- tmpBtn_Color[1] = btn_scriptType[1] * divisable - scriptNumber
- tmpBtn_Color[2] = btn_scriptType[2] * divisable - scriptNumber
- return tmpBtn_Color
- def AddPopUpMenu_GoToFolder(_button , _path):
- tmp_Path = _path.split('/')
- tmp_Path.remove(tmp_Path[-1])
- _R_ClickOpts = cmds.popupMenu( parent = _button , button = 3 )
- cmds.menuItem( label = 'Goto Folder' , parent = _R_ClickOpts , command = ( variables('toolID') + '.gotoFolder("' + str('/'.join(tmp_Path)) + '")' ) )
- def AddPopUpMenu_TryOldCommand(_button , _command):
- _R_ClickOpts = cmds.popupMenu( parent = _button , button = 3 )
- cmds.menuItem( label = "Doesn't work? \nTry alternate command?" , parent = _R_ClickOpts , command = _command[1] )
- DeleteOldUi()
- if(ScriptLoader_GlobalSettings._IsIconMode == 'True'): ## icon mode..
- for x in ScriptLoader_GlobalSettings.AllScriptClasses:
- if(tmp_Category != x.Category):
- tmp_Count = 0
- tmp_Category = x.Category
- tmpLayout = cmds.frameLayout( label = str(tmp_Category) , cll = True , cl = True , parent = ScriptLoader_GlobalSettings.window_UI_ScrollAttach ,
- ec = ( variables('toolID') + '.ScriptLoaderSystem_UI_expandedFrame("' + str(x.Category) + '")') ,
- cc = ( variables('toolID') + '.ScriptLoaderSystem_UI_closedFrame("' + str(x.Category) + '")') )
- cmds.columnLayout( tmpLayout , adj=True)
- AddPopUpMenu_GoToFolder(tmpLayout , x.Path) ## adding goto folder option
- tmpColumns = 1
- if( ScriptLoader_GlobalSettings.AllScriptCategorySize[ x.Category ] > 1):
- tmpColumns = 2
- if( ScriptLoader_GlobalSettings.AllScriptCategorySize[ x.Category ] > 2):
- tmpColumns = 3
- if( ScriptLoader_GlobalSettings.AllScriptCategorySize[ x.Category ] > 3 and tmp_WindowWidth > (Scrpt_Ldr_Win_W_H[0]+30) ):
- tmpColumns = 4
- if( ScriptLoader_GlobalSettings.AllScriptCategorySize[ x.Category ] > 4 and tmp_WindowWidth > (Scrpt_Ldr_Win_W_H[0]+60) ):
- tmpColumns = 5
- if( ScriptLoader_GlobalSettings.AllScriptCategorySize[ x.Category ] > 5 and tmp_WindowWidth > (Scrpt_Ldr_Win_W_H[0]+90) ):
- tmpColumns = 6
- ## should involve script width here?! for if greater than?
- tmpRow = cmds.rowColumnLayout( numberOfColumns = tmpColumns )
- if(tmp_Category in ScriptLoader_GlobalSettings.window_UI_CategoryOpen ): ## opening frames from last save..
- cmds.frameLayout( tmpLayout , edit = True , cl = False )
- else:
- tmp_Count = tmp_Count + 1
- if(x.Icon == None):
- tmpBtn = cmds.iconTextButton( style = 'textOnly' , bgc = NiceColor(x.Type , tmp_Count) , label = NiceName(x.Name,tmpColumns) , align = 'left' , width = ( (tmp_WindowWidth - 20) / tmpColumns ) , parent = tmpRow , command = x.Command[0] , ann = (x.Name + '.' + x.Type) )
- else:
- tmpBtn = cmds.iconTextButton( style = 'iconOnly' , image1 = x.Icon ,label = x.Name , align = 'left' , parent = tmpRow , command = x.Command[0] , ann = (x.Name + '.' + x.Type) )
- AddPopUpMenu_TryOldCommand(tmpBtn, x.Command ) ## adds the older command to try directly execute a command!
- if(ScriptLoader_GlobalSettings._IsIconMode == 'False'): ## text only mode..
- for x in ScriptLoader_GlobalSettings.AllScriptClasses:
- if(tmp_Category != x.Category):
- tmp_Count = 0
- tmp_Category = x.Category
- tmpLayout = cmds.frameLayout( label = str(tmp_Category) , cll = True , cl = True , parent = ScriptLoader_GlobalSettings.window_UI_ScrollAttach ,
- ec = ( variables('toolID') + '.ScriptLoaderSystem_UI_expandedFrame("' + str(x.Category) + '")') ,
- cc = ( variables('toolID') + '.ScriptLoaderSystem_UI_closedFrame("' + str(x.Category) + '")') )
- AddPopUpMenu_GoToFolder(tmpLayout , x.Path) ## adding goto folder option
- if(x.Category in ScriptLoader_GlobalSettings.window_UI_CategoryOpen ): ## opening frames from last save..
- cmds.frameLayout( tmpLayout , edit = True , cl = False )
- tmpColumn = cmds.columnLayout( tmpLayout , adj=True)
- else:
- tmp_Count = tmp_Count + 1
- tmpBtn = cmds.iconTextButton( style = 'textOnly' , bgc = NiceColor(x.Type , tmp_Count) , label = x.Name , align = 'left' , parent = tmpColumn , command = x.Command[0] , ann = (x.Name + '.' + x.Type) )
- AddPopUpMenu_TryOldCommand(tmpBtn, x.Command ) ## adds the older command to try directly execute a command!
- def ScriptLoaderSystem_UI_expandedFrame(_frameName): ## command triggered by opening of frame, will remember this so its open upon refrshing
- if(_frameName in ScriptLoader_GlobalSettings.window_UI_CategoryOpen):
- pass
- else:
- ScriptLoader_GlobalSettings.window_UI_CategoryOpen.append(_frameName)
- def ScriptLoaderSystem_UI_closedFrame(_frameName): ## command triggered by closing of frame, will remember this so its closed upon refrshing
- if(_frameName in ScriptLoader_GlobalSettings.window_UI_CategoryOpen):
- ScriptLoader_GlobalSettings.window_UI_CategoryOpen.remove(_frameName)
- def ScriptLoaderSystem_UI_scrollToPreviousPosition():
- cmds.scrollLayout( ScriptLoader_GlobalSettings.window_UI_ScrollAttach , edit=True, sbp= ["down" , int(ScriptLoader_GlobalSettings.window_UI_ScrollBarLocation[0]) ])
- def ScriptLoaderSystem_UI_IconTextMode(): ## changes mode of script from icon to text or vice versa.
- if ScriptLoader_GlobalSettings._IsIconMode == 'True': # Make Icon Only :
- ScriptLoader_GlobalSettings._IsIconMode = 'False'
- cmdMessage("ScriptLoader: TextMode" )
- else:
- ScriptLoader_GlobalSettings._IsIconMode = 'True'
- cmdMessage("ScriptLoader: IconMode" )
- ScriptLoaderSystem_UI_PopulateScripts()
- WriteToPrefsFile()
- def ScriptLoaderSystem_UI_DockMode(): ## changes mode of script from Docked to Un-Docked or vice versa.
- WriteToPrefsFile()
- if ScriptLoader_GlobalSettings.window_UI_DockedMode is True:
- ScriptLoader_GlobalSettings.window_UI_DockedMode = False
- cmdMessage("ScriptLoader: Un-Docking " )
- else:
- ScriptLoader_GlobalSettings.window_UI_DockedMode = True
- cmdMessage("ScriptLoader: Docking " )
- ScriptLoaderSystem_UI_DockModeUpdate()
- ScriptLoaderSystem_UI_PopulateScripts()
- def deleteOldDockUiByName():
- Scrpt_Ldr_DockUI_test = cmds.dockControl( 'ScriptLoader_Dock' , query = True , exists = True )
- if Scrpt_Ldr_DockUI_test is True:
- cmds.deleteUI( 'ScriptLoader_Dock' )
- deleteOldDockUiByVar()
- def deleteOldDockUiByVar():
- if(ScriptLoader_GlobalSettings.window_UI_DockUI is not None):
- Scrpt_Ldr_DockUI_test = cmds.dockControl( ScriptLoader_GlobalSettings.window_UI_DockUI , query = True , exists = True )
- if Scrpt_Ldr_DockUI_test is True:
- cmds.deleteUI( ScriptLoader_GlobalSettings.window_UI_DockUI )
- def ScriptLoaderSystem_UI_DockModeUpdate(): ## changes mode of script from Docked to Un-Docked or vice versa.
- if ScriptLoader_GlobalSettings.window_UI_DockedMode is True:
- cmds.button( _scriptLoader_window_Icons[1] , edit = True , label = '||' )
- deleteOldDockUiByName()
- ScriptLoader_GlobalSettings.window_UI_DockUI = cmds.dockControl( 'ScriptLoader_Dock' , fl = False , epo = False , r = False , area = 'left', aa = 'all' , content = ScriptLoader_GlobalSettings.window_UI_Name )
- else:
- cmds.button( _scriptLoader_window_Icons[1] , edit = True , label = '[]' )
- deleteOldDockUiByName()
- ScriptLoaderSystem_UI() ## main window, only open this one time a session ..
- ScriptLoaderSystem_UI_PopulateScripts() ## use created classes to create the buttons in the window
- def gotoFolder(_filePath):
- try:
- os.startfile( _filePath )
- except AttributeError:
- subprocess.call(['open', _filePath ])
- def gotoPrefsFile(): ## opens the prefs file folder..
- try:
- os.startfile( variables("scriptPrefsPathFolder") )
- except AttributeError:
- subprocess.call(['open', variables("scriptPrefsPathFolder") ])
- def resetPrefsFile(): ## deletes old prefs file..
- # try:
- # os.remove( variables("scriptPrefsPath"))
- # except AttributeError:
- # pass
- cmdMessage("Resetting ScriptLoader settings: " )
- ScriptLoader_GlobalSettings._UI_Position = [10,10] ## Last known actual window position (edited at docking/undocking)
- ScriptLoader_GlobalSettings._UI_WidthHeight = Scrpt_Ldr_Win_W_H ## users prefs [190 - 180] by default
- ScriptLoader_GlobalSettings._IsIconMode = 'False' ## is in Icon state?
- ScriptLoader_GlobalSettings._UI_MelColour = [.56 , .33 , .33] ## base color for all scripts
- ScriptLoader_GlobalSettings._UI_PyColour = [.33 , .56 , .33] ## base color for all scripts
- WriteToPrefsFile()
- # print "cmds.deleteUI('Scrpt_Ldr_Win')"
- # cmds.evalDeferred( ( "cmds.deleteUI('Scrpt_Ldr_Win')" ) ) # defer the delete so it doesnt crash Maya!
- # # cmds.deleteUI('Scrpt_Ldr_Win', window = True )
- # ScriptLoaderSystem_UI() ## main window, only open this one time a session ..
- ScriptLoaderSystem_UI_PopulateScripts() ## use created classes to create the buttons in the window
- def ChangeColourBtn( _type):
- if( _type == 'mel'):
- cmds.colorEditor( rgb = ScriptLoader_GlobalSettings._UI_MelColour)
- if( _type == 'py'):
- cmds.colorEditor( rgb = ScriptLoader_GlobalSettings._UI_PyColour)
- if cmds.colorEditor(query=True, result=True):
- _result = cmds.colorEditor(query=True, rgb=True)
- if( _type == 'mel'):
- cmds.button('melBtn_Colour' , edit = True , bgc = _result )
- if( _type == 'py'):
- cmds.button('pyBtn_Colour' , edit = True , bgc = _result )
- else:
- print 'Editor was dismissed'
- def ResetColourBtn():
- cmds.button('melBtn_Colour' , edit = True , bgc = ScriptLoader_GlobalSettings._UI_MelColour )
- cmds.button('pyBtn_Colour' , edit = True , bgc = ScriptLoader_GlobalSettings._UI_PyColour )
- def DefaultColourBtn():
- cmds.button('melBtn_Colour' , edit = True , bgc = [.56 , .33 , .33] )
- cmds.button('pyBtn_Colour' , edit = True , bgc = [.33 , .56 , .33] )
- def ApplyColourBtn():
- ScriptLoader_GlobalSettings._UI_MelColour = cmds.button('melBtn_Colour' , query = True , bgc = True )
- ScriptLoader_GlobalSettings._UI_PyColour = cmds.button('pyBtn_Colour' , query = True , bgc = True )
- WriteToPrefsFile()
- if cmds.window('ColourWin', exists = True ):
- cmds.deleteUI('ColourWin', window = True )
- ScriptLoaderSystem_UI_PopulateScripts()
- def ScriptLoaderSystem_UI_ColourSettings():
- ## add option here for prefs instead of on main..
- ## need to display both the current version, and the new colours side by side also the actual float numbers!?
- Scrpt_ColourWin = "ColourWin"
- if cmds.window('ColourWin', exists = True ):
- cmds.deleteUI('ColourWin', window = True )
- if cmds.windowPref('ColourWin', exists = True ):
- cmds.windowPref( 'ColourWin', remove = True )
- Scrpt_Ldr_ColourWin = cmds.window( Scrpt_ColourWin , title=".: Script Loader Colour Settings :.", widthHeight=(351, 61) , toolbox = True )
- cmds.rowColumnLayout( numberOfColumns=4 )
- cmds.button(label = "Mel" , width = 100 , bgc = ScriptLoader_GlobalSettings._UI_MelColour )
- cmds.button(label = "Python" , width = 100 , bgc = ScriptLoader_GlobalSettings._UI_PyColour )
- cmds.button(label = "Reset" , width = 75 , command = ( variables('toolID') + '.ResetColourBtn()'))
- cmds.button(label = "Default" , width = 75 , command = ( variables('toolID') + '.DefaultColourBtn()'))
- cmds.button('melBtn_Colour' , label = "Change?" , bgc = ScriptLoader_GlobalSettings._UI_MelColour , command = ( variables('toolID') + '.ChangeColourBtn("mel")'))
- cmds.button('pyBtn_Colour' , label = "Change?" , bgc = ScriptLoader_GlobalSettings._UI_PyColour , command = ( variables('toolID') + '.ChangeColourBtn("py")'))
- cmds.button(label = "Apply \nNew" , command = ( variables('toolID') + '.ApplyColourBtn()'))
- cmds.showWindow( Scrpt_Ldr_ColourWin)
- def ScriptLoaderSystem_UI():
- deleteOldDockUiByName()
- Scrpt_Ldr_Win = "Scrpt_Ldr_Win"
- if cmds.window('Scrpt_Ldr_Win', exists = True ):
- cmds.deleteUI('Scrpt_Ldr_Win', window = True )
- if cmds.windowPref('Scrpt_Ldr_Win', exists = True ):
- cmds.windowPref( 'Scrpt_Ldr_Win', remove = True )
- ScriptLoader_GlobalSettings.window_UI_Name = cmds.window( Scrpt_Ldr_Win , widthHeight = ScriptLoader_GlobalSettings._UI_WidthHeight ,
- tlc = ScriptLoader_GlobalSettings._UI_Position ,
- rtf = True , toolbox = True )
- ScriptLoader_GlobalSettings.window_UI_PaneAttach = cmds.paneLayout( 'master_Scrpt_Ldr_Win' , parent = 'Scrpt_Ldr_Win' , shp = True , configuration='horizontal2' )
- cmds.paneLayout( ScriptLoader_GlobalSettings.window_UI_PaneAttach , edit = True , ps = [ 1 , 0 , 1 ] )
- cmds.rowColumnLayout( 'master_Scrpt_Ldr_Win_ColsHeader' , numberOfColumns = 2 , parent = ScriptLoader_GlobalSettings.window_UI_PaneAttach )
- cmds.rowColumnLayout( 'master_Scrpt_Ldr_Win_ColsHeader_Left' , numberOfColumns = 1 , parent = 'master_Scrpt_Ldr_Win_ColsHeader' )
- cmds.button( 'Script_Loader_WinUI_Btn_Rfrsh' , label = ( 'Script Loader' ) , align = 'left' , ann = ( 'Click to refresh scripts shown.' ) , width = ( ( 190 / 10 ) * 8 ) , parent = 'master_Scrpt_Ldr_Win_ColsHeader_Left' , command = ( variables('toolID') + '.ScriptLoaderSystem_Refresh()') )
- cmds.rowColumnLayout( 'master_Scrpt_Ldr_Win_ColsHeader_Right' , numberOfColumns = 2 , parent = 'master_Scrpt_Ldr_Win_ColsHeader' )
- _scriptLoader_window_Icons[0] = cmds.button( 'Script_Loader_WinUI_Btn_Icon' , label = '=' , ann = 'Icon or Text only mode button.' , width = ( 190 / 10 ) , parent = 'master_Scrpt_Ldr_Win_ColsHeader_Right' , command = ( variables('toolID') + '.ScriptLoaderSystem_UI_IconTextMode()') )
- _scriptLoader_window_Icons[1] = cmds.button( 'Script_Loader_WinUI_Btn_Dock' , label = '[]' , ann = 'Docking or UnDocking mode button.' , width = ( 190 / 10 ) , parent = 'master_Scrpt_Ldr_Win_ColsHeader_Right' , command = ( variables('toolID') + '.ScriptLoaderSystem_UI_DockMode()') )
- _R_ClickOpts = cmds.popupMenu( parent = 'master_Scrpt_Ldr_Win' , button = 3 )
- cmds.menuItem( label = 'Goto preference file' , parent = _R_ClickOpts , command = ( variables('toolID') + '.gotoPrefsFile()' ) )
- cmds.menuItem( label = 'Reset preference file' , parent = _R_ClickOpts , command = ( variables('toolID') + '.resetPrefsFile()' ) )
- # cmds.menuItem( label = 'Add me to shelf?' , parent = _R_ClickOpts , command = ( variables('toolID') + '.()' ) )
- cmds.menuItem( label = 'Change Colourscheme?' , parent = _R_ClickOpts , command = ( variables('toolID') + '.ScriptLoaderSystem_UI_ColourSettings()' ) )
- #opts
- ScriptLoader_GlobalSettings.window_UI_PathBtn = cmds.button( label = ScriptLoader_GlobalSettings._ScriptsPath[0:15] , ann = ScriptLoader_GlobalSettings._ScriptsPath , parent = 'master_Scrpt_Ldr_Win_ColsHeader_Left' , command = ( variables('toolID') + '.ScriptLoaderSystem_UI_newFilePath()') )
- ## main header done, all scripts go below!
- ScriptLoader_GlobalSettings.window_UI_ScrollAttach = cmds.scrollLayout( parent = ScriptLoader_GlobalSettings.window_UI_PaneAttach , cr = True , vst = 10 ) #all script catogories nested to this
- cmds.showWindow( ScriptLoader_GlobalSettings.window_UI_Name )
- ScriptLoader_GlobalSettings = ScriptClass_ScriptLoaderGlobalSettings()
- def init():
- LoadPrefsFile() ## getting local info or creating setup file ..
- PopulateScriptClasses() ## find all scripts and setup the list of classes/container
- cmdMessage("Scripts loaded from disk: " + str(len(ScriptLoader_GlobalSettings.AllScriptClasses)) + " Scripts found." )
- ScriptLoaderSystem_UI() ## main window, only open this one time a session ..
- ScriptLoaderSystem_UI_PopulateScripts() ## use created classes to create the buttons in the window
- init()
Advertisement
Add Comment
Please, Sign In to add comment