Message 1 of 4
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
Hi all,
A quick question: is there any way to set a callback for closing a custom tab panel (as attached image) ?
Solved! Go to Solution.
Hi all,
A quick question: is there any way to set a callback for closing a custom tab panel (as attached image) ?
Solved! Go to Solution.
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?
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)
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!