HorizontalStackView
- class vanilla.HorizontalStackView(posSize, views, spacing=0, alignment='center', distribution='fillEqually', edgeInsets=(0, 0, 0, 0))
A view that allows the creation of a stack of views.
from vanilla import Button, HorizontalStackView, Window class HorizontalStackViewExample: def __init__(self): self.w = Window((300, 40)) self.button1 = Button("auto", "One") self.button2 = Button("auto", "Two") self.button3 = Button("auto", "Three") self.button4 = Button("auto", "Four") self.w.horizontalStack = HorizontalStackView( (0, 0, 0, 0), views=[ dict(view=self.button1), dict(view=self.button2), dict(view=self.button3), dict(view=self.button4) ], spacing=4, edgeInsets=(4, 4, 4, 4), ) self.w.open() HorizontalStackViewExample()
posSize Tuple of form (left, top, width, height) or “auto” representing the position and size of the stack view.
views The views to display in the stack. See below for structure.
spacing Space to insert between views.
alignment The alignment of the views. Options:
“leading”
“center”
“trailing”
One of the NSLayoutAttribute options.
distribution The distribution of the views. Options:
“equalCentering”
“equalSpacing”
“fill”
“fillEqually”
“fillProportionally”
“gravity”
edgeInsets Tuple of four numbers (left, top, right, bottom) indicating the amount to inset the views.
View Definition Structure
Views are defined with either a Vanilla object, a NSView (or NSView subclass) object or a dictionary with this structure:
view A vanilla object or an instance of NSView.
width A number, string (using the size syntax below) or None (indicating auto width) defining the width.
height A number, string (using the size syntax below) or None (indicating auto height) defining the height.
gravity The gravity that this view should be attracted to.
spacing A number defining custom spacing after the view.
Size Constants:
“fill” Stretch the view to fit the width or height of the stack view.
“fit” Fit the view to the size needed to contain its contents.
Size Syntax:
“==value” where value can be coerced to an integer or float
“<=value” where value can be coerced to an integer or float
“>=value” where value can be coerced to an integer or float
Up to two are allowed. Separate with
,
(comma).Horizontal Gravity Options:
“leading”
“center”
“trailing”
One of the NSStackViewGravity options.
Vertical Gravity Options:
“top”
“center”
“bottom”
One of the NSStackViewGravity options.
- 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:
strings that follow the Visual Format Language
dictionaries with the following key/value pairs:
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.
- appendView(view, width=None, height=None, spacing=None, gravity='center')
Append a view.
- enable(onOff)
Enable or disable the object. onOff should be a boolean.
- getPosSize()
The position and size of the object as a tuple of form (left, top, width, height).
- insertView(index, view, width=None, height=None, spacing=None, gravity='center')
Insert a view.
- isVisible()
Return a bool indicating if the object is visible or not.
- move(x, y)
Move the object by x units and y units.
- removeView(view)
Remove a view.
- resize(width, height)
Change the size of the object to width and height.
- setEdgeInsets(value)
Set the edge insets.
- 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.