Ejemplo n.º 1
0
    def run(self):
        try:
            cmds.deleteUI(self.workspaceControlName)
        except RuntimeError:
            pass

        self.show(dockable=True)
        cmds.workspaceControl(
            self.workspaceControlName,
            edit=True,
            dockToControl=['Outliner', 'right'])
        self.raise_()

        # Maya layout widget is added here to be parented under workspaceControl
        self.cw.tabWidget.addTab(mayaUIContent(self.workspaceControlName), "MayaLayout")
Ejemplo n.º 2
0
def restore_panels(engine):
    """
    Restores the persisted Shotgun app panels into their visible
    Maya workspace controls in the active Maya window.

    .. note:: This function is only meaningful for Maya 2017 and later,
              and does nothing for previous versions of Maya.

    :param engine: :class:`MayaEngine` instance running in Maya.
    """

    # Only restore Shotgun app panels in Maya 2017 and later.
    if mel.eval("getApplicationVersionAsFloat()") < 2017:
        return

    # Search for the Shotgun app panels that need to be restored
    # among the panels registered with the engine.
    for panel_id in engine.panels:

        # Recreate a Maya panel name with the Shotgun app panel unique identifier.
        maya_panel_name = MAYA_PANEL_PREFIX + SHOTGUN_APP_PANEL_PREFIX + panel_id

        # When the current Maya workspace contains the Maya panel workspace control,
        # the Shotgun app panel needs to be recreated and docked.
        if cmds.workspaceControl(maya_panel_name, exists=True):

            # Once Maya will have completed its UI update and be idle,
            # recreate and dock the Shotgun app panel.
            maya.utils.executeDeferred(engine.panels[panel_id]["callback"])
Ejemplo n.º 3
0
    def deleteInstances(self):
        ''' Delete any instances of this class '''
        mayaWindow = maya_main_window()
        if MAYA_2017:
            for obj in mayaWindow.children():
                if obj.objectName() == self.__class__.__name__:
                    obj.setParent(None)
                    obj.deleteLater()
            workspaceName = self.__class__.__name__ + 'WorkspaceControl'
            if cmds.workspaceControlState(workspaceName, q=True, exists=True):
                try:
                    cmds.workspaceControl(workspaceName, e=True, close=True)
                    cmds.deleteUI(workspaceName)
                except RuntimeError:
                    cmds.workspaceControlState(workspaceName, remove=True)

        else:
            for obj in mayaWindow.children():
                if type(obj) == MayaQDockWidget:
                    if obj.widget().objectName() == self.__class__.__name__:
                        mayaWindow.removeDockWidget(obj)
                        obj.setParent(None)
                        obj.deleteLater()
    def Dockable_Window_Fun(self, dock="undock", save=True):
        # 保存当前UI界面
        if save == True:
            self.DOCK = dock
            self.Save_Json_Fun()

        # 检测不同的UI 全部删除
        if cmds.window(self.undockWindow, query=True, exists=True):
            cmds.evalDeferred("cmds.deleteUI(\"" + self.undockWindow + "\")")

        if cmds.dockControl(self.dockControl, query=True, exists=True):
            cmds.evalDeferred("cmds.deleteUI(\"" + self.dockControl + "\")")

        if mel.eval("getApplicationVersionAsFloat;") >= 2017:
            if cmds.workspaceControl(self.workspaceCtrl,
                                     query=True,
                                     exists=True):
                cmds.deleteUI(self.workspaceCtrl)

        if save == False:
            os.remove(GUI_STATE_PATH)

        global Cam_Main_UI
        Cam_Main_UI = Cam_Main_UI_Interface(dock=dock)
Ejemplo n.º 5
0
def main():
    # 检测不同的UI 全部删除
    global Cap2Con_UI 

    try:
        if cmds.window(Cap2Con_UI.undockWindow,query=True,exists=True) :
            cmds.deleteUI(Cap2Con_UI.undockWindow)
    except:
        pass

    try:
        if cmds.dockControl(Cap2Con_UI.dockControl,query=True,exists=True) :
            cmds.deleteUI(Cap2Con_UI.dockControl)
    except:
        pass

    try:
        if cmds.workspaceControl(Cap2Con_UI.workspaceCtrl,query=True,exists=True) :
            cmds.deleteUI(Cap2Con_UI.workspaceCtrl)
    except:
        pass

    Cap2Con_UI = Cap2Con(dock="undock")
    Cap2Con_UI.show()
Ejemplo n.º 6
0
    def _makeMayaStandaloneWindow(self):
        '''Make a standalone window, though parented under Maya's mainWindow.
        The parenting under Maya's mainWindow is done so that the QWidget will not
        auto-destroy itself when the instance variable goes out of scope.
        '''
        origParent = self.parent()

        # Parent under the main Maya window
        mainWindowPtr = omui.MQtUtil.mainWindow()
        mainWindow = wrapInstance(long(mainWindowPtr), QMainWindow)
        self.setParent(mainWindow)

        # Make this widget appear as a standalone window even though it is parented
        if isinstance(self, QDockWidget):
            self.setWindowFlags(Qt.Dialog | Qt.FramelessWindowHint)
        else:
            self.setWindowFlags(Qt.Window)

        # Delete the parent workspace control if applicable
        if origParent:
            parentName = origParent.objectName()
            if parentName and len(parentName) and cmds.workspaceControl(
                    parentName, q=True, exists=True):
                cmds.deleteUI(parentName, control=True)
