Skip to content

UIUtils


=== Author: Assaf Ben Zur ===
UI Utility function assembly.
This module holds all UI utility functions as well s any QT dynamic draw functions.
All UI functions should be held in here for multi-usage of the same UI draw functions.
This module also holds the QT ui dynamic conversion to '.py' and the 'get_maya_window' function.


Classes


CollapsibleFrameWidget [Class]

Collapsible frame Widget class.
This is a wrapper widget that allows for a collapisble frame to be built.
The QFrame object will allow for Layouts to be inserted into the Collapsible frame, inserting any widgets within it,
collapsing and expanding it by a click trigger (from the user).

Constructor: CollapsibleFrameWidget(parent(str) ; [default: None],title(str) ; [default: None])
Inherits from: QFrame
Class Members:
    • _is_collasped
    • _title_frame
    • _content
    • _main_v_layout
    • clickedSignal
Methods:

CollapsibleFrameWidget methods


initCollapsable [CollapsibleFrameWidget class method]
Constructor: initCollapsable(self)
Return: None
Arguments:
  • self
Optional Arguments:
toggleCollapsed [CollapsibleFrameWidget class method]
Constructor: toggleCollapsed(self)
Return: None
Arguments:
  • self
Optional Arguments:
setArrow [CollapsibleFrameWidget class method]
Constructor: setArrow(self, arrow_dir)
Return: None
Arguments:
  • self
  • arrow_dir
Optional Arguments:
initArrow [CollapsibleFrameWidget class method]
Constructor: initArrow(self, collapsed)
Return: None
Arguments:
  • self
  • collapsed
Optional Arguments:
initContent [CollapsibleFrameWidget class method]
Constructor: initContent(self, collapsed)
Return: None
Arguments:
  • self
  • collapsed
Optional Arguments:
initTitleFrame [CollapsibleFrameWidget class method]
Constructor: initTitleFrame(self, title, collapsed)
Return: None
Arguments:
  • self
  • title
  • collapsed
Optional Arguments:
addWidget [CollapsibleFrameWidget class method]
Constructor: addWidget(self, widget)
Return: None
Arguments:
  • self
  • widget
Optional Arguments:

MnsAbout [Class]

Mansur - About dialog

Constructor: MnsAbout(parent(str) ; [default: get_maya_window()],version(str) ; [default: "dev"])
Inherits from: QtWidgets.QDialog
Class Members:
    • iconsDir
    • versionDisplay
    • close_btn

extraChannelsDelegate [Class]

Constructor: extraChannelsDelegate(parent(str) ; [default: None],*args)
Inherits from: QtWidgets.QItemDelegate
Class Members:
Methods:

extraChannelsDelegate methods


setModelData [extraChannelsDelegate class method]
Constructor: setModelData(self, editor, model, index)
Return: None
Arguments:
  • self
  • editor
  • model
  • index
Optional Arguments:
createEditor [extraChannelsDelegate class method]
Constructor: createEditor(self, parent, option, index)
Return: None
Arguments:
  • self
  • parent
  • option
  • index
Optional Arguments:

Defenitions


acquireExternalWindow

A simple method to acquire an external QT window, into an actual PyQt MianWindow object.

Constructor: acquireExternalWindow(UIName = None)
Return: QMainWindow (UI Class)
Arguments:
  • UIName(str) ; [default: None]
Keyword Arguments:

buildFormBaseClassForUI

Constructor: buildFormBaseClassForUI(script_dir, rel_path)
Return: baseClass, formClass
Arguments:
  • script_dir
  • rel_path
Keyword Arguments:

buildStackedTabForModuleParentDir

Main BLOCK dynamiuc tab builder.
Builds a tab for a given tab parent including all the neccesary layouts within, returning the main layout that can be inserted with new q items.

Constructor: buildStackedTabForModuleParentDir(modDirName, insertIndex, tabWidget, kwargs)
Return: None
Arguments:
  • modDirName
  • insertIndex
  • tabWidget
  • kwargs
Keyword Arguments:

buildTabForModuleParentDir

Main BLOCK dynamiuc tab builder.
Builds a tab for a given tab parent including all the neccesary layouts within, returning the main layout that can be inserted with new q items.

Constructor: buildTabForModuleParentDir(modDirName, insertIndex, tabWidget, kwargs)
Return: None
Arguments:
  • modDirName
  • insertIndex
  • tabWidget
  • kwargs
Keyword Arguments:

checkChannelCommand

DynUI 'channel control' checkBox changed command trigger.

Constructor: checkChannelCommand(chanBtn,chanCbxs)
Return: None
Arguments:
  • chanBtn
  • chanCbxs
Keyword Arguments:

colOverrideBlockDefTriggerCommand

DynUI color-override default command trigger.

Constructor: colOverrideBlockDefTriggerCommand(colorOverrideCbx, sideCB, ovverideBtnList)
Return: None
Arguments:
  • colorOverrideCbx
  • sideCB
  • ovverideBtnList
Keyword Arguments:

colOverrideStateChange

DynUI color-override changed command trigger.

Constructor: colOverrideStateChange(colorOverrideCbx, sideCB, ovverideBtnList)
Return: None
Arguments:
  • colorOverrideCbx
  • sideCB
  • ovverideBtnList
Keyword Arguments:

convertRelativePathToAbs

A method for replacing a projectRoot variable within a relative path to the absolute path
Based on the current project directory

Constructor: convertRelativePathToAbs(filePath = "")
Return: string
Arguments:
  • filePath(str) ; [default: ""]
Keyword Arguments:

createAboutWindow

Load about dialog

Constructor: createAboutWindow()
Return: None
Arguments:
Keyword Arguments:

createTextSeparator

Constructor: createTextSeparator(label = "", QMenuItem = None, parent = get_maya_window())
Return: None
Arguments:
  • label(str) ; [default: ""]
  • QMenuItem(str) ; [default: None]
  • parent(str) ; [default: get_maya_window()]
Keyword Arguments:

customScriptsAddCommand

Add button trigger command for "custom scripts" slot of synamic UI.

Constructor: customScriptsAddCommand(listWidget)
Return: None
Arguments:
  • listWidget
Keyword Arguments:

customScriptsDefaultCommand

Default trigger command for 'custom scripts' slot in dynUI.

Constructor: customScriptsDefaultCommand(listWidget, MnsArgumentObj)
Return: None
Arguments:
  • listWidget
  • MnsArgumentObj
Keyword Arguments:

customScriptsRemoveCommand

Remove button trigger command for "custom scripts" slot of synamic UI.

Constructor: customScriptsRemoveCommand(listWidget)
Return: None
Arguments:
  • listWidget
Keyword Arguments:

deleteAllLayoutItems

A method to delete all widgets/object from a given layout

Constructor: deleteAllLayoutItems(layout, kwargs)
Return: None
Arguments:
  • layout
  • kwargs
Keyword Arguments:

drawBooleanChk

Main dynamic check-box UI draw.
Creates a simple boolean check-box (QCheckBox) as well as a connected 'default' button.

Constructor: drawBooleanChk(MnsArgumentObj, layoutParent)
Return: QCheckBox
Arguments:
  • MnsArgumentObj
  • layoutParent
Keyword Arguments:

drawButtonAndField

Main dynamic 'button and field' draw.
Draws a deault button, text field and an 'Insert items from scene' button into the given parent layout.
This function makes all relevant connections between the QItems created-
- 'Load command' from the QPushButton (insert) to the text field
- 'Clear' trigger for the text field.
- 'Set default' from the QPushButton 'default' to the text field.
These connections are made within in order the return the QLEdit only, with no need to worrie about the 'functionallity' buttons created, only the value within the text field.

Constructor: drawButtonAndField(MnsArgumentObj, layoutParent, alphaLimit = False)
Return: QLEdit
Arguments:
  • MnsArgumentObj
  • layoutParent
  • alphaLimit(bool) ; [default: False]
Keyword Arguments:

drawButtonAndFieldUnknown

