Changeset 1342 for trunk/gui/scripts/imageentry.tcl
- Timestamp:
- Mar 18, 2009, 2:59:21 PM (16 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/gui/scripts/imageentry.tcl
r437 r1342 47 47 itcl::body Rappture::ImageEntry::constructor {owner path args} { 48 48 if {[catch {$owner isa Rappture::ControlOwner} valid] != 0 || !$valid} { 49 49 error "bad object \"$owner\": should be Rappture::ControlOwner" 50 50 } 51 51 set _owner $owner … … 57 57 # 58 58 itk_component add image { 59 59 ::label $itk_interior.image -borderwidth 0 60 60 } 61 61 pack $itk_component(image) -expand yes -fill both … … 64 64 set str [$_owner xml get $path.current] 65 65 if {[string length $str] == 0} { 66 66 set str [$_owner xml get $path.default] 67 67 } 68 68 if {[string length $str] > 0} { 69 69 value $str 70 70 } 71 71 … … 94 94 set i [lsearch -exact $args -check] 95 95 if {$i >= 0} { 96 97 96 set onlycheck 1 97 set args [lreplace $args $i $i] 98 98 } 99 99 100 100 if {[llength $args] == 1} { 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 101 if {$onlycheck} { 102 # someday we may add validation... 103 return 104 } 105 set newval [lindex $args 0] 106 if {[string length $newval] > 0} { 107 set imh [image create photo -data $newval] 108 } else { 109 set imh "" 110 } 111 112 if {$_imh != ""} { 113 image delete $_imh 114 } 115 set _imh $imh 116 _redraw 117 return $newval 118 118 119 119 } elseif {[llength $args] != 0} { 120 120 error "wrong # args: should be \"value ?-check? ?newval?\"" 121 121 } 122 122 … … 164 164 itcl::body Rappture::ImageEntry::_redraw {} { 165 165 if {"" == $_imh} { 166 167 166 $itk_component(image) configure -image "" 167 return 168 168 } 169 169 … … 174 174 set str [string trim [$_owner xml get $_path.resize]] 175 175 if {"" == $str} { 176 176 set str "none" 177 177 } 178 178 switch -glob -- $str { 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 179 auto { 180 if {$_resize == ""} { 181 set _resize [image create photo] 182 } 183 set w [winfo width $itk_component(image)] 184 set h [winfo height $itk_component(image)] 185 if {$w/double($iw) < $h/double($ih)} { 186 set h [expr {round($w/double($iw)*$ih)}] 187 } else { 188 set w [expr {round($h/double($ih)*$iw)}] 189 } 190 $_resize configure -width $w -height $h 191 blt::winop resample $_imh $_resize 192 $itk_component(image) configure -image $_resize 193 } 194 width=* - height=* { 195 if {$_resize == ""} { 196 set _resize [image create photo] 197 } 198 if {[regexp {^width=([0-9]+)$} $str match size]} { 199 set w $size 200 set h [expr {round($w*$ih/double($iw))}] 201 $_resize configure -width $w -height $h 202 blt::winop resample $_imh $_resize 203 $itk_component(image) configure -image $_resize \ 204 -width $w -height $h 205 } elseif {[regexp {^height=([0-9]+)$} $str match size]} { 206 set h $size 207 set w [expr {round($h*$iw/double($ih))}] 208 $_resize configure -width $w -height $h 209 blt::winop resample $_imh $_resize 210 $itk_component(image) configure -image $_resize \ 211 -width $w -height $h 212 } else { 213 $itk_component(image) configure -image $_imh 214 } 215 } 216 default { 217 $itk_component(image) configure -image $_imh 218 } 219 219 } 220 220 } … … 226 226 set valid {normal disabled} 227 227 if {[lsearch -exact $valid $itk_option(-state)] < 0} { 228 228 error "bad value \"$itk_option(-state)\": should be [join $valid {, }]" 229 229 } 230 230 $itk_component(image) configure -state $itk_option(-state)
Note: See TracChangeset
for help on using the changeset viewer.