Exemple #1
0
 def floating(self):
     """Return if the window is floating."""
     if not self.dockable():
         return False
     if self._Pre2017:
         return pm.dockControl(self.WindowID, query=True, floating=True)
     return pm.workspaceControl(self.WindowID, query=True, floating=True)
def getDock(name='LightingManagerDock'):
    """
    This function creates a dock with the given name.
    It's an example of how we can mix Maya's UI elements with Qt elements
    Args:
        name: The name of the dock to create

    Returns:
        QtWidget.QWidget: The dock's widget
    """
    # First lets delete any conflicting docks
    deleteDock(name)
    # Then we create a workspaceControl dock using Maya's UI tools
    # This gives us back the name of the dock created
    ctrl = pm.workspaceControl(name,
                               dockToMainWindow=('right', 1),
                               label="Lighting Manager")

    # We can use the OpenMayaUI API to get the actual Qt widget associated with the name
    qtCtrl = omui.MQtUtil_findControl(ctrl)

    # Finally we use wrapInstance to convert it to something Python can understand, in this case a QWidget
    ptr = wrapInstance(long(qtCtrl), QtWidgets.QWidget)

    # And we return that QWidget back to whoever wants it.
    return ptr
Exemple #3
0
 def hide(self):
     """Hide the window."""
     if self.dockable():
         if MAYA_VERSION < 2017:
             return pm.dockControl(self.WindowID, edit=True, visible=False)
         return pm.workspaceControl(self.WindowID, edit=True, visible=False)
     return super(MayaWindow, self).hide()
Exemple #4
0
def getDock(name='CoutureDock'):
    """
    Get the ptr to a dockable location for Couture
    @param name: str, name of the Couture dockable window
    @return ptr: ptr the dock windows newly created
    """

    deleteDock(name)

    if maya_api_version() < MAYA2017:
        ctrl = pm.dockControl(name,
                              area='right',
                              content='Couture',
                              allowedArea='all',
                              label="Couture tool",
                              vis=True,
                              r=True)
        print "do ctrl"

        # And then we return the control name
        return ctrl

    else:
        # ctrl = pm.workspaceControl(name, dockToMainWindow=('right', 1), label="Couture tool")
        ctrl = pm.workspaceControl(name,
                                   dockToMainWindow=('right', 1),
                                   label="Couture tool",
                                   loadImmediately=True,
                                   vis=True,
                                   r=True)
        qtCtrl = omui.MQtUtil_findControl(ctrl)
        ptr = wrapInstance(long(qtCtrl), QtWidgets.QWidget)

        return ptr
Exemple #5
0
def deleteDock(name='ProceduralRiggingTool'):
    """
    delete the Dock
    :param name: Dock name
    :return: None
    """
    if pm.workspaceControl(name, query=1, exists=1):
        pm.deleteUI(name)
Exemple #6
0
def showDialog(dialog, dInst=True, dockable=False, *args):
    """
    Show the defined dialog window

    Attributes:
        dialog (QDialog): The window to show.

    """
    if dInst:
        try:
            for c in maya_main_window().children():
                if isinstance(c, dialog):
                    c.deleteLater()
        except Exception:
            pass

    # Create minimal dialog object

    # if versions.current() >= 20180000:
    #     windw = dialog(maya_main_window())
    # else:
    windw = dialog()

    # ensure clean workspace name
    if hasattr(windw, "toolName") and dockable:
        control = windw.toolName + "WorkspaceControl"
        if pm.workspaceControl(control, q=True, exists=True):
            pm.workspaceControl(control, e=True, close=True)
            pm.deleteUI(control, control=True)
    desktop = QtWidgets.QApplication.desktop()
    screen = desktop.screen()
    screen_center = screen.rect().center()
    windw_center = windw.rect().center()
    windw.move(screen_center - windw_center)

    # Delete the UI if errors occur to avoid causing winEvent
    # and event errors (in Maya 2014)
    try:
        if dockable:
            windw.show(dockable=True)
        else:
            windw.show()
        return windw
    except Exception:
        windw.deleteLater()
        traceback.print_exc()
Exemple #7
0
def getDock(name='LightingManagerDock'):
    deleteDock(name)
    ctrl = pm.workspaceControl(name,
                               dockToMainWindow=('right', 1),
                               label="Lighting Manager")
    qtCtrl = omui.MQtUtil_findControl(ctrl)
    ptr = wrapInstance(long(qtCtrl), QtWidgets.QWidget)
    return ptr