Main 'unknown' button and field UI draw.
In case the MnsArgument.type in question is an unknown type, draw a button and field style item for it.

Constructor: drawButtonAndFieldUnknown(MnsArgumentObj, layoutParent)
Return: QLEdit
Arguments:
  • MnsArgumentObj
  • layoutParent
Keyword Arguments:

drawChannelColumnAndConnect

Draw channel column (part of channel control) into a DynUI.

Constructor: drawChannelColumnAndConnect(MnsArgumentObj, channel, kwargs)
Return: QVBoxLayout (layout), list (drawen boxes)
Arguments:
  • MnsArgumentObj
  • channel
  • kwargs
Keyword Arguments:

drawChannelControl

Draw the predefined channel-control slot into a DynUI.

Constructor: drawChannelControl(MnsArgumentObj, layoutParent, kwargs)
Return: list (all channel cbxs)
Arguments:
  • MnsArgumentObj
  • layoutParent
  • kwargs
Keyword Arguments:

drawColorBox

Main dynamic 'draw color box' creation function.
Will create a new QPushButton with its 'color picker' style display and inserts it into the given layoutParent.
An automatic connection to the 'getColor' function is made, as well as a 'default' button creation and connection is made.

Constructor: drawColorBox(MnsArgumentObj, layoutParent)
Return: QPushButton
Arguments:
  • MnsArgumentObj
  • layoutParent
Keyword Arguments:

drawColorBtnAndConnect

Constructor: drawColorBtnAndConnect(default, kwargs)
Return: QPushButton
Arguments:
  • default
  • kwargs
Keyword Arguments:
  • buttonSize(int) ; [default: 25]
  • colOverrideCbx(str) ; [default: None]

drawColorScheme

Main block 'draw color scheme box' creation function.
Will create a new QPushButton series with 'color picker's style display and inserts it into the given layoutParent.
An automatic connection to the 'getColor' function is made, as well as a 'default' button creation and connection is made.

Constructor: drawColorScheme(MnsArgumentObj, layoutParent)
Return: list
Arguments:
  • MnsArgumentObj
  • layoutParent
Keyword Arguments:

drawColorSchemeOverride

Draw the predefined 'color scheme' slot into a dynUI.

Constructor: drawColorSchemeOverride(MnsArgumentObj, layoutParent, kwargs)
Return: list
Arguments:
  • MnsArgumentObj
  • layoutParent
  • kwargs
Keyword Arguments:
  • sideCB(str) ; [default: None]
  • colOverride(bool)
  • rigTop(str) ; [default: None]

drawCustomScriptsSlot

draw a "custom scripts" slot into dyn UI.

Constructor: drawCustomScriptsSlot(MnsArgumentObj, layoutParent)
Return: QListWidget
Arguments:
  • MnsArgumentObj
  • layoutParent
Keyword Arguments:

drawExtraChannelsBox

Main dynamic 'draw blend shape targets box' creation function.

Constructor: drawExtraChannelsBox(MnsArgumentObj, layoutParent)
Return: QTreeWidget
Arguments:
  • MnsArgumentObj
  • layoutParent
Keyword Arguments:

drawFloatScroll

Main dynamic "Float spinner" UI draw
Creates a Float QDoubleSpinBox widget, and a default button connected to it.

Constructor: drawFloatScroll(MnsArgumentObj, layoutParent)
Return: QDoubleSpinBox
Arguments:
  • MnsArgumentObj
  • layoutParent
Keyword Arguments:

drawHorizontalDevider

Draw a simple Horizontal devider into the dynUI.

Constructor: drawHorizontalDevider(MnsArgumentObj, layoutParent)
Return: QFrame (Horizontal line devider)
Arguments:
  • MnsArgumentObj
  • layoutParent
Keyword Arguments:

drawIntSpinner

Main dynamic 'int field' field and spinner UI draw.
Creates an int QSpinBox widget, and a default button connected to it.

Constructor: drawIntSpinner(MnsArgumentObj, layoutParent)
Return: QSpinBox
Arguments:
  • MnsArgumentObj
  • layoutParent
Keyword Arguments:

drawJntStructMemberCol

Constructor: drawJntStructMemberCol(layout = None, argument = None)
Return: None
Arguments:
  • layout(str) ; [default: None]
  • argument(str) ; [default: None]
Keyword Arguments:

drawModuleButton

Main BLOCK dynamic build module buttom function draw.
Builds a new QPushButoon for a given module, return the QPushButton created after connecting it to the given 'connectFunction'.
The QPush buttom created will then to be inserted into a layout by the caller function.

Constructor: drawModuleButton(MnsBuildModuleObj, connectFunction)
Return: QPushButton
Arguments:
  • MnsBuildModuleObj
  • connectFunction
Keyword Arguments:

drawOptionBox

Main dynamic 'option box' draw.
Drawing a new ob based on parameters within the MnsArgument object passed in.
The QComboBox is inserted into the parent layout passed in.
A default button and connection is made.

Constructor: drawOptionBox(MnsArgumentObj, layoutParent)
Return: QComboBox
Arguments:
  • MnsArgumentObj
  • layoutParent
Keyword Arguments:

drawPathField

Main Path row draw

Constructor: drawPathField(MnsArgumentObj, layoutParent)
Return: QLEdit
Arguments:
  • MnsArgumentObj
  • layoutParent
Keyword Arguments:

drawPrimaryButton

Picker method- draw a generic picker button.

Constructor: drawPrimaryButton(plg, tabWidget, pickerBase, picker)
Return: None
Arguments:
  • plg
  • tabWidget
  • pickerBase
  • picker
Keyword Arguments:

drawSpacesBox

Main dynamic 'draw spaces box' creation function.

Constructor: drawSpacesBox(MnsArgumentObj, layoutParent, kwargs)
Return: QListWidget
Arguments:
  • MnsArgumentObj
  • layoutParent
  • kwargs
Keyword Arguments:

dynUIExtraChannelsMenu

Constructor: dynUIExtraChannelsMenu(treeWG, position)
Return: None
Arguments:
  • treeWG
  • position
Keyword Arguments:

extraChannelsAddDivider

Constructor: extraChannelsAddDivider(treeWG, kwargs)
Return: None
Arguments:
  • treeWG
  • kwargs
Keyword Arguments:

extraChannelsAddRow

Constructor: extraChannelsAddRow(treeWG, kwargs)
Return: None
Arguments:
  • treeWG
  • kwargs
Keyword Arguments:

extraChannelsChangeDirection

Constructor: extraChannelsChangeDirection(treeWG, direction = 1)
Return: None
Arguments:
  • treeWG
  • direction(int) ; [default: 1]
Keyword Arguments:

extraChannelsDuplicateRows

Constructor: extraChannelsDuplicateRows(treeWG, kwargs)
Return: None
Arguments:
  • treeWG
  • kwargs
Keyword Arguments:

extraChannelsEdit

Constructor: extraChannelsEdit(item, col)
Return: None
Arguments:
  • item
  • col
Keyword Arguments:

extraChannelsLoadCBSel

Constructor: extraChannelsLoadCBSel(treeWG)
Return: None
Arguments:
  • treeWG
Keyword Arguments:

extraChannelsMoveItemsDown

Constructor: extraChannelsMoveItemsDown(treeWG)
Return: None
Arguments:
  • treeWG
Keyword Arguments:

extraChannelsMoveItemsUp

Constructor: extraChannelsMoveItemsUp(treeWG)
Return: None
Arguments:
  • treeWG
Keyword Arguments:

extraChannelsRemoveSelected

Constructor: extraChannelsRemoveSelected(treeWG)
Return: None
Arguments:
  • treeWG
Keyword Arguments:

extraChannelsValidateCurrentData

Constructor: extraChannelsValidateCurrentData(treeWG)
Return: None
Arguments:
  • treeWG
Keyword Arguments:

getColor

Simple 'get color for a color PButton'.
Creates a new QColorDialog asking the user for a color choice.
When color selected sets the caller QPushButton color to the selected color

