Tabs

class vanilla.Tabs(posSize, titles=['Tab'], callback=None, sizeStyle='regular', showTabs=True, transitionStyle=None)

A set of tabs attached to a window. Each tab is capable of containing controls.

../_images/Tabs.png

To add a control to a tab, simply set it as an attribute of the tab.

from vanilla import Window, Tabs, TextBox

class TabsDemo:

    def __init__(self):
        self.w = Window((250, 100))
        self.w.tabs = Tabs((10, 10, -10, -10), ["Tab One", "Tab Two"])
        tab1 = self.w.tabs[0]
        tab1.text = TextBox((10, 10, -10, -10), "This is tab 1")
        tab2 = self.w.tabs[1]
        tab2.text = TextBox((10, 10, -10, -10), "This is tab 2")
        self.w.open()

TabsDemo()

No special naming is required for the attributes. However, each attribute must have a unique name.

To retrieve a particular tab, access it by index:

myTab = self.w.tabs[0]

posSize Tuple of form (left, top, width, height) or “auto” representing the position and size of the tabs.

titles An ordered list of tab titles.

callback The method to be called when the user selects a new tab.

sizeStyle A string representing the desired size style of the tabs. The options are:

“regular”

“small”

“mini”

showTabs Boolean representing if the tabview should display tabs.

transitionStyle A string rerpresenting a transition style between tabs. The options are:

None

“crossfade”

“slideUp”

“slideDown”

“slideLeft”

“slideRight”

“slideForward”

“slideBackward”

addAutoPosSizeRules(rules, metrics=None)

Add auto layout rules for controls/view in this view.

rules must be a list of rule definitions. Rule definitions may take two forms:

key

value

“view1”

The vanilla wrapped view for the left side of the rule.

“attribute1”

The attribute of the view for the left side of the rule. See below for options.

“relation” (optional)

The relationship between the left side of the rule and the right side of the rule. See below for options. The default value is “==”.

“view2”

The vanilla wrapped view for the right side of the rule.

“attribute2”

The attribute of the view for the right side of the rule. See below for options.

“multiplier” (optional)

The constant multiplied with the attribute on the right side of the rule as part of getting the modified attribute. The default value is 1.

“constant” (optional)

The constant added to the multiplied attribute value on the right side of the rule to yield the final modified attribute. The default value is 0.

The attribute1 and attribute2 options are:

value

AppKit equivalent

“left”

NSLayoutAttributeLeft

“right”

NSLayoutAttributeRight

“top”

NSLayoutAttributeTop

“bottom”

NSLayoutAttributeBottom

“leading”

NSLayoutAttributeLeading

“trailing”

NSLayoutAttributeTrailing

“width”

NSLayoutAttributeWidth

“height”

NSLayoutAttributeHeight

“centerX”

NSLayoutAttributeCenterX

“centerY”

NSLayoutAttributeCenterY

“baseline”

NSLayoutAttributeBaseline

“lastBaseline”

NSLayoutAttributeLastBaseline

“firstBaseline”

NSLayoutAttributeFirstBaseline

Refer to the NSLayoutAttribute documentation for the information about what each of these do.

The relation options are:

value

AppKit equivalent

“<=”

NSLayoutRelationLessThanOrEqual

“==”

NSLayoutRelationEqual

“>=”

NSLayoutRelationGreaterThanOrEqual

Refer to the NSLayoutRelation documentation for the information about what each of these do.

metrics may be either None or a dict containing key value pairs representing metrics keywords used in the rules defined with strings.

enable(onOff)

Enable or disable the object. onOff should be a boolean.

get()

Get the index of the selected tab.

getNSTabView()

Return the NSTabView that this object wraps.

getPosSize()

The position and size of the object as a tuple of form (left, top, width, height).

isVisible()

Return a bool indicating if the object is visible or not.

move(x, y)

Move the object by x units and y units.

resize(width, height)

Change the size of the object to width and height.

set(value)

Set the selected tab.

value The index of the tab to be selected.

setPosSize(posSize, animate=False)

Set the position and size of the object.

posSize A tuple of form (left, top, width, height).

animate A boolean flag telling to animate the transition. Off by default.

setShowFocusRing(value)

Set if the focus ring is visible.

setToolTip(toolTipMessage)

Add tool tip message to the object when hover over it with the cursor.

show(onOff)

Show or hide the object.

onOff A boolean value representing if the object should be shown or not.