# Copyright 2009 Autodesk, Inc.  All rights reserved.
# Use of this software is subject to the terms of the Autodesk license agreement 
# provided at the time of installation or download, or which otherwise accompanies
# this software in either electronic or hard copy form.
#
# Script description:
# Create a tool with radio buttons and show how to manage them with a ButtonGroup.
#
# Topic: FBAttachType, FBButtonStyle, FBButton, ButtonGroup
#

from pyfbsdk import *
from pyfbsdk_additions import *

def BtnRadioCallback(control, event):
    print control.Caption, " has been clicked!"

def PopulateLayout(mainLyt):
    group = ButtonGroup()
    group.AddCallback(BtnRadioCallback)
    anchor = ""
    attachType = FBAttachType.kFBAttachTop

    for i in range(5):
        name = "BtnRadio " + str(i)
        b = FBButton()
        group.Add(b)

        b.Caption = name
        b.Style = FBButtonStyle.kFBRadioButton

        x = FBAddRegionParam(10,FBAttachType.kFBAttachLeft,"")
        y = FBAddRegionParam(10,attachType,anchor)
        w = FBAddRegionParam(100,FBAttachType.kFBAttachNone,"")
        h = FBAddRegionParam(25,FBAttachType.kFBAttachNone,"")

        mainLyt.AddRegion(name,name, x, y, w, h)

        mainLyt.SetControl(name,b)

        attachType = FBAttachType.kFBAttachBottom
        anchor = name

def CreateTool():
    # Tool creation will serve as the hub for all other controls
    t = CreateUniqueTool("Radiobox Example")

    PopulateLayout(t)
    ShowTool(t)


CreateTool()