Constructor: getColor(btn, kwargs)
Return: tuple[3] (color)
Arguments:
  • btn
  • kwargs
Keyword Arguments:
  • colOverrideCbx(str) ; [default: None]

getColorArrayFromColorScheme

Collect a normalized array of colors from a 'colorSceheme' enum attribute.

Constructor: getColorArrayFromColorScheme(side, colorScheme)
Return: list (color sceheme)
Arguments:
  • side
  • colorScheme
Keyword Arguments:

getEulaText

get the most recent eula.

Constructor: getEulaText()
Return: None
Arguments:
Keyword Arguments:

getObjectScreenSpaceByFilmGate

This method is used to 'project' a plg into the projection camera's film gate.
Get the relative position of the plg to the camera film-gate's top left corener.

Constructor: getObjectScreenSpaceByFilmGate(objectProj, cam)
Return: float, float (posX, posY)
Arguments:
  • objectProj
  • cam
Keyword Arguments:

getPathCommand

Dyn UI path slot 'get path' command trigger.

Constructor: getPathCommand(LEdit, mode = 0, fileTypes = [])
Return: None
Arguments:
  • LEdit
  • mode(int) ; [default: 0]
  • fileTypes(list) ; [default: []]
Keyword Arguments:

getPlgPosition

Get the relative position of the requested plg, based on the 'Picker Layout Base' Guide top left corner.
Return the local bounding box size as well.

Constructor: getPlgPosition(plg, pickerBase)
Return: float,float,float,float (posX,PosY,Width,Height)
Arguments:
  • plg
  • pickerBase
Keyword Arguments:

getWindow

Constructor: getWindow(windowName = "")
Return: None
Arguments:
  • windowName(str) ; [default: ""]
Keyword Arguments:

get_maya_window

Main maya window get for a global UI parent

Constructor: get_maya_window()
Return: qtWindow (main maya window as a qt window)
Arguments:
Keyword Arguments:

listLoadCmd

Load to list command trigger (dynUI)

Constructor: listLoadCmd(QListWidget)
Return: None
Arguments:
  • QListWidget
Keyword Arguments:

listRemoveCommand

Remove from list command trigger (dynUI)

Constructor: listRemoveCommand(QListWidget)
Return: None
Arguments:
  • QListWidget
Keyword Arguments:

loadCmd

Main text field 'load from scene' trigger command.
This command will update the given QLEdit with members of the maya scene when triggered.
Three main cases:
1. Nothing is selected - if the field is empty- do nothing, else clear the field.
2. objects are selected, without any CB selection - load the object names in, seperated by commas.
3. Objects are selected and there is a CB selection as well - load all objects and chnnels in a 'object.channel' format, seperated by commas.

Constructor: loadCmd(LEdit)
Return: None
Arguments:
  • LEdit
Keyword Arguments:

load_ui_type

This function converts a '.ui' file into a '.py' file live.
This means that all UI's are derived from a QT designer ui files that are converted directly to form the UI.
This keeps a live connection between the '.ui' file and the actul UI in maya. Meaning that any edit or a change to the UI base needs to be done only from the QT designer, without any further action by the user.
It reruns a baseClass and a formClass to be used when creating any UI.

Constructor: load_ui_type(ui_file)
Return: baseClass, formClass
Arguments:
  • ui_file
Keyword Arguments:

optionBoxTextTrigger

Constructor: optionBoxTextTrigger(comboBox = None, lineWditWidget = None, index = 0)
Return: None
Arguments:
  • comboBox(str) ; [default: None]
  • lineWditWidget(str) ; [default: None]
  • index(int) ; [default: 0]
Keyword Arguments:

recDeleteAllLayoutItems

A method to delete all widgets/object from a given layout

Constructor: recDeleteAllLayoutItems(layout, kwargs)
Return: None
Arguments:
  • layout
  • kwargs
Keyword Arguments:

relativePathCheck

A method for checking if any file path can be converted to a relative path.
If relative path is available, promt a message asking the user if he want to convert.
if so, convert and return.

Constructor: relativePathCheck(filePath = "")
Return: string
Arguments:
  • filePath(str) ; [default: ""]
Keyword Arguments:

reloadWindow

Constructor: reloadWindow(windowName = "")
Return: None
Arguments:
  • windowName(str) ; [default: ""]
Keyword Arguments:

setBooleanDefaultCmd

'Set default' trigger for a QCheckBox item.

Constructor: setBooleanDefaultCmd(cbx,default)
Return: None
Arguments:
  • cbx
  • default
Keyword Arguments:

setChennelControlDefaultCmd

DynUI chennel control slot default command trigger.

Constructor: setChennelControlDefaultCmd(cbxList, MnsArgumentObj)
Return: None
Arguments:
  • cbxList
  • MnsArgumentObj
Keyword Arguments:

setColorDefaultCmd

A 'set color back to default command.
A command to be triggered by an outside 'default' button, or when initializing to set the specified QPushButton color back to it's default value.

Constructor: setColorDefaultCmd(btn, colorDef)
Return: None
Arguments:
  • btn
  • colorDef
Keyword Arguments:

setColorSchemeDefaultCmd

DynUI color-scheme default command trigger.

Constructor: setColorSchemeDefaultCmd(btnList, default)
Return: None
Arguments:
  • btnList
  • default
Keyword Arguments:

setFloatDefaultCmd

'Set default' trigger for a QDoubleSpinBox item.

Constructor: setFloatDefaultCmd(spinner,default)
Return: None
Arguments:
  • spinner
  • default
Keyword Arguments:

setIntDefaultCmd

'Set deafult' command trigget for an int QSpinBox.

Constructor: setIntDefaultCmd(spinner,default)
Return: None
Arguments:
  • spinner
  • default
Keyword Arguments:

setIntIncrement

Constructor: setIntIncrement(spinner, increment, start)
Return: None
Arguments:
  • spinner
  • increment
  • start
Keyword Arguments:

setLinkToQLabel

Constructor: setLinkToQLabel(labelObj = None, ahref = "")
Return: None
Arguments:
  • labelObj(str) ; [default: None]
  • ahref(str) ; [default: ""]
Keyword Arguments:

setListWidgetDefaultCommand

'Default' command trigger for a 'list' type synamic row (dynUI)

Constructor: setListWidgetDefaultCommand(QListWidget, default)
Return: None
Arguments:
  • QListWidget
  • default
Keyword Arguments:

setOtionBoxDefaultCmd

A 'set default' command to be triggered for a combo box item.

Constructor: setOtionBoxDefaultCmd(cbox, default)
Return: None
Arguments:
  • cbox
  • default
Keyword Arguments:

setSpaceDefault

Constructor: setSpaceDefault(listWG, kwargs)
Return: None
Arguments:
  • listWG
  • kwargs
Keyword Arguments:

setStringDefaultCmd

'Set default' command trigger from a text field

Constructor: setStringDefaultCmd(LEdit,default)
Return: None
Arguments:
  • LEdit
  • default
Keyword Arguments:

sideCBChangedTriggerCommand

DynUI side combo box changed command trigger.

Constructor: sideCBChangedTriggerCommand(colorOverrideCbx, sideCB, ovverideBtnList, rigTop, ignoreOvverideCheckbox = False)
Return: None
Arguments:
  • colorOverrideCbx
  • sideCB
  • ovverideBtnList
  • rigTop
  • ignoreOvverideCheckbox(bool) ; [default: False]
Keyword Arguments:

tearOffWindow

Create a new maya 'tear-off' panel.

Constructor: tearOffWindow(name, title, width, height, cameraToView)
Return: pymel.core.window (tear-off window)
Arguments:
  • name
  • title
  • width
  • height
  • cameraToView
Keyword Arguments:

toQtObject

Convert a maya UI component into a QT object

Constructor: toQtObject(mayaName, kwargs)
Return: None
Arguments:
  • mayaName
  • kwargs
Keyword Arguments: