美文网首页工具癖
MotionBuilder Python Script07 -

MotionBuilder Python Script07 -

作者: Houdinini | 来源:发表于2019-07-23 20:12 被阅读3次
    Continue!

    看了一下前两天的文章,发现把之前的box全都敲成Button了,惭愧。。今天我们就来看看MotionBuilder中的Button!

    一、Button

    UI中最基本的元素,也是因为基本导致把Box误敲成Button。。

    先来看一下UI效果

    Button 效果
    这里展示了6种Button的样式,我们来看一下代码:
    #!/usr/bin/env python
    # -*- coding: utf-8 -*-
    
    # 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 = FBHBoxLayout()
        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.png","tape/tape_play_on.png")
        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 = FBCreateUniqueTool("Button Example")
        t.StartSizeX = 400
        t.StartSizeY = 200
        PopulateLayout(t)
        ShowTool(t)
    
    CreateTool()
    

    代码比较干净,清晰明了!同样, decomposition and refactor!

    二、结语

    继续更新!

    共勉!

    相关文章

      网友评论

        本文标题:MotionBuilder Python Script07 -

        本文链接:https://www.haomeiwen.com/subject/cxxzlctx.html