How to set a callback function for close tab action ?

How to set a callback function for close tab action ?

huseila
Enthusiast Enthusiast
411 Views
3 Replies
Message 1 of 4

How to set a callback function for close tab action ?

huseila
Enthusiast
Enthusiast

Hi all,

 

A quick question: is there any way to set a callback for closing a custom tab panel (as attached image) ?

Accepted solutions (1)
412 Views
3 Replies
Replies (3)
Message 2 of 4

Kahylan
Advisor
Advisor

Hi!

 

could you please post the part of your code where you create the dockable tab layout, so we can know what layoutelements you used?

0 Likes
Message 3 of 4

huseila
Enthusiast
Enthusiast

Hi Kahylan,

 

This is the code I use to build side tab panel, and I'm not sure if it provides any callback setup for closing tab

import maya.mel as mel
import maya.cmds as cmds
from maya.app.general.mayaMixin import MayaQWidgetDockableMixin


class ExportXGenCacheDockableWidget(MayaQWidgetDockableMixin, QtWidgets.QWidget):
    def __init__(self, parent=None):
        super(ExportXGenCacheDockableWidget, self).__init__(parent=parent)
        self._build_ui()

    def _build_ui(self):
        pass


# This is how I create side tab panel
class MainUI(object):
    def __init__(self, xgen_cache_data_builder, xgen_cache_file_exporter):
        self._build_side_tab(xgen_cache_data_builder, xgen_cache_file_exporter)

    def _build_side_tab(self, xgen_cache_data_builder, xgen_cache_file_exporter):
        self.export_xgen_cache_mixin_window = ExportXGenCacheDockableWidget(xgen_cache_data_builder, xgen_cache_file_exporter)
        self.export_xgen_cache_mixin_window.setObjectName('ExportXGenCacheMixinWindow')

        if cmds.workspaceControl('ExportXGenCacheMixinWindowWorkspaceControl', q=True, ex=True):
            cmds.deleteUI('ExportXGenCacheMixinWindowWorkspaceControl', control=True)

        # When "export_xgen_cache_mixin_window.show" is evaluated, a "ExportXGenCacheMixinWindowWorkspaceControl" will be created !
        self.export_xgen_cache_mixin_window.show(dockable=True, height=600, width=480, uiScript='DockableWidgetUIScript(restore=False)')
        ui_component_dock_control = mel.eval('getUIComponentDockControl("Channel Box / Layer Editor", false);')
        cmds.workspaceControl('ExportXGenCacheMixinWindowWorkspaceControl', e=True, ttc=(ui_component_dock_control, -1), wp='preferred', mw=200)

 

0 Likes
Message 4 of 4

Kahylan
Advisor
Advisor
Accepted solution

The MayaQWidgetDockableMixin class has a built function to trigger the close event called "dockCloseEventTriggered". which runs whenever the widget is closed. This acts like a built in callback, as you can just do whatever you want on closing the window, without having to catch a callback first.

 

So you can run a command when the window closes by adding this to your class:

    def dockCloseEventTriggered(self):
        self.closeEvent()
    def closeEvent(self):
        print("Window closed")

 

I hope it helps!