SplitView

class vanilla.SplitView(posSize, paneDescriptions, isVertical=True, dividerStyle='splitter', dividerThickness=None, dividerColor=None, autosaveName=None, dividerImage=None)

View that can be split into two or more subviews with dividers.

../_images/SplitView.png
from vanilla import Window, List, SplitView

class SplitViewDemo:

    def __init__(self):
        self.w = Window((200, 200), "SplitView Demo", minSize=(100, 100))
        list1 = List((0, 0, -0, -0), ["A", "B", "C"])
        list2 = List((0, 0, -0, -0), ["a", "b", "c"])
        paneDescriptors = [
            dict(view=list1, identifier="pane1"),
            dict(view=list2, identifier="pane2"),
        ]
        self.w.splitView = SplitView((0, 0, -0, -0), paneDescriptors)
        self.w.open()

SplitViewDemo()

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

paneDescriptions An ordered list of dictionaries describing the subviews, or “panes”. Those dictionaries can have the following keys:

view A view, either a Vanilla object or a NSView. Required.
“identifier” A string identifying the pane. Required.
“size” The initial size of the pane. Optional.
“minSize” The minimum size of the pane. Optional. The default is 0.
“maxSize” The maximum size of the pane. Optional. The default is no maximum size.
“canCollapse” Boolean indicating if the pane can collapse. Optional. The default is True.
“resizeFlexibility” Boolean indicating if the pane can adjust its size automatically when the SplitView size changes. Optional. The default is True unless the pane has a fixed size.

isVertical Boolean representing if the split view is vertical. Default is True.

dividerStyle String representing the style of the divider. These are the options:

splitter
thin
thick
None

dividerThickness An integer representing the desired thickness of the divider.

dividerColor A NSColor that should be used to paint the divider.

autosaveName The autosave name for the SplitView.

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.

getNSSplitView()

Return the NSSplitView that this object wraps.

getPosSize()

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

isPaneVisible(identifier)

Returns a boolean indicating if the pane with identifier is visible or not.

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.

setDividerDrawingFunction(function)

Set a function that will draw the contents of the divider. This can be None or a function that accepts the following arguments:

splitView The SplitView calling the function.
rect The rectangle containing the divider.

The function must use the Cocoa drawing API.

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.

show(onOff)

Show or hide the object.

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

showPane(identifier, onOff, animate=False)

Set the visibility of the pane with identifier.

onOff should be a boolean indicating the desired visibility of the pane. If animate is True, the pane will expand or collapse with an animation.

togglePane(identifier, animate=False)

Toggle the visibility of the pane with identifier. If animate is True, the pane will expand or collapse with and animation.