RadioGroup

class vanilla.VerticalRadioGroup(posSize, titles, callback=None, sizeStyle='regular')

A vertical collection of radio buttons.:

from vanilla import *

class RadioGroupDemo(object):

    def __init__(self):
        self.w = Window((100, 0))
        self.w.radioGroup = VerticalRadioGroup(
            "auto",
            ["Option 1", "Option 2"],
            callback=self.radioGroupCallback
        )
        rules = [
            "H:|-[radioGroup]-|",
            "V:|-[radioGroup(==%d)]-|" % self.w.radioGroup.getFittingHeight()
        ]
        self.w.open()

    def radioGroupCallback(self, sender):
        print("radio group edit!", sender.get())

RadioGroupDemo()

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

titles A list of titles to be shown next to the radio buttons.

callback The method to be caled when a radio button is selected.

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

“regular”
“small”
“mini”
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.

addView(view, width=None, height=None, gravity='center')

Add a view.

view A vanilla object or an instance of NSView.

width and height are None, numbers or strings:

  • value as 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
  • “>=value” where value can be coerced to an integer or float

Up to two are allowed. Separate with , (comma).

gravity The gravity that this view should be attracted to.

HorizontalStackGroup Options:

  • “leading”
  • “center”
  • “trailing”
  • One of the NSStackViewGravity options.

VerticalStackGroup Options:

  • “top”
  • “center”
  • “bottom”
  • One of the NSStackViewGravity options.
enable(onOff)

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

get()

Get the index of the selected radio button.

getFittingHeight()

Get the fitting height for all buttons in the group.

getPosSize()

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

insertView(index, view, width=None, height=None, gravity='center')

Insert a view.

See addView() documentation.

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.

view A vanilla object or an instance of NSView.

resize(width, height)

Change the size of the object to width and height.

set(index)

Set the index of the selected radio button.

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.

class vanilla.HorizontalRadioGroup(posSize, titles, callback=None, sizeStyle='regular')

A horizontal collection of radio buttons.:

from vanilla import *

class RadioGroupDemo(object):

    def __init__(self):
        self.w = Window((200, 0))
        self.w.radioGroup = HorizontalRadioGroup(
            "auto",
            ["Option 1", "Option 2"],
            callback=self.radioGroupCallback
        )
        rules = [
            "H:|-[radioGroup]-|",
            "V:|-[radioGroup(==%d)]-|" % self.w.radioGroup.getFittingHeight()
        ]
        self.w.open()

    def radioGroupCallback(self, sender):
        print("radio group edit!", sender.get())

RadioGroupDemo()

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

titles A list of titles to be shown next to the radio buttons.

callback The method to be caled when a radio button is selected.

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

“regular”
“small”
“mini”
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.

addView(view, width=None, height=None, gravity='center')

Add a view.

view A vanilla object or an instance of NSView.

width and height are None, numbers or strings:

  • value as 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
  • “>=value” where value can be coerced to an integer or float

Up to two are allowed. Separate with , (comma).

gravity The gravity that this view should be attracted to.

HorizontalStackGroup Options:

  • “leading”
  • “center”
  • “trailing”
  • One of the NSStackViewGravity options.

VerticalStackGroup Options:

  • “top”
  • “center”
  • “bottom”
  • One of the NSStackViewGravity options.
enable(onOff)

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

get()

Get the index of the selected radio button.

getFittingHeight()

Get the fitting height for all buttons in the group.

getPosSize()

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

insertView(index, view, width=None, height=None, gravity='center')

Insert a view.

See addView() documentation.

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.

view A vanilla object or an instance of NSView.

resize(width, height)

Change the size of the object to width and height.

set(index)

Set the index of the selected radio button.

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.

class vanilla.RadioGroup(posSize, titles, isVertical=True, callback=None, sizeStyle='regular')

Note

This should be used only for frame layout.

A collection of radio buttons.:

from vanilla import *

class RadioGroupDemo(object):

    def __init__(self):
        self.w = Window((100, 60))
        self.w.radioGroup = RadioGroup((10, 10, -10, 40),
                                ["Option 1", "Option 2"],
                                callback=self.radioGroupCallback)
        self.w.open()

    def radioGroupCallback(self, sender):
        print("radio group edit!", sender.get())

RadioGroupDemo()

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

titles A list of titles to be shown next to the radio buttons.

isVertical Boolean representing if the radio group is vertical or horizontal.

callback The method to be caled when a radio button is selected.

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

“regular”
“small”
“mini”
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.

enableRadioButton(index, onOff=True)

Enable or disable a RadioGroup button specified by its index.

get()

Get the index of the selected radio button.

getNSMatrix()

Return the NSMatrix that this object wraps.

getPosSize()

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

getTitle()

Get the control title.

isEnabled()

Return a bool indicating if the object is enable 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.

set(index)

Set the index of the selected radio button.

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.

setTitle(title)

Set the control title.

title A string representing the title.

show(onOff)

Show or hide the object.

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