# 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 that shows different kind of buttons and their properties.
#
# Topic: FBButton, FBButtonStyle, FBTextJustify, FBButtonLook
#

from pyfbsdk import *
from pyfbsdk_additions import *

# Button creation
def BtnCallback(control, event):
    print control.Caption, " has been clicked!"

def PopulateLayout(mainLyt):
    x = FBAddRegionParam(0,FBAttachType.kFBAttachLeft,"")
    y = FBAddRegionParam(0,FBAttachType.kFBAttachTop,"")
    w = FBAddRegionParam(0,FBAttachType.kFBAttachRight,"")
    h = FBAddRegionParam(25,FBAttachType.kFBAttachNone,"")
    mainLyt.AddRegion("main","main", x, y, w, h)
    lyt = HBoxLayout()
    mainLyt.SetControl("main",lyt)

    b = FBButton()
    b.Caption = "But1"
    b.Justify = FBTextJustify.kFBTextJustifyLeft
    lyt.Add(b,60)
    b.OnClick.Add(BtnCallback)

    b = FBButton()
    b.Caption = "But2"
    b.Justify = FBTextJustify.kFBTextJustifyRight
    lyt.Add(b,60)
    b.OnClick.Add(BtnCallback)


    b = FBButton()
    b.Caption = "But3"
    b.Style = FBButtonStyle.kFB2States
    b.Look = FBButtonLook.kFBLookColorChange
    b.Justify = FBTextJustify.kFBTextJustifyCenter
    b.SetStateColor(FBButtonState.kFBButtonState0,FBColor(1.0, 0.0, 0.5))
    b.SetStateColor(FBButtonState.kFBButtonState1,FBColor(0.0, 1.0, 0.5))
    lyt.Add(b,60)

    b.OnClick.Add(BtnCallback)

    b = FBButton()
    b.Caption = "But4"
    b.Style = FBButtonStyle.kFBBitmap2States
    b.Look = FBButtonLook.kFBLookNormal
    b.Justify = FBTextJustify.kFBTextJustifyCenter
    b.SetImageFileNames("tape/tape_play_off.tif","tape/tape_play_on.tif")
    lyt.Add(b,60)

    b.OnClick.Add(BtnCallback)

    b = FBButton()
    b.Caption = "Check1"
    b.Style = FBButtonStyle.kFBCheckbox
    b.Justify = FBTextJustify.kFBTextJustifyLeft
    lyt.Add(b,60)

    b.OnClick.Add(BtnCallback)


    b = FBButton()
    b.Caption = "Check2"
    b.Style = FBButtonStyle.kFBCheckbox
    b.Justify = FBTextJustify.kFBTextJustifyCenter
    lyt.Add(b,60)
    b.State = True


    b.OnClick.Add(BtnCallback)

def CreateTool():
    # Tool creation will serve as the hub for all other controls
    t = CreateUniqueTool("Button Example")
    t.StartSizeX = 400
    t.StartSizeY = 200
    PopulateLayout(t)
    ShowTool(t)


CreateTool()