::namespace eval ::QW::WIDGET {} # ------------------------------------------------------------ # QW::WIDGET::COMPLETION class # ------------------------------------------------------------ #2.32.2 linux ::if {$::qw::control(tk_is_enabled)} { # check on tk_is_enabled added 2.34.0 ::package require $::qw::control(package_itk); ::package require $::qw::control(package_iwidgets); } ::itcl::class QW::WIDGET::COMPLETION_PERCENTAGE { inherit ::itk::Widget protected variable _options ""; protected variable _canvas ""; method option_get {Path} {::return [::sargs::get_poly $_options $Path];} method option_set {args} { ::qw::s_args_marshal; ::sargs::var::+= _options $s_args; } constructor {args} { ::switch -- $::tcl_version { 8.4 { ::set _options [::sargs::+= $::qw::widget::options [::subst { .background [$itk_interior cget -background] /incomplete { .background tomato } /complete { .background green } }]]; } 8.6 { /* { 2.28.0 - pgq said colours were too dark in 8.6 */ } ::set _options [::sargs::+= $::qw::widget::options [::subst { .background [$itk_interior cget -background] /incomplete { .background red } /complete { .background lawngreen } }]]; } } ::set _canvas [::canvas $itk_interior.canvas \ -borderwidth [option_get .border.width] \ -background [option_get .background] \ -highlightthickness 0 \ -relief [option_get .relief] \ -width 10 -height 10 \ ]; # -background "light steel blue" \ # 2.34.5 - added (changed) background above because white text not readable on windows 10 ::pack $_canvas -expand yes -fill both; # ::set Color [::option get $itk_interior color Color]; $_canvas create rectangle 0 0 0 0 -outline black -width 1 -fill [option_get /incomplete.background] -tags bar $_canvas create text 0 0 -anchor c -text "0%" -tags value -font [option_get .font]; ::bind $_canvas [::itcl::code $this redraw]; ::eval itk_initialize $args; } destructor { ::trace vdelete $itk_option(-valuevariable) w [::itcl::code $this value_changed]; ::trace vdelete $itk_option(-limitvariable) w [::itcl::code $this limit_changed]; } itk_option define -valuevariable valueVariable ValueVariable "" { ::trace variable $itk_option(-valuevariable) w [::itcl::code $this value_changed]; } itk_option define -limitvariable limitVariable LimitVariable "" { ::trace variable $itk_option(-limitvariable) w [::itcl::code $this limit_changed]; } method limit_changed {Name1 Name2 Op} { ::if {$_limit==[::set $itk_option(-limitvariable)]} {::return $this;} ::set _limit [::set $itk_option(-limitvariable)]; ::if {$_percentage==[percentage]} {::return $this;} ::set _percentage [percentage]; redraw; return $this; } method value_changed {Name1 Name2 Op} { ::if {$_value==[::set $itk_option(-valuevariable)]} {::return $this;} ::set _value [::set $itk_option(-valuevariable)]; ::if {$_percentage==[percentage]} {::return $this;} ::set _percentage [percentage]; redraw; return $this; } private variable _value 0.0; private variable _limit 0.0; private variable _percentage 0.0; private method percentage {} { ::if {$_limit==0.0} {::return 0;} ::if {$_value>=$_limit} {::return 100;} return [::expr int((1.0*$_value)/$_limit*100.0)]; } private method redraw {} { ::set Percentage [percentage]; ::if {$Percentage==100} {$_canvas itemconfigure bar -fill [option_get /complete.background];} ::if {$Percentage!=0} { $_canvas itemconfigure value -text [::format "%3.0f%%" $Percentage]; } else { $_canvas itemconfigure value -text ""; } ::set CanvasWidth [::winfo width $itk_interior]; ::set CanvasHeight [::winfo height $itk_interior]; $_canvas coords value [::expr 0.5*$CanvasWidth] [::expr 0.5*$CanvasHeight]; $_canvas coords bar 0 0 [::expr 0.01*$Percentage*$CanvasWidth] $CanvasHeight; ::update; return $this; } } # ------------------------------------------------------------ # QW::WIDGET::COMPLETION1 class # ------------------------------------------------------------ ::itcl::class QW::WIDGET::COMPLETION_PERCENTAGE1 { inherit ::itk::Widget protected variable _options ""; protected variable _canvas ""; protected variable _percent 0.0; protected variable _color 0.0; method option_get {Path} {::return [::sargs::get_poly $_options $Path];} method option_set {args} { ::qw::s_args_marshal; ::sargs::var::+= _options $s_args; } constructor {args} { ::qw::s_args_marshal; ::set args ""; ::switch -- $::tcl_version { 8.4 { ::set _options [::sargs::+= $::qw::widget::options [::subst { .foreground black .background [$itk_interior cget -background] /incomplete { .background tomato } /complete { .background green } }]]; } 8.6 { /* { 2.28.0 - pgq said colours were too dark in 8.6 */ } ::set _options [::sargs::+= $::qw::widget::options [::subst { .background [$itk_interior cget -background] /incomplete { .background red } /complete { .background lawngreen } }]]; } } ::sargs::var::+= _options $s_args; ::set _canvas [::canvas $itk_interior.canvas \ -borderwidth [option_get .border.width] \ -highlightthickness 0 \ -relief [option_get .relief] \ -width 10 -height 10 \ -background "light steel blue" \ ]; # 2.34.5 - added (changed) background above because white text not readable on windows 10 ::pack $_canvas -expand yes -fill both; # ::set Color [::option get $itk_interior color Color]; ::set _color [option_get /incomplete.background]; $_canvas create rectangle 0 0 0 0 -outline black -width 1 -fill $_color -tags bar # $_canvas create text 0 0 -anchor c -text "0%" -tags value -font [option_get .font]; $_canvas create text 0 0 \ -anchor c \ -text "0%" \ -tags value \ -font {-family Arial -size 9 -weight normal} \ -fill [option_get .foreground] \ ; /* { -outline [option_get .foreground] \ -activeoutline [option_get .foreground] \ -disabledoutline [option_get .foreground] \ */ } ::bind $_canvas [::itcl::code $this redraw]; ::eval itk_initialize $args; } method percent {{Percent ""}} { ::if {$Percent eq ""} { ::return $_percent; } ::set _percent [::expr {double($Percent)}]; redraw; return $this; } private method redraw {} { ::if {$_percent==100} { ::set _color [option_get /complete.background]; $_canvas itemconfigure bar -fill $_color; $_canvas itemconfigure value -fill black; } else { ::if {$_color ne [option_get /incomplete.background]} { ::set _color [option_get /incomplete.background]; $_canvas itemconfigure bar -fill $_color; } } ::if {$_percent!=0} { $_canvas itemconfigure value -text [::format "%3.0f%%" $_percent]; } else { $_canvas itemconfigure value -text ""; } ::set CanvasWidth [::winfo width $itk_interior]; ::set CanvasHeight [::winfo height $itk_interior]; $_canvas coords value [::expr 0.5*$CanvasWidth] [::expr 0.5*$CanvasHeight]; $_canvas coords bar 0 0 [::expr 0.01*$_percent*$CanvasWidth] $CanvasHeight; # ::update idletasks; } method width_set {Width} { $_canvas configure -width $Width; } method height_set {Height} { $_canvas configure -height $Height; } }