示例#1
0
def vtkKWPushButtonEntryPoint(parent, win):

    app = parent.GetApplication()
    
    # -----------------------------------------------------------------------
    
    # Create a push button
    
    pushbutton1 = vtkKWPushButton()
    pushbutton1.SetParent(parent)
    pushbutton1.Create()
    pushbutton1.SetText("A push button")
    
    app.Script(
        "pack %s -side top -anchor nw -expand n -padx 2 -pady 2",
        pushbutton1.GetWidgetName())
    
    # -----------------------------------------------------------------------
    
    # Create another push button, use an icon
    
    pushbutton2 = vtkKWPushButton()
    pushbutton2.SetParent(parent)
    pushbutton2.Create()
    pushbutton2.SetImageToPredefinedIcon(vtkKWIcon.IconConnection)
    pushbutton2.SetBalloonHelpString(
        "Another pushbutton, using one of the predefined icons")
    
    app.Script(
        "pack %s -side top -anchor nw -expand n -padx 2 -pady 6",
        pushbutton2.GetWidgetName())
    
    # -----------------------------------------------------------------------
    
    # Create another push button, use both text and icon
    
    pushbutton2b = vtkKWPushButton()
    pushbutton2b.SetParent(parent)
    pushbutton2b.Create()
    pushbutton2b.SetText("A push button with an icon")
    pushbutton2b.SetImageToPredefinedIcon(vtkKWIcon.IconWarningMini)
    pushbutton2b.SetCompoundModeToLeft()
    pushbutton2b.SetBalloonHelpString(
        "Another pushbutton, using both a text and one of the predefined icons")
    
    app.Script(
        "pack %s -side top -anchor nw -expand n -padx 2 -pady 6",
        pushbutton2b.GetWidgetName())
    
    # -----------------------------------------------------------------------
    
    # Create another push button, with a label this time
    
    pushbutton3 = vtkKWPushButtonWithLabel()
    pushbutton3.SetParent(parent)
    pushbutton3.Create()
    pushbutton3.SetLabelText("Press this...")
    pushbutton3.GetWidget().SetText("button")
    pushbutton3.SetBalloonHelpString(
        "This is a vtkKWPushButtonWithLabel, i.e. a pushbutton associated to a "
        "label that can be positioned around the pushbutton.")
    
    app.Script(
        "pack %s -side top -anchor nw -expand n -padx 2 -pady 6",
        pushbutton3.GetWidgetName())
    
    # -----------------------------------------------------------------------

    # Create another push button, with a menu

    pushbutton4 = vtkKWPushButtonWithMenu()
    pushbutton4.SetParent(parent)
    pushbutton4.Create()
    pushbutton4.GetPushButton().SetImageToPredefinedIcon(
        vtkKWIcon.IconTransportRewind)
    pushbutton4.SetBalloonHelpString(
        "This is a vtkKWPushButtonWithMenu, i.e. a pushbutton associated to a "
        "menu.")
    
    menu = pushbutton4.GetMenu()
    menu.AddCommand("Microsoft Office")
    menu.AddCommand("Program Files")
    menu.AddCommand("C:")
    
    app.Script(
        "pack %s -side top -anchor nw -expand n -padx 2 -pady 6", 
        pushbutton4.GetWidgetName())

    # -----------------------------------------------------------------------
    
    # Create a set of pushbutton
    # An easy way to create a bunch of related widgets without allocating
    # them one by one
    
    pushbutton_set = vtkKWPushButtonSet()
    pushbutton_set.SetParent(parent)
    pushbutton_set.Create()
    pushbutton_set.SetBorderWidth(2)
    pushbutton_set.SetReliefToGroove()
    pushbutton_set.SetWidgetsPadX(1)
    pushbutton_set.SetWidgetsPadY(1)
    pushbutton_set.SetPadX(1)
    pushbutton_set.SetPadY(1)
    pushbutton_set.ExpandWidgetsOn()
    pushbutton_set.SetMaximumNumberOfWidgetsInPackingDirection(3)
    
    for id in range(0,9):
        buffer = "Push button %d" % (id)
        pushbutton = pushbutton_set.AddWidget(id)
        pushbutton.SetText(buffer)
        pushbutton.SetBackgroundColor(
            vtkMath.HSVToRGB(float(id) / 8.0, 0.3, 0.75))
        pushbutton.SetBalloonHelpString(
            "This pushbutton is part of a unique set (a vtkKWPushButtonSet), "
            "which provides an easy way to create a bunch of related widgets "
            "without allocating them one by one. The widgets can be layout as a "
            "NxM grid. Each button is assigned a different color.")
        
    
    pushbutton_set.GetWidget(0).SetText("I'm the first button")
    
    app.Script(
        "pack %s -side top -anchor nw -expand n -padx 2 -pady 6",
        pushbutton_set.GetWidgetName())
    
    
    # TODO: add callbacks
    
    
    return "TypeCore"
示例#2
0
def vtkKWProgressGaugeEntryPoint(parent, win):

    app = parent.GetApplication()
    
    # -----------------------------------------------------------------------
    
    # Create a progress gauge
    
    progress1 = vtkKWProgressGauge()
    progress1.SetParent(parent)
    progress1.Create()
    progress1.SetWidth(150)
    progress1.SetBorderWidth(2)
    progress1.SetReliefToGroove()
    progress1.SetPadX(2)
    progress1.SetPadY(2)
    
    app.Script(
        "pack %s -side top -anchor nw -expand n -padx 2 -pady 2",
        progress1.GetWidgetName())
    
    # -----------------------------------------------------------------------
    
    # Create a set of pushbutton that will modify the progress gauge
    
    progress1_pbs = vtkKWPushButtonSet()
    progress1_pbs.SetParent(parent)
    progress1_pbs.Create()
    progress1_pbs.SetBorderWidth(2)
    progress1_pbs.SetReliefToGroove()
    progress1_pbs.SetWidgetsPadX(1)
    progress1_pbs.SetWidgetsPadY(1)
    progress1_pbs.SetPadX(1)
    progress1_pbs.SetPadY(1)
    progress1_pbs.ExpandWidgetsOn()
    progress1_pbs.PackHorizontallyOn()
    progress1_pbs.SetMaximumNumberOfWidgetsInPackingDirection(3)

    nb_buttons = 0
    for id in range(0,101,25):
        buffer = "Set primary to %d%%" % (id)
        pushbutton = progress1_pbs.AddWidget(nb_buttons)
        nb_buttons = nb_buttons + 1
        pushbutton.SetText(buffer)
        buffer = "SetValue %d" % (id)
        pushbutton.SetCommand(progress1, buffer)

        buffer = "Set secondary to %d%%" % (id)
        pushbutton = progress1_pbs.AddWidget(nb_buttons)
        nb_buttons = nb_buttons + 1
        pushbutton.SetText(buffer)
        buffer = "SetNthValue 1 %d" % (id)
        pushbutton.SetCommand(progress1, buffer)

        buffer = "Set tertiary to %d%%" % (id)
        pushbutton = progress1_pbs.AddWidget(nb_buttons)
        nb_buttons = nb_buttons + 1
        pushbutton.SetText(buffer)
        buffer = "SetNthValue 2 %d" % (id)
        pushbutton.SetCommand(progress1, buffer)

    # Add a special button that will iterate from 0 to 100% in Tcl
    
    pushbutton = progress1_pbs.AddWidget(1000)
    pushbutton.SetText("Set primary from 0% to 100%")
    
    buffer = "for {set i 0} {$i <= 100} {incr i} { %s SetValue $i ; after 20; update}" % (progress1.GetTclName())
    pushbutton.SetCommand(None, buffer)

    app.Script(
        "pack %s -side top -anchor nw -expand n -padx 2 -pady 6",
        progress1_pbs.GetWidgetName())


    # TODO: add callbacks

    return "TypeComposite"