command (MEL/Python)
|
MGPickerUserPanel
|
Go to: Synopsis. MEL examples. Python examples.
Synopsis
MGPickerUserPanel (string, [allowedAreas=[UnsignedInt]],[allIds=[boolean]], [dockArea=UnsignedInt], [dockFeatures=boolean], [exist=boolean], [floating=boolean],[installWidget=string], [name=string], [pickerMode=[int]], [remove=[boolean]], [title=string], [visible=boolean])
Note: Strings representing zip full path when used with zip related flags. This is not depicted in the synopsis.
MGPickerUserPanel is NOT undoable, queryable, and editable.
This command create and manage a user widget parent, so that user can install their own widget into MG-Picker Studio.
Long name (short name)
|
Argument types
|
Properties
|
-allowedAreas(-aas)
|
UnsignedInt
|
  
|
|
The docking widget areas that the user panel is allow to dock in. In create and edit mode, you need to provide the integer version of Qt flag Qt::DockWidgetAreas.
|
|
-allIds(-ai)
|
|

|
|
This is a query only flag to get all user panel IDs get installed.
|
|
-dockArea(-da)
|
UnsignedInt
|
  
|
|
The dock area of the user panel, it only takes effect when the dock area is currently visible. In create and edit mode, you need to provide the integer version of Qt enum Qt::DockWidgetArea.
|
|
-dockFeatures(-df)
|
UnsignedInt
|
  
|
|
|
-exist(-ex)
|
|

|
|
Check if the user panel id exists.
|
|
-floating(-fl)
|
boolean
|
  
|
|
The flag gets/sets the floating state of the user panel.
|
|
-installWidget(-iw)
|
string
|
 
|
|
Create/Edit only flag to install a user widget by its object name. Check the example below for more information.
|
|
-name(-n)
|
|

|
|
An optional creation only flag to give a initial hint on the user panel ID. The actual ID will be a prefixed and possibly suffixed version of the name which will be guaranteed to be unique to MG-Picker Studio.
If no name provided, a default name "unamed" will be used.
|
|
-pickerMode(-pm)
|
int
|
  
|
|
Whether the user panel should show up on different MG-Picker Studio UI mode: 0=Designer Mode, 1=Animator Mode, 2=Both.
The value of 1 means the user panel will be hidden automatically when you switch to designer mode, and be shown when switched to animator mode.
|
|
-remove(-rm)
|
|

|
|
Remove this user panel, the installed widget will also be removed.
|
|
-title(-t)
|
string
|
  
|
|
The title of the dockable user panel.
|
|
-visible(-vis)
|
boolean
|
  
|
|
The visibility of user panel. The visibility first get ruled by pickerMode, this flag serves as another layer of visibility.
|
|
|
|
|
|
|
|
Flag can appear in Create mode of command
|
Flag can appear in Edit mode of command
|
Flag can appear in Query mode of command
|
Flag can be used more than once in a command.
|
MEL examples
// Install a MEL command based widget into MG-Picker and make it an animator mode only widget:
string $dockWgtId = `MGPickerUserPanel -name "test1" -title "Test User Panel" -pickerMode 1`;
string $userWidget = `columnLayout`;
colorSliderGrp -label "Blue" -rgb 0 0 1;
colorSliderGrp -label "Green" -hsv 120 1 1;
MGPickerUserPanel -e -installWidget $userWidget $dockWgtId;
// To remove, use: MGPickerUserPanel -e -remove $dockWgtId;
Python examples
# ---------------------------------------------------------------------
# Install a python command based widget into MG-Picker and make it an animator mode only widget:
from maya import cmds
dockWgtId = cmds.MGPickerUserPanel(name="pyCmdUi", title="Python Command UI", pickerMode=1)
userWidget = cmds.columnLayout()
cmds.colorSliderGrp(label="Blue", rgb=(0, 0, 1))
cmds.colorSliderGrp(label="Green", hsv=(120, 1, 1))
cmds.MGPickerUserPanel(dockWgtId, e=True, installWidget=userWidget)
# To remove, use: cmds.MGPickerUserPanel(dockWgtId, e=True, remove=True)
# ---------------------------------------------------------------------
# Install a native PySide2 QWidget into MG-Picker and make it an animator mode only widget.
# For PyQt5 it works in a similar way but you use sip instead of shiboken2.
from maya import cmds
from maya import OpenMayaUI as omui
from PySide2 import QtWidgets
from shiboken2 import wrapInstance
from mgpicker import mgp
class UserPanelExample(QtWidgets.QWidget):
def __init__(self, parent=None):
QtWidgets.QWidget.__init__(self, parent)
self.dockWgtId = cmds.MGPickerUserPanel(name="nativeQt")
cmds.MGPickerUserPanel(self.dockWgtId, e=True, title="Native Qt Panel")
cmds.MGPickerUserPanel(self.dockWgtId, e=True, dockArea=1)
cmds.MGPickerUserPanel(self.dockWgtId, e=True, pickerMode=2)
dockWgtPtr = omui.MQtUtil.findControl(self.dockWgtId)
self.dockWgt = wrapInstance(int(dockWgtPtr), QtWidgets.QDockWidget)
lay = QtWidgets.QVBoxLayout(self)
self.currentDocBtn = QtWidgets.QPushButton(self)
lay.addWidget(self.currentDocBtn)
self.uiModeBtn = QtWidgets.QPushButton(self)
lay.addWidget(self.uiModeBtn)
self.uiLangBtn = QtWidgets.QPushButton(self)
lay.addWidget(self.uiLangBtn)
# Qt Native Way to install the widget.
self.dockWgt.setWidget(self)
# Another way to install it, is to set object name and use installWidget flag:
# objName = "MySpecialName"
# self.setObjectName(objName)
# cmds.MGPickerUserPanel(self.dockWgtId, e=True, installWidget=objName)
# Refresh UI:
self.updateOnDocChanged()
self.updateUIModeChanged()
self.updateOnUILangChanged()
# Install callbacks so the UI refresh on these MG-Picker events:
mgp.CallbackManager.registerCallback(mgp.Event.CurrentDocChanged, "test", self.updateOnDocChanged)
mgp.CallbackManager.registerCallback(mgp.Event.UiModeChanged, "test", self.updateUIModeChanged)
mgp.CallbackManager.registerCallback(mgp.Event.UiLanguageChanged, "test", self.updateOnUILangChanged)
def updateOnDocChanged(self):
view = mgp.MGPicker(q=True, activePickerView=True)
if not view:
self.currentDocBtn.setText("N/A")
else:
ns = mgp.MGPickerView(view, q=True, namespace=True) or "N/A"
self.currentDocBtn.setText("NS: {}".format(ns))
def updateUIModeChanged(self):
mode = mgp.MGPicker(q=True, pickerMode=True)
self.uiModeBtn.setText("Animator Mode" if mode else "Designer Mode")
def updateOnUILangChanged(self):
lang = mgp.MGPicker(q=True, config=("language", ""))
self.uiLangBtn.setText("Language: {}".format(lang))
wgt = UserPanelExample()
|