Maya /Python - Base Window Class

Hi. I’m back to studying Python.
Now reading up on classes and how to utilize it with UI:s.

I’m having some problems figuring out how to get exactly what I want though and so I turn to you.
I’m using the book “Maya Python for Games and Film”. They are distributing a base window class found here:
http://maya-python.com/files/optwin.py

I then created another class which inherits from the base class, here:

import optwin
reload(optwin)

from optwin import AR_OptionsWindow


class newWin(AR_OptionsWindow):
    def __init__(self):
        AR_OptionsWindow.__init__(self)
        self.title = 'Dag\'s window'
        self.window = 'dag\'s window'
        self.actionName = 'Huey'
     

    def displayOptions(self):
        mc.setParent(self.optionsForm)
        self.btnA = mc.button(
                        label = "button A")


        mc.formLayout(self.optionsForm, edit=True,
                      attachForm=(
                      [self.btnA, 'left', 0],
                      [self.btnA, 'right', 0],
                      [self.btnA, 'top', 0],
                      [self.btnA, 'bottom', 0],

                      ),
                      
                      attachPosition=(
                      [self.btnA, 'right', 0, 50],
                      )               
        )

        
newWin.showUI()

It’s really simple. However I really can’t figure out how to attach the button in the tab layout to the bottom so it will scale with the window =/
Tried parenting the button to the mainForm instead and sure, that works, but I want it to be attached to the tab layout. Also tried creating another form layout inside the tablayout(whatever that would do), but it looked the same of course.

Thank you for reading! :nod:

Ok, I figured this one out. However I still don’t get it… :banghead:

By editing the base class, the elements resize according to the formLayout settings.
on line 42 I changed:
scrollable=True to scrollable=False

However I really wouldn’t want to go in and edit the class, but it seems nothing else work. :rolleyes:

I tried to edit this in my inherited class:

    def displayOptions(self):

        mc.tabLayout(
                    self.optionsBorder,
                    e=True,
                    scrollable=False,
                    tabsVisible=True,
                    tli = (1, 'tab 1')
            	    )

This works for the tabVisible and tab label, but does nothing for the scrollable function. :argh:

Anyone could shed some light on this?

I’m posting both the edited class and my full inherited one for you to try.

https://dl.dropboxusercontent.com/u/16029672/3D/Script/optwin.py
https://dl.dropboxusercontent.com/u/16029672/3D/Script/optwin_derived_class.py

I would just edit the base class. Even though the comment above the tabLayout says “see getOptionBox.mel for why we implement this layout pattern to emulate Maya’s option boxes”, the optionBox in maya does not set scrollable or childResizable for the tabLayout.

These are the two commands that create the tabLayout in getOptionBox.mel

	//	To reduce flicker when changing the option box contents
	//	use a tab layout.  Create new UI in the hidden tab, leaving
	//	the current option box contents visible until the new UI is
	//	created.  When creation of the new UI is complete then the 
	//	hidden tab will become the current one and the old option box
	//	UI will be deleted.
	//
	$gOptionBoxTabLayout = `tabLayout -tabsVisible 0`;

	// Make the minimum height of the tab layout as small as possible
	// so that when the window is scaled down, the common option box
	// buttons do not overlap the contents of the option box.
	tabLayout -e -height 1 $gOptionBoxTabLayout;
1 Like