Maya python window tabs as a button

Hi,
i am trying to create a window in Maya with python and i have a question.
What i am trying to achieve, is a window with 3 tabs, each tab will have several preview icons and each icon will have its own button.
I have manage to create the above window with the tabs the icons and the buttons and everything seems to be functional.
My main question is how can i make each tab as a button itself.
What i mean is when the user clicks on a tab a function is executed the same way as the buttons, but i don’t want a graphic button.
Lets say i have in the outliner three nulls, (nullA, nullB, nullC), each tab of the window has the same name as the nulls and it is connected with the visibility of these nulls.
So for example when you are on the tab B, only the nullB is visible etc.
Any idea for that?

Are you using QT to create your tab widget?
If you are, you can emit its tabBarClicked or currentChanged signal. And assign a function to that.

No, i am not using QT

In that case I take it you are using the tabLayout command?
Which looking at the documentation has a selectCommand flag, which does the following:

Command executed when a tab is selected interactively This command will be invoked whenever a tab is selected, ie. re-selecting the current tab will invoke this command.

Yes i am using tabLayout command, but i don’t understand where to place this flag you are referencing.

Here is the main structure of the code:

import maya.cmds as mc

if mc.window("dumWin",exists = True):
    mc.deleteUI("dumWin")

myWindow = mc.window("dumWin",t="TEST",w =1200, h=600,sizeable = False )
form = mc.formLayout()
tabs = mc.tabLayout(innerMarginWidth=5, innerMarginHeight=5)
mc.formLayout( form, edit=True, attachForm=((tabs, 'top', 0), (tabs, 'left', 0), (tabs, 'bottom', 0), (tabs, 'right', 0)) )


child1 = mc.rowColumnLayout( numberOfColumns=4, columnWidth=[(1, 150), (2, 150), (3, 150), (4, 150)] )


mc.button(h= 20, l = "testA")

mc.setParent( '..' )


child2 = mc.rowColumnLayout( numberOfColumns=4, columnWidth=[(1, 150), (2, 150), (3, 150), (4, 150)] )


mc.button(h= 20, l = "testB")

mc.setParent( '..' )

child3 = mc.rowColumnLayout( numberOfColumns=4, columnWidth=[(1, 150), (2, 150), (3, 150), (4, 150)] )


mc.button(h= 20, l = "testC")

mc.setParent( '..' )

mc.tabLayout( tabs, edit=True, tabLabel=((child1, 'nullA'), (child2, 'nullB'), (child3, 'nullC')) )

mc.showWindow(myWindow)

You can add it to the tabLayout command when you fist create it.

As far as I can tell, tabLayout doesn’t return any arguments when clicked,
so in order to identify which tab was clicked, you need to query that information in your assigned function.

I created a test function which prints out some data about the clicked tab as an example.

def on_tab(*args):
    
    tab_index = mc.tabLayout(tabs, q=True, selectTabIndex=True )
    tab_name = mc.tabLayout(tabs, q=True, selectTab=True )
    tab_label = mc.tabLayout(tabs, q=True, tabLabel=True)[tab_index-1]
    
    print('index: {}'.format(tab_index))
    print('name: {}'.format(tab_name))
    print('label: {}'.format(tab_label))

myWindow = mc.window("dumWin",t="TEST",w =1200, h=600,sizeable = False )
form = mc.formLayout()
tabs = mc.tabLayout(innerMarginWidth=5, innerMarginHeight=5, selectCommand=on_tab )

Great thank you very much for your help,
i did it :slight_smile: