body test

class test {
 inherit itk::Widget
 public method aaa
 public method rollover
 public method rolloutof
 public method showStage
 private variable current_stage "hull"
 
 constructor { args } {
  itk_option add hull.width hull.height
  $itk_component(hull) configure -width 1050 -height 768 
  wm minsize [winfo toplevel $itk_component(hull)] 1050 768
  pack propagate $itk_interior 0
  
  
  itk_component add body {
      frame $itk_component(hull).body \
   -borderwidth 1 \
   -relief raised
  }
    
  itk_component add stages {
      canvas $itk_component(body).stages \
   -relief sunken \
   -bd 2 \
   -bg white \
   -width 100 \
   -highlightthickness 0
  }
  
  
  set l_stage_name(hull) "Images"
  set l_stage_name(indexing) "Indexing"
  set l_stage_name(strategy) "Strategy"
  set l_stage_name(cell_refinement) "Cell Refinement"
  set l_stage_name(integration) "Integration"
     # set l_stage_name(pointless) "Pointless"
  set l_stage_name(history) "History"
    
  set i_y 10
  foreach i_stage { hull indexing strategy cell_refinement integration  history} {
      $itk_component(stages) create rectangle \
   -5 $i_y 105 [expr $i_y + 5 + 32 + 14 + 5] \
   -fill {} \
   -outline {} \
   -tags box($i_stage)
      $itk_component(stages) create image 50 [expr $i_y + 5] \
   -image ::img::stage_${i_stage} \
   -anchor n \
   -tags icon($i_stage)
      $itk_component(stages) create text 50 [expr $i_y + 5 + 32] \
   -text $l_stage_name($i_stage) \
   -anchor n \
   -tags label($i_stage)
      $itk_component(stages) create rectangle \
   -5 $i_y 105 [expr $i_y + 5 + 32 + 14 + 5] \
   -fill {} \
   -outline {} \
   -tags overlay($i_stage)
      $itk_component(stages) bind overlay($i_stage) <Enter> \
   [code $this rollover $i_stage]
      $itk_component(stages) bind overlay($i_stage) <Leave> \
   [code $this rolloutof $i_stage]
      $itk_component(stages) bind overlay($i_stage) <1> \
   [code $this showStage $i_stage]
      set i_y [expr $i_y + 5 + 32 + 10 + 5 + 10]
  }
  

  pack $itk_component(body) -side top -fill both -expand 1
  grid $itk_component(stages) -row 0 -column 0
  
 } 
}


body test::rolloutof { a_stage } {
    # Undshades stage button (if not already current stage or disabled)
    if {$a_stage != $current_stage} {
 if {[$itk_component(stages) itemcget icon($a_stage) -image] != "::img::stage_${a_stage}_haze"} {
     $itk_component(stages) itemconfigure box($a_stage) \
  -fill {} \
  -outline {}
 }
    }
}


body test::rollover { a_stage } {
    # Shades stage button (if not already current stage or disabled)
    if {$a_stage != $current_stage} {
 if {[$itk_component(stages) itemcget icon($a_stage) -image] != "::img::stage_${a_stage}_haze"} {
     $itk_component(stages) itemconfigure box($a_stage) \
  -fill "\#eeeeee" \
  -outline "\#dcdcdc"
 }
    }
}


body test::showStage { a_stage } {
    # Send focus to stages menu, to force SettingEntry update
    focus $itk_component(stages)

    # Restore current stage's icon to unselected state
    $itk_component(stages) itemconfigure box($current_stage) \
 -fill {} \
 -outline {}

    # hide current stage
    $itk_component($current_stage) hide

    # Store previous stage (in case of reversion)
    set previous_state $current_stage

    # update the record of current stage
    set current_stage $a_stage

    # Update new stage's icon
    $itk_component(stages) itemconfigure box($current_stage) \
 -fill "\#dcdcdc" \
 -outline "\#bbbbbb"


    # display the panel
    $itk_component($a_stage) launch

#added by luke on 18 October 2007
#puts focus on the image selection box in the integration stage
 if {$a_stage == "integration"} {
#  focus .c.body.integration.normal.isf.inf.in.entry.p.f.entry
#  focus [[[$itk_component($a_stage) component image_numbers] component entry] component entry]  
 }


}


body test::aaa { } {
 
}

test .c
.c aaa
pack .c

原文地址:https://www.cnblogs.com/greencolor/p/2123331.html