Exemple #8
0
 def hide(self):
     """Hide the window."""
     if self.dockable():
         if MAYA_VERSION < 2017:
             return pm.dockControl(self.WindowID, edit=True, visible=False)
         self.parent().setAttribute(QtCore.Qt.WA_DeleteOnClose, False)
         return pm.workspaceControl(self.WindowID, edit=True, visible=False)
     return super(MayaWindow, self).hide()
def getDock(name='poseLibraryDock'):
    deleteDock(name)
    ctrl = pm.workspaceControl(name,
                               ttc=("AttributeEditor", -1),
                               label='Pose Library')
    qtCtrl = omui.MQtUtil_findControl(ctrl)
    pointer = wrapInstance(long(qtCtrl), QtWidgets.QWidget)
    return pointer
Exemple #10
0
def deleteDock(name='LightingManagerDock'):
    """
    A simple function to delete the given dock
    Args:
        name: the name of the dock
    """
    if pm.workspaceControl(name, query=True, exists=True):
        pm.deleteUI(name)
Exemple #11
0
 def isVisible(self):
     if self.dockable():
         try:
             if self._Pre2017:
                 return pm.dockControl(self.WindowID, query=True, visible=True)
             return pm.workspaceControl(self.WindowID, query=True, visible=True)
         except RuntimeError:
             return False
     return super(MayaWindow, self).isVisible()
Exemple #12
0
 def setWindowTitle(self, title):
     if self.dockable():
         try:
             if self._Pre2017:
                 return pm.dockControl(self.WindowID, edit=True, label=title)
             return pm.workspaceControl(self.WindowID, edit=True, label=title)
         except RuntimeError:
             pass
     return super(MayaWindow, self).setWindowTitle(title)
Exemple #13
0
    def __init__(self, widgetCls=None, label=None):
        self.widgetCls = widgetCls
        self.name = self.widgetCls.__name__
        if not label == None or not len(label):
            self.label = getattr(self.widgetCls, "label", self.name)
        else:
            self.label = label

        if not pm.workspaceControl(self.name, q=True, ex=True):
            dockControl = pm.workspaceControl(self.name, label=self.label)
        else:
            dockControl = self.name

        dockPtr = omui.MQtUtil.findControl(dockControl)
        self.dockWidget = wrapInstance(long(dockPtr), QtWidgets.QWidget)
        self.dockWidget.setAttribute(QtCore.Qt.WA_DeleteOnClose)

        self.createWidget()
    def mayaShow(self, name="MF_AVG_NORMAL"):
        # NOTE 如果变量存在 就检查窗口多开
        try:
            if pm.workspaceControl(name, q=1, ex=1):
                pm.deleteUI(name)
            window = pm.workspaceControl(name, label=self.windowTitle())
        except:
            if pm.window(name, q=1, ex=1):
                pm.deleteUI(name)
            window = pm.window(name, label=self.windowTitle())

        pm.showWindow(window)
        # NOTE 将Maya窗口转换成 Qt 组件
        ptr = self.mayaToQT(window)
        ptr.setLayout(QtWidgets.QVBoxLayout())
        ptr.layout().setContentsMargins(0, 0, 0, 0)
        ptr.layout().addWidget(self)
        return ptr
def deleteDock(name='LightingManagerDock'):
    """
    A simple function to delete the given dock
    Args:
        name: the name of the dock
    """
    # We use the workspaceControl to see if the dock exists
    if pm.workspaceControl(name, query=True, exists=True):
        # If it does we delete it
        pm.deleteUI(name)
Exemple #16
0
def add_widget_to_layout(widget, control_name):
    if pm.workspaceControl(control_name, q=1, ex=1):
        if os.sys.version_info[0] >= 3:
            workspaceControlPtr = int(pma.MQtUtil.findControl(control_name))
            widgetPtr = int(getCppPointer(widget)[0])
        else:
            workspaceControlPtr = long(pma.MQtUtil.findControl(control_name))
            widgetPtr = long(getCppPointer(widget)[0])

        pma.MQtUtil.addWidgetToMayaLayout(widgetPtr, workspaceControlPtr)
