Popover

class vanilla.Popover(size, parentView=None, preferredEdge='top', behavior='semitransient')

A popover capable of containing controls.

../_images/Popover.png
from vanilla import Window, List, Popover, TextBox

class PopoverExample:

    def __init__(self):
        self.w = Window((120, 120))
        self.w.list = List((0, 0, -0, -0),
                ['A', 'B', 'C'],
                selectionCallback=self.showPopoverCallback)
        self.w.open()

    def showPopoverCallback(self, sender):
        selection = sender.getSelection()
        if not selection:
            return
        index = sender.getSelection()[0]
        relativeRect = sender.getNSTableView().rectOfRow_(index)
        self.pop = Popover((140, 80))
        self.pop.text = TextBox((10, 10, -10, -10), 'This is a popover.')
        self.pop.open(parentView=sender.getNSTableView(), preferredEdge='right', relativeRect=relativeRect)

PopoverExample()

size Tuple of form (width, height) representing the size of the content in the popover.

parentView The parent view that the popover should pop out from. This can be either a vanilla object or an instance of NSView or NSView_ subclass.

preferredEdge The edge of the parent view that you want the popover to pop out from. These are the options:

“left”

“right”

“top”

“bottom”

behavior The desired behavior of the popover. These are the options:

“applicationDefined”

Corresponds to NSPopoverBehaviorApplicationDefined.

“transient”

Corresponds to NSPopoverBehaviorTransient.

“semitransient”

Corresponds to NSPopoverBehaviorSemitransient.

addAutoPosSizeRules(rules, metrics=None)

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

rules must by 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.

bind(event, callback)

Bind a callback to an event.

event A string representing the desired event. The options are:

“will show”

Called immediately before the popover shows.

“did show”

Called immediately after the popover shows.

“will close”

Called immediately before the popover closes.

“did close”

Called immediately after the popover closes.

close()

Close the popover.

Once a popover has been closed it can not be re-opened.

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).

isVisible()

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

move(x, y)

Move the object by x units and y units.

open(parentView=None, preferredEdge=None, relativeRect=None)

Open the popover. If desired, the parentView may be specified. If not, the values assigned during init will be used.

Additionally, a rect of form (x, y, width, height) may be specified to indicate where the popover should pop out from. If not provided, the parent view’s bounds will be used.

resize(width, height)

Change the size of the popover to width and height.

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.

unbind(event, callback)

Unbind a callback from an event.

event A string representing the desired event. Refer to Popover.bind() for the options.

callback The callback that has been bound to the event.