Qt helper library

Module documentation

mlib.core.qt.loadUiFile(ui_path, appname=None, manage_settings=True)[view]

Load a designer UI xml file in

Parameters:ui_path (str) – Path to UI file. ui_path be a partial path relative to the file calling loadUiFile(). It is also not necessary to include the .ui extension.
Returns:Window Class defined by the input UI file
class mlib.core.qt.DesignerForm(parent=None)[view]

Bases: object

Base class for widgets loaded with loadUiType. This class provides convenience functions, and manages a few of the more specific features of the loadUiFile function.

showEvent(event)[view]
closeEvent(event)[view]
close()[view]

Slight tweak to the default close function, cleans up the window to avoid memory leaking.

setUnmanagedWidgets(widgets)

Set a new list of managed widgets

Parameters:widgets (list of QObjects or objectName’s) – Widgets to not manage
getUnmanagedWidgets()
saveSettings(ignore=None)[view]
Parameters:ignore
loadSettings(ignore=None)[view]
Parameters:ignore
resetSettings(ignore=None, skipGeometry=False, skipWindowState=False)[view]

Reset the window to it’s “initial” state from when the UI for was loaded

Parameters:
  • ignore
  • skipGeometry
  • skipWindowState
saveWindowState()[view]

Save position/size of window

loadWindowState()[view]

Load position/size of window

classmethod setAppName(appname)
classmethod getAppName()
classmethod setUiPath(path)
classmethod getUiPath()
classmethod setSettingsManaged(state)
classmethod getSettingsManaged()
classmethod showUI(*args, **kwargs)[view]

Show a single instance of this form class, closes any previous instances regardless of reloads All arguments pass through to the base class.

classmethod closeUI()[view]

Close the visible instance of this form class

classmethod getVisibleInstance(create=False)[view]

Get the visible instance of this form class. If create is True, and this window does not already exists, it will return the result of showUI with no arguments.

Parameters:create (bool) – Create this ui if none exists
Returns:The visible instance if one exists
Return type:DesignerForm or None
mlib.core.qt.getFocusWidget()[view]

Get the currently focused widget

Returns:Widget with focus currently
Return type:QtGui.QWidget or None
mlib.core.qt.getWidgetAtMouse()[view]

Get the widget under the mouse

Returns:QtGui.QWidget or None
mlib.core.qt.qrcToPythonRc(path, target)[view]

Given a path to a qrc file, create the target file This also tries to checkout the file from perforce if it can.

Parameters:
  • path (str) – Qrc file path to compile
  • target (str) – Target path for compiled python RC file
mlib.core.qt.wrapinstance(ptr, base=None)[view]

Utility to convert a pointer to a Qt class instance

Parameters:
  • ptr (long or Swig instance) – Pointer to QObject in memory
  • base (QtGui.QWidget) – (Optional) Base class to wrap with (Defaults to QObject, which should handle anything)
Returns:

QWidget or subclass instance

Return type:

QtGui.QWidget

mlib.core.qt.unwrapinstance(obj)[view]

Utility to convert a Qt class instance to a pointer

Parameters:obj (Qt Object) – Object to unwrap
Returns:Unwrapped instance pointer
Return type:long
mlib.core.qt.isValid(widget)[view]

Check if a widget is valid in the backend

Parameters:widget – QtGui.QWidget
Returns:True if the widget still has a c++ object
Return type:bool
mlib.core.qt.closeAndCleanup(widget)[view]

Call close and deleteLater on a widget safely.

Note

Skips the close call if the widget is already not visible.

Parameters:widget (QtGui.QWidget) – Widget to close and delete
mlib.core.qt.getSettings(appName, unique=False, version=None)[view]

Helper to get a settings object for a given app-name It uses INI settings format for Maya, and registry format for stand-alone tools. Try to ensure that the appName provided is unique, as overlapping appNames will try to load/overwrite each others settings file/registry data.

Parameters:appName – string – Application name to use when creating qtSettings ini file/registry entry.
Returns:QtCore.QSettings – Settings object
mlib.core.qt.saveLoadSettings(widget, ignore=None, save=True, windowStateOnly=False, skipGeometry=False, skipWindowState=None, settings=None)[view]

Save/Load state for a widget and it’s sub-widgets

Parameters:
  • widget (QtGui.QWidget) – Widget to save/load state for
  • ignore (list) – widgets to ignore
  • save (bool) – Save if True, load if False
  • windowStateOnly (bool) – Save/Load window state only?
  • skipGeometry (bool) – Skip geometry when saving/loading?
  • settings (QSettings or InitialSettings) – Optional QSettings object to save/load from instead of the default
mlib.core.qt.saveLoadState(settings, widget, key=None, save=True)[view]

How to store/load state for a number of widget types

Parameters:
  • settings (QtCore.QSettings) – settings object to use
  • widget (QtGui.QWidget) – widget to save
  • key (str) – (Optional) key to save it as, uses objectName if None
  • save (bool) – Save if True, Load if False
mlib.core.qt.pathToWidget(mayaName)

Given the name of a Maya UI element of any type, return the corresponding QWidget or QAction. If the object does not exist, returns None

Parameters:mayaName (str) – Maya name to get a Qt widget for
Returns:Widget Object
Return type:QtCore.QWidget
mlib.core.qt.getMayaWindow()[view]

Get the maya main window as a QMainWindow instance

Returns:MainWindow instance
Return type:QtGui.QMainWindow
mlib.core.qt.widgetToPath(widget)

Return the maya full ui path to the given Qt widget

Parameters:widget (QtGui.QWiget or QtCore.QObject) – Qt widget to get a Maya path for if possible
Returns:Maya UI path, or None
Return type:str
mlib.core.qt.getParentWidget(widget)[view]

Take a given QWidget and return it’s Maya UI parent

Parameters:widget (QtGui.QWidget) – widget to get parent for
Returns:Parent widget or None
Return type:QtGui.QWidget
class mlib.core.qt.InitialSettings(*args)[view]

Bases: dict

A python dictionary with a similar API to QSettings in order to store
a backup of the initial form settings when using loadUiFile
getGroupKey(key)[view]
setValue(key, value)[view]
value(key, default=None)[view]
contains(key)[view]
beginGroup(groupName)[view]
endGroup()[view]
group()[view]
class mlib.core.qt.BaseCallback(func, *args, **kwargs)

Bases: object

Callback object similar to functools.partial. It bakes arguments at creation time and makes itself callable.

class mlib.core.qt.Callback(func, *args, **kwargs)

Bases: mlib.core.qt.BaseCallback

classmethod callbackStack()
mlib.core.qt.undoable(func)

Make the decorated function undoable in Maya using a Callback

Parameters:func (callable) – function to decorate
Returns:Wrapper Callback
Return type:Callback
mlib.core.qt.notundoable(func)

Make the decorated function not undoable in Maya using a Callback

Parameters:func (callable) – Decorated function
Returns:Wrapper Callback
Return type:Callback

Table Of Contents

Previous topic

MLib Maya/Python tools and Library

Next topic

Misc helper library

This Page