Exemple #17
0
def dock_window(dialog_class):
    try:
        pm.deleteUI(dialog_class.CONTROL_NAME)
    except:
        pass

    main_control = pm.workspaceControl(dialog_class.CONTROL_NAME, iw=300, ttc=["AttributeEditor", -1], li=False, mw=True, wp='preferred',
                                       label=dialog_class.LABEL_NAME)

    control_widget = OpenMayaUI.MQtUtil.findControl(dialog_class.CONTROL_NAME)

    control_wrap = wrapInstance(long(control_widget), QtWidgets.QWidget)
    control_wrap.setStyleSheet("background-color:#505050;")
    control_wrap.setAttribute(QtCore.Qt.WA_DeleteOnClose)

    win = dialog_class(control_wrap)

    pm.evalDeferred(lambda *args: pm.workspaceControl(main_control, e=True, rs=True))

    return win.run()
Exemple #18
0
 def resize(self, width, height=None):
     """Resize the window."""
     if isinstance(width, QtCore.QSize):
         height = width.height()
         width = width.width()
     if self.dockable():
         if self._Pre2017:
             if not self.floating():
                 return pm.dockControl(self.WindowID, edit=True, width=width, height=height)
         else:
             return pm.workspaceControl(self.WindowID, edit=True, resizeWidth=width, resizeHeight=height)
     return super(MayaWindow, self).resize(width, height)
Exemple #19
0
def maya_workspace_docker(qt_widget, window_title):
    """
    qt maya docker
    """

    label = getattr(qt_widget, "label", window_title)
    try:
        pm.deleteUI(window_title)
    except RuntimeError:
        pass

    workspace_control = pm.workspaceControl(
        window_title, tabToControl=["AttributeEditor", -1], label=label)
    workspace_pointer = omui.MQtUtil.findControl(workspace_control)
    wrap_widget = wrapInstance(long(workspace_pointer), QtWidgets.QWidget)
    wrap_widget.setAttribute(QtCore.Qt.WA_DeleteOnClose)
    # wrap_widget.destroyed.connect(close)
    child = qt_widget(wrap_widget)
    wrap_widget.layout().addWidget(child)
    pm.evalDeferred(lambda *args: pm.workspaceControl(
        workspace_control, edit=True, restore=True))
def getDock(name='LightingManagerDock'):
    # Delete dock with same name if it exists
    deleteDock(name)
    # Create a new dock control
    ctrl = pm.workspaceControl(name,
                               dockToMainWindow=('right', 1),
                               label="Lighting Manager")
    # Get the memory address of control
    qtCtrl = omui.MQtUtil_findControl(ctrl)
    # Convert it to an instance and convert it to long and convert to a regular widget
    ptr = wrapInstance(long(qtCtrl), QtWidgets.QWidget)
    return ptr
Exemple #21
0
def deleteDock(name='CoutureDock'):
    """
    Delete an already existing Couture dockable windows
    @param name: str, name of the Couture dockable window
    """
    if maya_api_version() < MAYA2017:
        if pm.dockControl(name, query=True, exists=True):
            # If it does we delete it
            pm.deleteUI(name)
    else:
        if pm.workspaceControl(name, query=True, exists=True):
            pm.deleteUI(name)
Exemple #22
0
def getDock(name='FbxExporterUIDock'):
    deleteDock(name)

    # Creates and manages the widget used to host windows in a layout
    # which enables docking and stacking windows together
    ctrl = pm.workspaceControl(name, dockToMainWindow=('right', 1), label='Fbx Exporter')
    # we need the QT version, MQtUtil_findControl return the qt widget of the named maya control
    qtCtrl = omui.MQtUtil_findControl(ctrl)
    # translate to something python understand
    ptr = wrapInstance(long(qtCtrl), QtWidgets.QWidget)

    return ptr
def run(self):

	self.setObjectName("toolkit")
	workspaceControlName = self.objectName() + "WorkspaceControl"

	if pm.workspaceControl(workspaceControlName, exists=True):
		pm.deleteUi(workspaceControlName)

	# this class is inheriting MayaQWidgetDockableMixin.show(), which will eventually call maya.cmds.workspaceControl.
	# I'm calling it again, since the MayaQWidgetDockableMixin dose not have the option to use the "tabToControl" flag,
	# which was the only way i found i can dock my window next to the channel controls, attributes editor and modelling toolkit.
	self.show(	dockable=True, 
					area="right",
				floating=False)

	pm.workspaceControl(workspaceControlName, edit=True,
									 widthProperty="preferred",
								  dockToMainWindow=["right",True],
									  minimumWidth=True)
	self.raise_()
	self.setDockableParameters(width=393)
def getDock(name='LightingManagerDock'):

    # delete any conflicting docks
    deleteDock(name)
    ctrl = pm.workspaceControl(name,
                               dockToMainWindow=('right', 1),
                               label="Lighting Manager")
    qtCtrl = omui.MQtUtil_findControl(ctrl)

    # wrapInstance used to convert it to something Python can understand, in this case a QWidget
    ptr = wrapInstance(long(qtCtrl), QtWidgets.QWidget)

    return ptr
Exemple #25
0
def workspaceControlWrap(windowClass, dock=True, resetFloating=True, *args, **kwargs):
    """Template class for docking a Qt widget to maya 2017+.
    Requires the window to contain the attributes WindowID and WindowName.

    Source (heavily modified): https://gist.github.com/liorbenhorin/69da10ec6f22c6d7b92deefdb4a4f475
    """
    # Set window ID if needed but disable saving
    if not hasattr(windowClass, 'WindowID'):
        windowClass.WindowID = str(uuid.uuid4())
        windowClass.saveWindowPosition = lambda *args, **kwargs: None

    # Remove existing window
    floating = deleteWorkspaceControl(windowClass.WindowID, resetFloating=resetFloating)
    if not resetFloating and floating is None:
        floating = not dock

    # Setup Maya's window
    if dock:
        defaultDock = mel.eval('getUIComponentDockControl("Attribute Editor", false)')
        if isinstance(dock, (bool, int)):
            dock = defaultDock
        try:
            pm.workspaceControl(windowClass.WindowID, retain=True, label=getattr(windowClass, 'WindowName', 'New Window'), tabToControl=[dock, -1])
        except RuntimeError:
            deleteWorkspaceControl(windowClass.WindowID, resetFloating=resetFloating)
            pm.workspaceControl(windowClass.WindowID, retain=True, label=getattr(windowClass, 'WindowName', 'New Window'), tabToControl=[defaultDock, -1])
    else:
        pm.workspaceControl(windowClass.WindowID, retain=True, label=getattr(windowClass, 'WindowName', 'New Window'), floating=True)

    # Setup main window and parent to Maya
    workspaceControlWin = getMainWindow(windowClass.WindowID)
    workspaceControlWin.setAttribute(QtCore.Qt.WA_DeleteOnClose)
    windowInstance = windowClass(parent=workspaceControlWin, dockable=True, *args, **kwargs)

    # Attach callbacks
    windowInstance.signalConnect(workspaceControlWin.destroyed, windowInstance.close, group='__mayaDockWinDestroy')
    try:
        pm.workspaceControl(windowClass.WindowID, edit=True, visibleChangeCommand=windowInstance.visibleChangeEvent)
    except (AttributeError, TypeError):
        pass
    try:
        windowInstance.loadWindowPosition()
    except (AttributeError, TypeError):
        pass

    # Restore the window (after maya is ready) since it may not be visible
    windowInstance.deferred(windowInstance.raise_)
    windowInstance.deferred(windowInstance.windowReady.emit)
    return windowInstance
Exemple #26
0
    def mayaShow(self, name="MF_CamShaker"):
        # NOTE 如果变量存在 就检查窗口多开
        if pm.versions.current() > pm.versions.v2016:
            if pm.window(name, q=1, ex=1):
                pm.deleteUI(name)
            window = pm.window(name, title=self.windowTitle())
        else:
            if pm.workspaceControl(name, q=1, ex=1):
                pm.deleteUI(name)
            window = pm.workspaceControl(name, label=self.windowTitle())

        pm.showWindow(window)

        # NOTE 将Maya窗口转换成 Qt 组件
        self.ptr = mayaToQT(window)
        self.ptr.setLayout(QtWidgets.QVBoxLayout())
        self.ptr.layout().setContentsMargins(0, 0, 0, 0)
        self.ptr.layout().addWidget(self)
        self.ptr.resize(300, 300)
        self.ptr.destroyed.connect(
            lambda: self.channelBox.CHANNELBOX_PLUS.removeCallback())
        # self.ptr.setMaximumHeight(300)
        return self.ptr


# import sys
# MODULE = r"F:\MayaTecent\MayaScript\anim\camShaker"
# if MODULE not in sys.path:
#     sys.path.append(MODULE)

# try:
#     import camShaker
#     reload (camShaker)
#     win = camShaker.CamShakerWin()
#     win.mayaShow()
# except:
#     import traceback
#     traceback.print_exc()
Exemple #27
0
    def _open_ui(self, restore):
        if restore:
            # We're being reopened, and a layout has already been created.
            restored_control = omui.MQtUtil.getCurrentParent()

        if self.ui is None:
            self.ui = self.window_class()

            def closed():
                self.ui = None

            self.ui.destroyed.connect(closed)

        if restore:
            # We're restoring into an existing layout.  Just add the control that was created
            # for us, and show() will be called automatically.
            ptr = omui.MQtUtil.findControl(self.ui.objectName())
            omui.MQtUtil.addWidgetToMayaLayout(long(ptr),
                                               long(restored_control))
            return

        # Disable retain, or we won't be able to create the window again after reloading the script
        # with an "Object's name 'DialogWorkspaceControl' is not unique" error.
        #
        # Watch out: this function has *args and *kwargs which shouldn't be there, which causes it to
        # silently eat unknown parameters instead of throwing an error.
        self.ui.setDockableParameters(dockable=True,
                                      retain=False,
                                      plugins=self.plugins,
                                      uiScript=self.uiScript)

        # If we just set plugins (which is really workspaceControl -requiredPlugin), the control
        # will be closed on launch.  We need to enable checksPlugins too to work around this.
        control_name = self.ui.objectName() + 'WorkspaceControl'
        pm.workspaceControl(control_name, e=True, checksPlugins=True)

        self.ui.show()
Exemple #28
0
def getDock(name='ProceduralRiggingTool'):
    """
    Delete existing Dock and create a Dock Ctrl, finally return the ptr of the new Dock ctrl
    :param name: Dock name
    :return: ptr of the new create Dock as QWidget
    """
    deleteDock(name)

    ctrl = pm.workspaceControl(name,
                               dockToMainWindow=('right', 1),
                               label='ProceduralRiggingTool')

    qtCtrl = omui.MQtUtil.findControl(ctrl)
    ptr = wrapInstance(long(qtCtrl), QtWidgets.QWidget)

    return ptr
Exemple #29
0
    def __init__(self):
        super(Dialog, self).__init__()

        self.__class__.UI_INSTANCE = self
        self.setObjectName(self.__class__.UI_NAME)

        self.setWindowTitle(self.WINDOW_TITLE)
        self.setMinimumSize(330, 100)

        workspaceControlName = "{0}WorkspaceControl".format(self.UI_NAME)
        if pm.workspaceControl(workspaceControlName, q=1, ex=1):
            workspaceControlPtr = long(
                pma.MQtUtil.findControl(workspaceControlName))
            widgetPtr = long(getCppPointer(self)[0])

            pma.MQtUtil.addWidgetToMayaLayout(widgetPtr, workspaceControlPtr)

        self.createWidgets()
        self.createLayouts()
        self.createConnections()
Exemple #30
0
def getDock(name='LightingManagerDock'):
    """
    This function creates a dock with the given name.
    It's an example of how we can mix Maya's UI elements with Qt elements
    Args:
        name: The name of the dock to create
    Returns:
        QtWidget.QWidget: The dock's widget
    """
    # delete any conflict dock
    deleteDock(name)
    # name of the dock created
    ctrl = pm.workspaceControl(name,
                               dockToMainWindow=('right', 1),
                               label="Lighting Manager")
    qtCtrl = omui.MQtUtil_findControl(ctrl)

    # conver to something python can understand
    ptr = wrapInstance(long(qtCtrl), QtWidgets.QWidget)
    return ptr
Exemple #31
0
    def __init__(self):
        super(MainWindow, self).__init__()

        self.__class__.UI_INSTANC = self
        self.setObjectName(self.__class__.UI_NAME)
        self.setWindowTitle(self.WINDOW_TITLE)
        self.setMinimumSize(380, 160)

        workspaceControlName = "{0}WorkspaceControl".format(self.UI_NAME)

        if pm.workspaceControl(workspaceControlName, q=1, ex=1):
            workspaceControlPtr = long(
                pma.MQtUtil.findControl(workspaceControlName))
            widgetPtr = long(getCppPointer(self)[0])

            pma.MQtUtil.addWidgetToMayaLayout(widgetPtr, workspaceControlPtr)

        self.create_widgets()
        self.create_layouts()
        self.create_connections()
        self.set_default_states()
        self.update_ui_options()
        self.create_script_job()