Ejemplo n.º 7
0
def main():
    graphWindowName = "customGraphEditorWindow"
    panelname = "graphEditor1"

    if cmds.workspaceControl(graphWindowName, ex=True):
        print "Restore Window"
        if cmds.workspaceControl(graphWindowName, q=True, r=True):
            changeLayot(graphWindowName, panelname)
        cmds.workspaceControl(graphWindowName, e=True, restore=True)

    else:
        print "New Window"
        if cmds.window(panelname + "Window", exists=True):
            cmds.deleteUI(panelname + "Window")
        cmds.workspaceControl(
            graphWindowName,
            label="Custom Graph Editor",
            retain=True,
            dup=False,
            uiScript=
            "from customGraphEditor import UI;UI.addWidgetToMayaWindow('%s','%s')"
            % (graphWindowName, panelname))
Ejemplo n.º 8
0
 def __init__(self):
     print ">> __init__"
     self.workspaceControlName = "superWorkspace"
     if mc.workspaceControl(self.workspaceControlName, exists=True):
         mc.deleteUI(self.workspaceControlName, control=True)
Ejemplo n.º 9
0
def enhanceScriptEditor():
    
    # NOTE 避免重复修改
    callback = cmds.scriptedPanelType( 'scriptEditorPanel', query=True, addCallback=True )
    if "addScriptEditorPanel2" == callback.strip():
        return
    
    # NOTE 从 scriptEditorPanel.mel 复制下来的代码 
    # NOTE 修改 execute & executeAll 按钮的执行代码 修复 Maya2017 运行崩溃问题
    mel.eval('''
        source "scriptEditorPanel.mel";

        global proc int isFullPathToScriptFile(string $f, string $test)
        {
            // In order to be a full path, we must have a directory.
            string $dir = dirname($f);
            return( size($dir) && `filetest $test $f` );
        }


        proc scriptEditorPredefines() 
        //
        // Predefinitions such as:
        // Tagging for labels which are used multiple times.  We can call uiRes() for the specified
        // labels later in the file.
        //
        {
            global string $gScriptEditorMenuBarPrefix = "scriptEditor";
            // Options Menu Item suffixes
            global string $showLineNumbersMenuItemSuffix = "ShowLineNumbersMenuItem";
            global string $useTabsForIndentMenuItemSuffix = "UseTabsForIndentMenuItem";
            global string $autoCloseBracesMenuItemSuffix = "AutoCloseBracesMenuItem";
            global string $commandCompletionMenuItemSuffix = "CommandCompletionMenuItem";
            global string $pathCompletionMenuItemSuffix = "PathCompletionMenuItem";
            global string $toolTipHelpMenuItemSuffix = "ToolTipHelpMenuItem";
            global string $showQuickHelpMenuItemSuffix = "QuickHelpMenuItem";
            global string $batchRenderMsgsMenuItemSuffix = "BatchRenderMessagesMenuItem";
            global string $echoAllCmdsMenuItemSuffix = "EchoAllCmdsMenuItem";
            global string $errorLineNumsMenuItemSuffix = "ErrorLineNumberMenuItem";
            global string $stackTraceMenuItemSuffix = "StackTraceMenuItem";
            global string $suppressResultsMenuItemSuffix = "SuppressResultsMenuItem";
            global string $suppressInfoMenuItemSuffix = "SuppressInfoMenuItem";
            global string $suppressWarningsMenuItemSuffix = "SuppressWarningsMenuItem";
            global string $suppressErrorsMenuItemSuffix = "SuppressErrorsMenuItem";
            global string $suppressErrorsMenuItemSuffix = "SuppressDupVarMessagesMenuItem";
            global string $suppressStackTraceMenuItemSuffix = "SuppressStackTraceMenuItem";
            global string $historyFilterNoneMenuItemSuffix = "FilterNoneMenuItem";
            global string $historyFilterMELMenuItemSuffix = "FilterMELMenuItem";
            global string $historyFilterPythonMenuItemSuffix = "FilterPythonMenuItem";
            global string $executerBackupFileName = "commandExecuter";
            global string $gLastUsedDir;
            
            // Tagging
            string $cancel					= (uiRes("m_scriptEditorPanel.kCancel"));
            // * menus
            string $file					= (uiRes("m_scriptEditorPanel.kFile"));
            string $edit					= (uiRes("m_scriptEditorPanel.kEdit"));
            string $history					= (uiRes("m_scriptEditorPanel.kHistory"));
            string $command					= (uiRes("m_scriptEditorPanel.kCommand"));
            string $help					= (uiRes("m_scriptEditorPanel.kHelp"));
            // file
            string $load					= (uiRes("m_scriptEditorPanel.kLoadScript"));
            string $source					= (uiRes("m_scriptEditorPanel.kSourceScript"));
            string $save					= (uiRes("m_scriptEditorPanel.kSaveScript"));
            string $saveToShelf				= (uiRes("m_scriptEditorPanel.kSaveScriptToShelf"));
            // edit
            string $undo					= (uiRes("m_scriptEditorPanel.kUndo"));
            string $redo					= (uiRes("m_scriptEditorPanel.kRedo")); 
            string $cut						= (uiRes("m_scriptEditorPanel.kCut")); 
            string $copy					= (uiRes("m_scriptEditorPanel.kCopy")); 
            string $paste					= (uiRes("m_scriptEditorPanel.kPaste"));
            string $selectAll				= (uiRes("m_scriptEditorPanel.kSelectAll"));
            string $clearHistory			= (uiRes("m_scriptEditorPanel.kClearHistory"));
            string $clearInput				= (uiRes("m_scriptEditorPanel.kClearInput"));
            string $clearAll				= (uiRes("m_scriptEditorPanel.kClearAll"));
            string $goto					= (uiRes("m_scriptEditorPanel.kGoto"));
            string $indentSel				= (uiRes("m_scriptEditorPanel.kIndentSelection"));
            string $unindentSel				= (uiRes("m_scriptEditorPanel.kUnindentSelection"));
            // show
            string $showHistory				= (uiRes("m_scriptEditorPanel.kShowHistory"));
            string $showInput				= (uiRes("m_scriptEditorPanel.kShowInput"));
            string $showBoth				= (uiRes("m_scriptEditorPanel.kShowBoth"));
            string $searchAndReplace		= (uiRes("m_scriptEditorPanel.kSearchAndReplace"));
            // history
            string $batchRenderMessages		= (uiRes("m_scriptEditorPanel.kBatchRenderMessages"));
            string $echoAllCommands			= (uiRes("m_scriptEditorPanel.kEchoAllCommands"));
            string $showErrorLineNumbers	= (uiRes("m_scriptEditorPanel.kLineNumbersInErrors"));
            string $showStackTrace			= (uiRes("m_scriptEditorPanel.kShowStackTrace"));
            string $suppressCommandResults	= (uiRes("m_scriptEditorPanel.kSuppressCommandResults"));
            string $suppressInfoMessages	= (uiRes("m_scriptEditorPanel.kSuppressInfoMessages"));
            string $suppressWarningMessages = (uiRes("m_scriptEditorPanel.kSuppressWarningMessages"));
            string $suppressErrorMessages	= (uiRes("m_scriptEditorPanel.kSuppressErrorMessages"));
            string $suppressDupVarMessages	= (uiRes("m_scriptEditorPanel.kSuppressDupVarMessages"));
            string $suppressStackWindow		= (uiRes("m_scriptEditorPanel.kSuppressStackWindow"));
            string $filterOutput			= (uiRes("m_scriptEditorPanel.kFilterOutput"));
            // command
            string $showLineNumbers			= (uiRes("m_scriptEditorPanel.kShowLineNumbers"));
            string $useTabsForIndent		= (uiRes("m_scriptEditorPanel.kUseTabsForIndent"));	
            string $autoCloseBraces			= (uiRes("m_scriptEditorPanel.kAutoCloseBraces"));	
            string $showQuickHelp			= (uiRes("m_scriptEditorPanel.kShowQuickHelp"));
            string $commandCompletion			= (uiRes("m_scriptEditorPanel.kCommandCompletion"));
            string $pathCompletion			= (uiRes("m_scriptEditorPanel.kPathCompletion"));
            string $toolTipHelp			= (uiRes("m_scriptEditorPanel.kToolTipHelp"));
            string $showCommandHelp			= (uiRes("m_scriptEditorPanel.kShowCommandHelp"));
            string $execute					= (uiRes("m_scriptEditorPanel.kExecute"));
            string $executeAll				= (uiRes("m_scriptEditorPanel.kExecuteAll"));
            // tabs
            string $tabName					= (uiRes("m_scriptEditorPanel.kTabName"));
            string $tabNameWarning			= (uiRes("m_scriptEditorPanel.kInvalidTabNameWarning"));
            string $addTab					= (uiRes("m_scriptEditorPanel.kAddTab"));
            string $rename					= (uiRes("m_scriptEditorPanel.kRename"));
            //
            string $searchError				= (uiRes("m_scriptEditorPanel.kSearchFailed"));
        }

        global proc
        addScriptEditorPanel2 (string $whichPanel)
        //
        //  Description:mp
        //		Add the panel to a layout.
        //		Parent the editors to that layout and create any other
        //		controls required.
        //
        {
            // Predefines
            scriptEditorPredefines;
            //
            global int $gScriptEditorMenuBarVisible;
            global string $gCommandPopupMenus[];
                
            global string $gCommandLayout;
            global string $gCommandReporter;
            global string $gCommandExecuter[];
            global string $gCommandExecuterLayout[];
            global string $gCommandExecuterName[];
            global string $gCommandExecuterType[];
            global string $gLastFocusedCommandExecuter;
            global string $gLastFocusedCommandReporter;
            global string $gLastFocusedCommandControl;

            $gScriptEditorMenuBarVisible = 1;
            $gLastFocusedCommandControl = "";
            $gLastFocusedCommandReporter = "";
            $gLastFocusedCommandExecuter = "";

            $gCommandExecuterLayout = {};
            $gCommandExecuter = {};
            $gCommandPopupMenus = {};

            global string $gCommandExecuterTabs;
            global string $gCommandExecuterTabsPane;
            string $editorControl = ($whichPanel + "EditorControl");

            int $hasPython = `exists python`;

            // Make sure that there is no template active
            setUITemplate -pushTemplate NONE;

            // clear the option vars from before first;
            if (size($gCommandExecuter) == 0) {
                // on the first instance of the script editor, we load the arrays from the option vars
                if (`optionVar -exists ScriptEditorExecuterTypeArray`) {
                    // We first load them into temporary arrays and then make sure that we
                    // don't have any that are file's which are duplicated in array.
                    string $tempCommandExecuterName[] = `optionVar -q ScriptEditorExecuterLabelArray`;
                    string $tempCommandExecuterType[] = `optionVar -q ScriptEditorExecuterTypeArray`;
                    clear($gCommandExecuterName);
                    clear($gCommandExecuterType);

                    int $len = size($tempCommandExecuterName);
                    int $i;
                    int $index;
                    for ($i = 0; $i < $len; ++$i) {
                        // If this item points to a file, make sure we don't already have it.
                        // If this item points to a scratch tab, just add it.
                        if (isFullPathToScriptFile($tempCommandExecuterName[$i], "-r")) {
                            if (0 == stringArrayContains($tempCommandExecuterName[$i], $gCommandExecuterName)) {
                                $gCommandExecuterName[$index] = $tempCommandExecuterName[$i];
                                $gCommandExecuterType[$index] = $tempCommandExecuterType[$i];
                                $index++;
                            }
                        } else {
                            $gCommandExecuterName[$index] = $tempCommandExecuterName[$i];
                            $gCommandExecuterType[$index] = $tempCommandExecuterType[$i];
                            $index++;
                        }
                    }
                }
            }else {
                if (`optionVar -exists ScriptEditorExecuterTypeArray`) {
                    optionVar -clearArray ScriptEditorExecuterLabelArray;
                    optionVar -clearArray ScriptEditorExecuterTypeArray;
                }
            }

            // Define the standard panel
            //
            string $widgetList[];

            $widgetList[2] = `scriptedPanel -query -control $whichPanel`;
            $widgetList[0] = `formLayout`;
            $widgetList[3] = `frameLayout -visible true -borderVisible false
                    -labelVisible false -collapsable false -collapse true`;
            $widgetList[4] = `formLayout -visible true`;
            $widgetList[5] = `flowLayout -columnSpacing 4`;
            setParent $widgetList[0];
            $widgetList[6] = `formLayout -visible true`;

            formLayout -edit
                -attachForm $widgetList[3] top 0 
                -attachForm $widgetList[3] right 0
                -attachForm $widgetList[3] left 0

                -attachControl $widgetList[6] top 0 $widgetList[3]
                -attachForm $widgetList[6] bottom 0
                -attachForm $widgetList[6] right 0
                -attachForm $widgetList[6] left 0
                $widgetList[0];

            setParent $widgetList[0];

            
            // Add tools to the tool layout
            //
            int $iconSize = 23;
            setParent $widgetList[5];
                iconTextButton 
                    -width $iconSize -height $iconSize
                    -annotation (uiRes("m_scriptEditorPanel.kLoadScript"))
                    -image "openScript.png"
                    -command "handleScriptEditorAction \\"load\\""
                    openScriptButton;
                iconTextButton 
                    -width $iconSize -height $iconSize
                    -annotation (uiRes("m_scriptEditorPanel.kSourceScript"))
                    -image "sourceScript.png"
                    -command "handleScriptEditorAction \\"source\\""
                    sourceScriptButton;
                iconTextButton 
                    -width $iconSize -height $iconSize
                    -annotation (uiRes("m_scriptEditorPanel.kSaveScript"))
                    -image "save.png"
                    -command "handleScriptEditorAction \\"save\\""
                    saveScriptButton;
                iconTextButton 
                    -width $iconSize -height $iconSize
                    -annotation (uiRes("m_scriptEditorPanel.kSaveScriptToShelf"))
                    -image "saveToShelf.png"
                    -command "handleScriptEditorAction \\"saveToShelf\\""
                    saveScriptToShelfButton;

                separator -height $iconSize -horizontal false -style single fileSeperator;

                iconTextButton 
                    -width $iconSize -height$iconSize
                    -annotation (uiRes("m_scriptEditorPanel.kClearHistory"))
                    -image "clearHistory.png"
                    -command "handleScriptEditorAction \\"clearHistory\\""
                    clearHistoryButton;
                iconTextButton 
                    -width $iconSize -height $iconSize
                    -annotation (uiRes("m_scriptEditorPanel.kClearInput"))
                    -image "clearInput.png"
                    -command "handleScriptEditorAction \\"clearInput\\""
                    clearInputButton;
                iconTextButton 
                    -width $iconSize -height $iconSize
                    -annotation (uiRes("m_scriptEditorPanel.kClearAll"))
                    -image "clearAll.png"
                    -command "handleScriptEditorAction \\"clearAll\\""
                    clearAllButton;

                separator -height $iconSize -horizontal false -style single clearSeperator;

                iconTextButton 
                    -width $iconSize -height $iconSize
                    -annotation (uiRes("m_scriptEditorPanel.kShowHistory"))
                    -image "showHistory.png"
                    -command "handleScriptEditorAction \\"maximizeHistory\\""
                    showHistoryButton;
                iconTextButton 
                    -width $iconSize -height $iconSize
                    -annotation (uiRes("m_scriptEditorPanel.kShowInput"))
                    -image "showInput.png"
                    -command "handleScriptEditorAction \\"maximizeInput\\""
                    showInputButton;
                iconTextButton 
                    -width $iconSize -height $iconSize
                    -annotation (uiRes("m_scriptEditorPanel.kShowBoth"))
                    -image "showBoth.png"
                    -command "handleScriptEditorAction \\"maximizeBoth\\""
                    showBothButton;

                separator -height $iconSize -horizontal false -style single showSeperator;

                iconTextButton 
                    -width $iconSize -height $iconSize
                    -annotation (uiRes("m_scriptEditorPanel.kEchoAllCommands"))			
                    -command "handleScriptEditorAction \\"echoAllCommands\\""
                    echoAllCommandsButton;
                // echo all commands initial icon state
                if (`optionVar -exists echoAllLines`) {
                    string $icon = (`optionVar -q echoAllLines` ? "echoCommands.png" : "echoCommandsOff.png");
                    iconTextButton -e -image $icon echoAllCommandsButton;
                }	

                iconTextButton 
                    -width $iconSize -height $iconSize
                    -annotation (uiRes("m_scriptEditorPanel.kShowLineNumbers"))			
                    -command "handleScriptEditorAction \\"showLineNumbers\\""
                    showLineNumbersButton;
                // show line numbers initial icon state
                if (`optionVar -exists commandExecuterShowLineNumbers`) {
                    string $icon = (`optionVar -q commandExecuterShowLineNumbers` ? "showLineNumbers.png" : "showLineNumbersOff.png");
                    iconTextButton -e -image $icon showLineNumbersButton;
                }

                separator -height $iconSize -horizontal false -style single optionsSeperator;

                int $version = `about -v`;
                if ($version > 2017){
                    iconTextButton 
                        -width $iconSize -height $iconSize
                        -annotation (uiRes("m_scriptEditorPanel.kExecuteAll"))
                        -image "executeAll.png"
                        -command "handleScriptEditorAction \\"executeAll\\";python \\"import mpdb;mpdb.quitting = False\\""
                        executeAllButton;
                    iconTextButton 
                        -width $iconSize -height $iconSize
                        -annotation (uiRes("m_scriptEditorPanel.kExecute"))
                        -image "execute.png"
                        -command "handleScriptEditorAction \\"execute\\";python \\"import mpdb;mpdb.quitting = False\\""
                        executeButton;
                }else{
                    iconTextButton 
                        -width $iconSize -height $iconSize
                        -annotation (uiRes("m_scriptEditorPanel.kExecuteAll"))
                        -image "executeAll.png"
                        -command "python \\"import mpdb;mpdb.scriptEditorExecuteAll(globals());mpdb.quitting = False\\""
                        executeAllButton;
                    iconTextButton 
                        -width $iconSize -height $iconSize
                        -annotation (uiRes("m_scriptEditorPanel.kExecute"))
                        -image "execute.png"
                        -command "python \\"import mpdb;mpdb.scriptEditorExecute(globals());mpdb.quitting = False\\""
                        executeButton;
                }


                separator -height $iconSize -horizontal false -style single executeSeperator;

                textField 
                    -width 120 -height 20
                    -annotation (uiRes("m_scriptEditorPanel.kSASToolbarField"))
                    -enterCommand "searchAndSelectToolbarCmd(true)"
                    -alwaysInvokeEnterCommandOnReturn true
                    scriptEditorToolbarSearchField;
                popupMenu -postMenuCommand "searchAndSelectToolbarPopupUpdate" 
                    scriptEditorToolbarSearchFieldPopupMenu;	
                iconTextButton 
                    -width $iconSize -height $iconSize
                    -annotation (uiRes("m_scriptEditorPanel.kSASToolbarDownButton"))
                    -image "searchDown.png"
                    -command "searchAndSelectToolbarCmd(true)"
                    scriptEditorToolbarSearchDownButton;
                iconTextButton 
                    -width $iconSize -height $iconSize
                    -annotation (uiRes("m_scriptEditorPanel.kSASToolbarUpButton"))
                    -image "searchUp.png"
                    -command "searchAndSelectToolbarCmd(false)"
                    scriptEditorToolbarSearchDownUp;

                separator -height $iconSize -horizontal false -style single searchSeperator;

                textField 
                    -width 30 -height 20
                    -annotation (uiRes("m_scriptEditorPanel.kGotoLineToolbarField"))
                    -enterCommand "gotoLineToolbarCmd"
                    -alwaysInvokeEnterCommandOnReturn true
                    scriptEditorToolbarGotoField;
                popupMenu -postMenuCommand "gotoLineToolbarPopupUpdate" 
                    scriptEditorToolbarGotoFieldPopupMenu;							
                iconTextButton 
                    -width $iconSize -height $iconSize
                    -annotation (uiRes("m_scriptEditorPanel.kGotoLineToolbarButton"))
                    -image "gotoLine.png"
                    -command "gotoLineToolbarCmd"
                    scriptEditorToolbarGotoLineButton;
                

            int $formMargin = 2;
            //	Layout the toolbar
            //
            setParent $widgetList[4];
            formLayout -edit
                -attachForm	$widgetList[5] "left"	$formMargin
                -attachForm $widgetList[5] "top"    $formMargin
                -attachForm $widgetList[5] "bottom" $formMargin
                -attachForm $widgetList[5] "right"  0
                
                $widgetList[4];
            // Parent the editors to the editor layout
            //
            setParent $widgetList[6];

            {
                // build the panels first
                $gCommandLayout = `paneLayout -configuration "horizontal2"`;
                    $gCommandReporter = `cmdScrollFieldReporter -width 20 -height 20`;
                    cmdScrollFieldReporter -e -receiveFocusCommand ("setLastFocusedCommandReporter " + $gCommandReporter) $gCommandReporter;	
                        $gCommandPopupMenus[size($gCommandPopupMenus)] = `popupMenu -markingMenu true -postMenuCommand "verifyCommandPopupMenus"`;
                        buildScriptEditorCondensedPopupMenus($gCommandPopupMenus[size($gCommandPopupMenus)-1], true);		
                        loadCommandReporterOptionVars($gCommandReporter);

                    setLastFocusedCommandReporter $gCommandReporter;

                    $gCommandExecuterTabsPane = `paneLayout -configuration "vertical2" -staticWidthPane 2`;
                    $gCommandExecuterTabs = `tabLayout -selectCommand "selectCurrentExecuterControl" -showNewTab true
                                                -newTabCommand "handleScriptEditorAction \\"addExecuterTab\\""
                                                -borderStyle "none"`;
                    if (size($gCommandExecuterName) == 0) {
                        // build all new	
                        buildNewExecuterTab(-1, "MEL", "mel", 0);
                        if ($hasPython) {
                            buildNewExecuterTab(-1, "Python", "python", 0);
                        }
                    }else {
                        // don't need to update name, just build with the other info
                        int $len = size($gCommandExecuterName);
                        int $i;
                        for ($i = 0; $i < $len; ++$i) {
                            buildNewExecuterTab($i, $gCommandExecuterName[$i], $gCommandExecuterType[$i], 0);
                        }
                    }

                    if (size($gCommandExecuterName) > 0)
                        setLastFocusedCommandExecuter $gCommandExecuter[0];

                    // help sidebar
                    setParent $gCommandExecuterTabsPane;

                    global string $gCommandExecuterSideBar;
                    global string $gCommandExecuterSideBarHelpForm;
                    global string $gCommandExecuterSideBarHelpField;
                    global string $gCommandExecuterSideBarHelpResults;
                    global int $gCommandExecuterShowQuickHelp;

                    $gCommandExecuterSideBar = `tabLayout`;
                    $gCommandExecuterSideBarHelpForm = `formLayout -width 120`;
                        $gCommandExecuterSideBarHelpField = `textField -height 24 -enterCommand "showFieldCmdQuickHelp" -alwaysInvokeEnterCommandOnReturn true`;
                        $gCommandExecuterSideBarHelpResults = `textScrollList -doubleClickCommand "doubleClickCmdQuickHelp" -allowMultiSelection on`;

                            // popup menu to hide quick help
                            popupMenu;
                                menuItem -radialPosition "N"
                                        -label (uiRes("m_scriptEditorPanel.kShowDetailedHelp"))
                                        -command "showFieldCmdDocumentation";
                                menuItem -radialPosition "S"
                                        -label (uiRes("m_scriptEditorPanel.kHideQuickHelp"))
                                        -command "toggleCmdQuickHelp(0, 0)";
                    
                    tabLayout -e -tabLabel $gCommandExecuterSideBarHelpForm (uiRes("m_scriptEditorPanel.kQuickHelp")) $gCommandExecuterSideBar;
                    
                    formLayout -e 
                                -attachForm $gCommandExecuterSideBarHelpField top 0
                                -attachForm $gCommandExecuterSideBarHelpField left 0
                                -attachForm $gCommandExecuterSideBarHelpField right 0
                                -attachNone $gCommandExecuterSideBarHelpField bottom

                                -attachControl $gCommandExecuterSideBarHelpResults top 2 $gCommandExecuterSideBarHelpField
                                -attachForm $gCommandExecuterSideBarHelpResults left 0
                                -attachForm $gCommandExecuterSideBarHelpResults right 0
                                -attachForm $gCommandExecuterSideBarHelpResults bottom 0

                            $gCommandExecuterSideBarHelpForm;
                
                    // show and attach forms accordingly
                    // NOTE: move formLayout attachments out of func if we add new side bars!
                    toggleCmdQuickHelp($gCommandExecuterShowQuickHelp, 1);

                formLayout -e 
                            -attachForm $gCommandLayout left 0
                            -attachForm $gCommandLayout right 0
                            -attachForm $gCommandLayout top 0
                            -attachForm $gCommandLayout bottom 0 $widgetList[6];
            }

            //	menuBarLayout is turned on for this editor -
            //	create the top level menus
            //
            setParent $widgetList[2];

            // build the menus
            { 
                global string $gScriptEditorMenuBarPrefix;
                buildScriptEditorMenus($widgetList[2], $gScriptEditorMenuBarPrefix, false, false);

                addContextHelpProc $whichPanel "buildScriptEditorContextHelpItems";
                doHelpMenu $whichPanel $whichPanel;
            }

            // select the previous executer tab (if one was saved)
            //
            if (`optionVar -exists ScriptEditorExecuterTabIndex`) {
                int $prevIdx = `optionVar -q ScriptEditorExecuterTabIndex`;
                if ( (0 < $prevIdx) && ($prevIdx <= `tabLayout -q -numberOfChildren $gCommandExecuterTabs`) ) {
                    tabLayout -e -selectTabIndex $prevIdx $gCommandExecuterTabs;
                }
            }

            setUITemplate -popTemplate;

            selectCurrentExecuterControl;

            scriptJob -parent $whichPanel -event "quitApplication" ("removeScriptEditorPanel " + $whichPanel);

            // # NOTE 添加键盘执行事件 
            python "from mpdb import  scriptEditorEventFilter;scriptEditorEventFilter()";
        }
    ''')
    cmds.scriptedPanelType( 'scriptEditorPanel', e=1, addCallback='addScriptEditorPanel2' )
    if cmds.workspaceControl("scriptEditorPanel1Window",query=1,ex=1):
        # NOTE 关闭当前代码编辑器窗口
        cmds.deleteUI("scriptEditorPanel1Window")
        # NOTE 重新打开一个新的窗口
        mel.eval("ScriptEditor;")

# if __name__ == "__main__":
#     enhanceScriptEditor()
Ejemplo n.º 10
0
    def launch(self):
        if mc.workspaceControl(self.wscName, query=True, exists=True):
            mc.workspaceControl(self.wscName, edit=True, close=True)
            try:
                mc.deleteUI(self.wscName, control=True)
            except:
                pass

        mc.workspaceControl(self.wscName,
                            uiScript="KMod.buildUI()",
                            floating=False,
                            retain=False)
        mc.workspaceControl(self.wscName, edit=True, minimumWidth=58)
        mc.workspaceControl(self.wscName, edit=True, resizeWidth=58)
        mc.workspaceControl(self.wscName, edit=True, tabPosition=("west", 1))
        mc.workspaceControl(self.wscName,
                            edit=True,
                            dockToControl=("Outliner", "left"))
        #print ">> width = ", mc.workspaceControl(self.wscName, query=True, width=True)
        mc.workspaceControl("ToolBox", edit=True, visible=False)
Ejemplo n.º 11
0
    def collect_rendered_images(self, parent_item):
        """
        Creates items for any rendered images that can be identified by
        render layers in the file.

        :param parent_item: Parent Item instance
        :return:
        """
        scene = cmds.file(q=True, sn=True)
        basename = os.path.basename(scene)
        _name, ext = os.path.splitext(basename)
        work_dir = cmds.workspace(q=True, sn=True)
        image_dir = work_dir + '/images'

        # get a list of render layers not defined in the file
        render_layers = []
        _render = cmds.getAttr("defaultRenderGlobals.currentRenderer")
        # _prefix = cmds.getAttr("vraySettings.fileNamePrefix")
        for layer_node in cmds.ls(type="renderLayer"):
            try:
                # if this succeeds, the layer is defined in a referenced file
                cmds.referenceQuery(layer_node, filename=True)
            except RuntimeError:
                # runtime error means the layer is defined in this session
                render_layers.append(layer_node)

        # iterate over defined render layers and query the render settings for
        # information about a potential render
        for layer in render_layers:

            self.logger.info("Processing render layer: %s" % (layer, ))

            # use the render settings api to get a path where the frame number
            # spec is replaced with a '*' which we can use to glob
            (frame_glob, ) = cmds.renderSettings(genericFrameImageName="*",
                                                 fullPath=True,
                                                 layer=layer)
            if _render == "vray":
                try:

                    mel.eval("unifiedRenderGlobalsWindow;")
                    cmds.workspaceControl("unifiedRenderGlobalsWindow",
                                          e=True,
                                          vis=0,
                                          r=True)
                    fileprefix = cmds.getAttr('vraySettings.fileNamePrefix')
                    _image_format = cmds.getAttr("vraySettings.imageFormatStr")
                    if fileprefix == '<Scene>/<Layer>/<Scene>':
                        image_file = image_dir + '/' + _name + '/' + layer + '/' + _name + '*.%s' % _image_format
                        frame_glob = image_file
                except:
                    pass
            # see if there are any files on disk that match this pattern
            rendered_paths = glob.glob(frame_glob)
            self.logger.debug("rendered_paths: ----%s----" % rendered_paths)
            if rendered_paths:
                # we only need one path to publish, so take the first one and
                # let the base class collector handle it
                item = super(MayaSessionCollector,
                             self)._collect_file(parent_item,
                                                 rendered_paths[0],
                                                 frame_sequence=True)

                # the item has been created. update the display name to include
                # the an indication of what it is and why it was collected
                item.name = "%s (Render Layer: %s)" % (item.name, layer)
                item._expanded = False
                item._active = False
Ejemplo n.º 12
0
 def delete_control(self, control):
     if mc.workspaceControl(control, q=True, exists=True):
         mc.workspaceControl(control, e=True, close=True)
         mc.deleteUI(control, control=True)
         self.delete_callbacks()
Ejemplo n.º 13
0
    def launch(self):
        # self.kmClock()
        if mc.workspaceControl(self.wscName, query=True, exists=True):
            mc.workspaceControl(self.wscName, edit=True, close=True)
            try:
                mc.deleteUI(self.wscName, control=True)
            except:
                pass

        mc.workspaceControl(self.wscName,
                            uiScript="KShelf.buildUI()",
                            floating=False,
                            retain=False)
        mc.workspaceControl(self.wscName,
                            edit=True,
                            minimumHeight=self.iconSize + 2)
        mc.workspaceControl(self.wscName,
                            edit=True,
                            resizeHeight=self.iconSize + 2)
        mc.workspaceControl(self.wscName, edit=True, tabPosition=("west", 1))
        mc.workspaceControl(self.wscName, edit=True, heightProperty="fixed")
        # mc.workspaceControl(self.wscName, edit=True, dockToMainWindow=("top", True))

        mc.workspaceControl("Shelf", edit=True, visible=True)
        mc.workspaceControl(self.wscName,
                            edit=True,
                            dockToControl=("Shelf", "bottom"))
        mc.workspaceControl(self.wscName, edit=True, r=True)
        mc.workspaceControl("Shelf", edit=True, visible=False)
Ejemplo n.º 14
0
def dock_panel(engine, shotgun_panel, title, new_panel):
    """
    Docks a Shotgun app panel into a new Maya panel in the active Maya window.

    In Maya 2016 and before, the panel is docked into a new tab of Maya Channel Box dock area.
    In Maya 2017 and after, the panel is docked into a new workspace area in the active Maya workspace.

    :param engine: :class:`MayaEngine` instance running in Maya.
    :param shotgun_panel: Qt widget at the root of the Shotgun app panel.
                          This Qt widget is assumed to be child of Maya main window.
                          Its name can be used in standard Maya commands to reparent it under a Maya panel.
    :param title: Title to give to the new dock tab.
    :param new_panel: True when the Shotgun app panel was just created by the calling function.
                      False when the Shotgun app panel was retrieved from under an existing Maya panel.
    :returns: Name of the newly created Maya panel.
    """

    # The imports are done here rather than at the module level to avoid spurious imports
    # when this module is reloaded in the context of a workspace control UI script.
    import maya.mel as mel

    # Retrieve the Shotgun app panel name.
    shotgun_panel_name = shotgun_panel.objectName()

    # Use the proper Maya panel docking method according to the Maya version.
    if mel.eval("getApplicationVersionAsFloat()") < 2017:

        import maya.utils
        import pymel.core as pm

        # Create a Maya panel name.
        maya_panel_name = "maya_%s" % shotgun_panel_name

        # When the Maya panel already exists, it can be deleted safely since its embedded
        # Shotgun app panel has already been reparented under Maya main window.
        if pm.control(maya_panel_name, query=True, exists=True):
            engine.log_debug("Deleting existing Maya panel %s." % maya_panel_name)
            pm.deleteUI(maya_panel_name)

        # Create a new Maya window.
        maya_window = pm.window()
        engine.log_debug("Created Maya window %s." % maya_window)

        # Add a layout to the Maya window.
        maya_layout = pm.formLayout(parent=maya_window)
        engine.log_debug("Created Maya layout %s." % maya_layout)

        # Reparent the Shotgun app panel under the Maya window layout.
        engine.log_debug("Reparenting Shotgun app panel %s under Maya layout %s." % (shotgun_panel_name, maya_layout))
        pm.control(shotgun_panel_name, edit=True, parent=maya_layout)

        # Keep the Shotgun app panel sides aligned with the Maya window layout sides.
        pm.formLayout(maya_layout,
                      edit=True,
                      attachForm=[(shotgun_panel_name, 'top', 1),
                                  (shotgun_panel_name, 'left', 1),
                                  (shotgun_panel_name, 'bottom', 1),
                                  (shotgun_panel_name, 'right', 1)]
        )

        # Dock the Maya window into a new tab of Maya Channel Box dock area.
        engine.log_debug("Creating Maya panel %s." % maya_panel_name)
        pm.dockControl(maya_panel_name, area="right", content=maya_window, label=title)

        # Since Maya does not give us any hints when a panel is being closed,
        # install an event filter on Maya dock control to monitor its close event
        # in order to gracefully close and delete the Shotgun app panel widget.
        # Some obscure issues relating to UI refresh are also resolved by the event filter.
        panel_util.install_event_filter_by_name(maya_panel_name, shotgun_panel_name)

        # Once Maya will have completed its UI update and be idle,
        # raise (with "r=True") the new dock tab to the top.
        maya.utils.executeDeferred("import maya.cmds as cmds\n" \
                                   "cmds.dockControl('%s', edit=True, r=True)" % maya_panel_name)

    else:  # Maya 2017 and later

        import maya.cmds as cmds

        # Create a Maya panel name.
        maya_panel_name = "maya_%s" % shotgun_panel_name

        # When the current Maya workspace contains our Maya panel workspace control,
        # embed the Shotgun app panel into this workspace control.
        # This can happen when the engine has just been started and the Shotgun app panel is
        # displayed for the first time around, or when the user reinvokes a displayed panel.
        if cmds.workspaceControl(maya_panel_name, exists=True) and \
           cmds.workspaceControl(maya_panel_name, query=True, visible=True):

            engine.log_debug("Restoring Maya workspace panel %s." % maya_panel_name)

            # Set the Maya default parent to be our Maya panel workspace control.
            cmds.setParent(maya_panel_name)

            # Embed the Shotgun app panel into the Maya panel workspace control.
            build_workspace_control_ui(shotgun_panel_name)

            return maya_panel_name

        # Retrieve the Channel Box dock area, with error reporting turned off.
        # This MEL function is declared in Maya startup script file UIComponents.mel.
        # It returns an empty string when a dock area cannot be found, but Maya will
        # retrieve the Channel Box dock area even when it is not shown in the current workspace.
        dock_area = mel.eval('getUIComponentDockControl("Channel Box / Layer Editor", false)')
        engine.log_debug("Retrieved Maya dock area %s." % dock_area)

        # This UI script will be called to build the UI of the new dock tab.
        # It will embed the Shotgun app panel into a Maya workspace control.
        # Since Maya 2017 expects this script to be passed in as a string,
        # not as a function pointer, it must retrieve the current module in order
        # to call function build_workspace_control_ui() that actually builds the UI.
        # Note that this script will be saved automatically with the workspace control state
        # in the Maya layout preference file when the user quits Maya, and will be executed
        # automatically when Maya is restarted later by the user.
        ui_script = "import sys\n" \
                    "import maya.api.OpenMaya\n" \
                    "import maya.utils\n" \
                    "for m in sys.modules:\n" \
                    "    if 'tk_maya.panel_generation' in m:\n" \
                    "        try:\n" \
                    "            sys.modules[m].build_workspace_control_ui('%(panel_name)s')\n" \
                    "        except Exception, e:\n" \
                    "            msg = 'Shotgun: Cannot restore %(panel_name)s: %%s' %% e\n" \
                    "            fct = maya.api.OpenMaya.MGlobal.displayError\n" \
                    "            maya.utils.executeInMainThreadWithResult(fct, msg)\n" \
                    "        break\n" \
                    "else:\n" \
                    "    msg = 'Shotgun: Cannot restore %(panel_name)s: Shotgun is not currently running'\n" \
                    "    fct = maya.api.OpenMaya.MGlobal.displayError\n" \
                    "    maya.utils.executeInMainThreadWithResult(fct, msg)\n" \
                    % {"panel_name": shotgun_panel_name}

        # Dock the Shotgun app panel into a new workspace control in the active Maya workspace.
        engine.log_debug("Creating Maya workspace panel %s." % maya_panel_name)

        kwargs = {"uiScript": ui_script,
                  "retain": False,  # delete the dock tab when it is closed
                  "label": title,
                  "r": True}  # raise at the top of its workspace area

        # When we are in a Maya workspace where the Channel Box dock area can be found,
        # dock the Shotgun app panel into a new tab of this Channel Box dock area
        # since the user was used to this behaviour in previous versions of Maya.
        # When we are in a Maya workspace where the Channel Box dock area can not be found,
        # let Maya embed the Shotgun app panel into a floating workspace control window.
        kwargs["tabToControl"] = (dock_area, -1)  # -1 to append a new tab

        cmds.workspaceControl(maya_panel_name, **kwargs)

    return maya_panel_name