Ejemplo n.º 1
0
        import PySide.QtGui as ModQtGui
        return ModQtGui.QDialog( mwin )
    
    
    @classmethod
    def infoPrompt(cls, msg='message', title='Maya' ):
        cls.prompt( msg=msg, title=title, okOnly=True )
        return None

    @staticmethod
    def prompt( msg='', opts=None, typeToReturn=None, okOnly=False, returnEmptyStringAsNone=True, **kargs ):
        """
        Get a prompt and as soon as it's done, return the results.
        Can be told to return a string, int or float using:
        typeToReturn='string' or 'int' or 'float'
        
        
        By default if the user enters nothing,
        the return value will be: None
        
        Most of the time this is useful so the return value doesn't have to be checked to ensure
        it isn't an empty string.
        
        To return empty strings instead, set 
        returnEmptyStringAsNone to False
        """
        if opts is None:
            opts = kargs
    
        opts.setdefault( 'message', msg )
        opts.setdefault( 'title', 'Maya' )
        if okOnly:
            opts.setdefault( 'button', [ 'OK' ] )
        else:
            opts.setdefault( 'button', [ 'OK', 'Cancel'] )   
        opts.setdefault( 'dismissString', 'Cancel' )        

        
        if okOnly:
            result = pm.confirmDialog(**opts)
            text = None
        else:
            result = pm.promptDialog(**opts)
            if result == 'OK':
                text = pm.promptDialog(query=True, text=True)
            else:
                text =  None
        
        if returnEmptyStringAsNone:
            ## at this point text should always be in string-like form
            ## or the None object
            ## it won't be an int or float or something yet
            ## so it's safe to test it this way
            if not text:  
                text = None
        
Ejemplo n.º 2
0
 def rename_ui(self, **kwargs):
     self.rename_ip = pm.promptDialog(title="Rename Object",
                                      message="Enter name",
                                      button=["Ok", "Cancel"],
                                      cancelButton="Cancel",
                                      dismissString="Cancel")
     if self.rename_ip == "Ok":
         txt = pm.promptDialog(query=True, text=True)
         txt = self.get_stripped_text(ip_txt=txt)
         if txt.find(" ") > -1:
             pm.displayError("Names cannot contain spaces")
             return None
         self.rename_selection(new_name=txt)
Ejemplo n.º 3
0
    def getUserInput(self):
        self.result = pm.promptDialog(
            title=self.windowName,
            message='Enter Hotstring:',
            button=['OK', 'Cancel'],
            defaultButton='OK',
            cancelButton='Cancel',
            dismissString='')

        self.parent.text = 'help'
            
        if self.result == 'OK':
            self.parent.text = pm.promptDialog(query=True, text=True)

        self.parent.doAction()        
Ejemplo n.º 4
0
             text = str(text)
         if typeToReturn == 'float':
             text = float(text)
         elif typeToReturn=='int':
             text = int(text)
         return text
     else:
         return text
     
 @classmethod
 def setProjectByStringUi(cls):     
     dialogResult = pm.promptDialog(
             title='Set Project',
             message='Type or Paste Project Path Here:',
             button=['OK', 'Cancel'],
             defaultButton='OK',
             cancelButton='Cancel',
             dismissString='Cancel')
Ejemplo n.º 5
0
 def userStrToAction(self, commandsFromLast=None, textFromLast=""):
     rtcmds =  self.rtcmds   ## pm.mel.eval("runTimeCommand -q -ca;")
     
     cmdsStartingWith = []
     cmdsContaining = []
     
     
     if commandsFromLast is not None:
         commandsStr = 'Commands similar were found, but you must be more specific, or end your command with a space to force a "best guess".\n\n '
         for commandFromLast in commandsFromLast:
             commandsStr += commandFromLast + "   "
             
         messageStr = commandsStr  
             
     else:
         messageStr = ' Enter HotMel "search" command.\n\n HotMel commands are made automatically for most of the menu items in Maya, and often match the name. You can try typing in words to search for here. If several matches are found, they will be shown.\n\n End the command with spacebar to force best guess.\n End the command with a semicolon to run as Mel code.\n Use "runTimeCommand -q -ca;" to print a list of all available commands in the script editor.\n\n Press Enter To Execute'
             
         
     
     
     
     promptWin = pm.promptDialog(
         title="HotMel",
         message=messageStr,
         text=textFromLast,
         button=['OK'],
         defaultButton='OK',
         dismissString='')
     try:
         userStr = pm.promptDialog(query=True, text=True)
     except:
         print( "Error getting value from prompt dialog." )
         return
     
     searchStr = userStr.replace( " ", "" )
     
     for cmdStr in rtcmds:
         if cmdStr.startswith(searchStr):
             cmdsStartingWith.append( cmdStr )
         elif searchStr in cmdStr:
             cmdsContaining.append( cmdStr )
             
     
     cmdsStartingWith.sort()
     cmdsContaining.sort()
     
     cmdsFound = cmdsStartingWith + cmdsContaining
     
     
     
     
     ## If nothing entered, bail
     if userStr == "":
         tmp=0  ## do nothing here
         
     ## If we have an exact match, run it    
     elif userStr in cmdsFound:
         pm.mel.eval( searchStr )
     
     ## If it ends in a semicolon, then run it as a mel command
     elif userStr.endswith( ";" ):
         pm.mel.eval( searchStr )
     
     ## If it ends in a space, then run the first thing we find that start
     elif userStr.endswith( " " ):
         print userStr[:-1]
         spaceCmdFound = False
         for cmdToTest in cmdsFound:
             print "command: " + cmdToTest
             if cmdToTest.startswith( userStr[:-1] ):
                 print( cmdToTest )
                 pm.mel.eval( cmdToTest )
                 spaceCmdFound = True
                 break  ## We only want to run one command!
         if spaceCmdFound==False:
             for cmdToTest in cmdsFound:
                 if userStr[:-1] in cmdToTest:
                     print( cmdToTest )
                     pm.mel.eval( cmdToTest )
                     spaceCmdFound = True
                     break
                     
                 
     ## If there's only one command that matches, then run it         
     elif len(cmdsFound)==1:
         pm.mel.eval( cmdsFound[0] )
     
     
     ##  If none of these thngs are found, then run another thing entirely    
     else:
         defaultWasFound=False
         
         if len(cmdsFound)==2:
             if cmdsFound[1].endswith( "Options" ):
                 defaultWasFound=True
                 pm.mel.eval( cmdsFound[0] )
             
         if defaultWasFound==False:
             print(  cmdsFound )
             tmp = ""
             for cmd in cmdsFound[:4]:
                 tmp = tmp + " " + cmd
             OpenMaya.MGlobal.displayInfo( "Suggestions: " + tmp )
             self.userStrToAction( commandsFromLast=cmdsFound, textFromLast=userStr)