Changeset 785
- Timestamp:
- Jul 19, 2007, 5:21:51 AM (17 years ago)
- Location:
- trunk/gui/scripts
- Files:
-
- 5 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/gui/scripts/htmlviewer.tcl
r773 r785 98 98 99 99 # ---------------------------------------------------------------------- 100 # USAGE: load <htmlText> ?- file<fileName>?100 # USAGE: load <htmlText> ?-in <fileName>? 101 101 # 102 102 # Clients use this to clear the contents and load a new string of … … 106 106 itcl::body Rappture::HTMLviewer::load {htmlText args} { 107 107 Rappture::getopts args params { 108 value - file""108 value -in "" 109 109 } 110 110 if {[llength $args] > 0} { 111 error "wrong # args: should be \"load text ?- filename?\""111 error "wrong # args: should be \"load text ?-in name?\"" 112 112 } 113 113 … … 118 118 $itk_component(html) parse $htmlText 119 119 120 if {"" != $params(-file) && [file exists $params(-file)]} { 121 lappend _dirlist [file dirname $params(-file)] 122 } 123 } 124 125 # ---------------------------------------------------------------------- 126 # USAGE: add <htmlText> ?-file <fileName>? 120 if {"" != $params(-in) && [file exists $params(-in)]} { 121 if {[file isdirectory $params(-in)]} { 122 lappend _dirlist $params(-in) 123 } else { 124 lappend _dirlist [file dirname $params(-in)] 125 } 126 } 127 $_dispatcher event -now !config 128 } 129 130 # ---------------------------------------------------------------------- 131 # USAGE: add <htmlText> ?-in <fileName>? 127 132 # 128 133 # Clients use this to add the <htmlText> to the bottom of the contents … … 131 136 itcl::body Rappture::HTMLviewer::add {htmlText args} { 132 137 Rappture::getopts args params { 133 value - file""138 value -in "" 134 139 } 135 140 if {[llength $args] > 0} { 136 error "wrong # args: should be \"add text ?- filename?\""141 error "wrong # args: should be \"add text ?-in name?\"" 137 142 } 138 143 139 144 $itk_component(html) parse $htmlText 140 145 141 if {"" != $params(-file) && [file exists $params(-file)]} { 142 lappend _dirlist [file dirname $params(-file)] 143 } 146 if {"" != $params(-in) && [file exists $params(-in)]} { 147 if {[file isdirectory $params(-in)]} { 148 lappend _dirlist $params(-in) 149 } else { 150 lappend _dirlist [file dirname $params(-in)] 151 } 152 } 153 $_dispatcher event -now !config 144 154 } 145 155 … … 151 161 # to pop up further information. If the <url> starts with http:// 152 162 # or https://, then it is used directly. Otherwise, it is treated 153 # as a relative file path and resolved with respect to the - file163 # as a relative file path and resolved with respect to the -in 154 164 # options passed into load/add. 155 165 # ---------------------------------------------------------------------- … … 305 315 # Used internally to convert a <fileName> to its corresponding image 306 316 # handle. If the <fileName> is relative, then it is loaded with 307 # respect to the paths given by the - fileoption for the load/add317 # respect to the paths given by the -in option for the load/add 308 318 # methods. Returns an image handle for the image within the file, 309 319 # or the broken image icon if anything goes wrong. -
trunk/gui/scripts/image.tcl
r127 r785 24 24 public method hints {{keyword ""}} 25 25 26 private variable _xmlobj "" ;# ref to lib obj with curve data 26 private variable _xmlobj "" ;# ref to lib obj with image data 27 private variable _path "" ;# path in _xmlobj where data sits 27 28 private variable _image "" ;# underlying image data 29 private variable _hints 28 30 } 29 31 … … 36 38 } 37 39 set _xmlobj $xmlobj 40 set _path $path 38 41 set data [string trim [$xmlobj get $path.current]] 39 42 if {[string length $data] == 0} { … … 42 45 set _image [image create photo -data $data] 43 46 } 47 48 set _hints(note) [string trim [$_xmlobj get $_path.note.contents]] 49 set _hints(tooldir) [$_xmlobj get tool.version.application.directory(tool)] 44 50 } 45 51 … … 59 65 # ---------------------------------------------------------------------- 60 66 itcl::body Rappture::Image::hints {{keyword ""}} { 61 return "" 67 if {$keyword != ""} { 68 if {[info exists _hints($keyword)]} { 69 return $_hints($keyword) 70 } 71 return "" 72 } 73 return [array get _hints] 62 74 } -
trunk/gui/scripts/imageresult.tcl
r767 r785 36 36 37 37 protected method _rebuild {args} 38 protected method _top image {}38 protected method _top {what} 39 39 protected method _zoom {option args} 40 40 protected method _move {option args} … … 63 63 max 1.0 64 64 current 1.0 65 default 1 65 66 x 0 66 67 y 0 … … 70 71 pack propagate $itk_component(hull) no 71 72 73 Rappture::Panes $itk_interior.panes -sashwidth 1 -sashrelief solid -sashpadding 2 74 pack $itk_interior.panes -expand yes -fill both 75 set main [$itk_interior.panes pane 0] 76 $itk_interior.panes fraction 0 1 77 72 78 itk_component add controls { 73 frame $ itk_interior.cntls79 frame $main.cntls 74 80 } { 75 81 usual … … 122 128 123 129 itk_component add image { 124 label $ itk_interior.image -image $_image(final)130 label $main.image -image $_image(final) 125 131 } { 126 132 keep -background -foreground -cursor -font … … 140 146 bind $itk_component(image) <ButtonRelease-1> \ 141 147 [itcl::code $this _move release %x %y] 148 149 # 150 # Add area at the bottom for notes. 151 # 152 set notes [$itk_interior.panes insert end -fraction 0.15] 153 $itk_interior.panes visibility 1 off 154 Rappture::Scroller $notes.scr -xscrollmode auto -yscrollmode auto 155 pack $notes.scr -expand yes -fill both 156 itk_component add notes { 157 Rappture::HTMLviewer $notes.scr.html 158 } 159 $notes.scr contents $notes.scr.html 142 160 143 161 eval itk_initialize $args … … 287 305 } 288 306 now { 289 set top [_top image]307 set top [_top image] 290 308 if {$top == ""} { 291 309 return "" … … 331 349 } 332 350 } 333 if {$_scale(current) == "?"} { 334 _zoom reset 351 if {$_scale(current) == "?" || $_scale(default)} { 352 set _scale(current) $_scale(max) 353 set _scale(x) 0 354 set _scale(y) 0 335 355 } 336 356 … … 343 363 $_image(final) put $bg -to 0 0 $w $h 344 364 345 set imh [_top image]365 set imh [_top image] 346 366 if {$imh != ""} { 347 367 if {$_scale(current) <= 1.0} { … … 369 389 } 370 390 } 371 } 372 373 # ---------------------------------------------------------------------- 374 # USAGE: _topimage 391 392 set note [_top note] 393 if {[string length $note] > 0} { 394 if {[regexp {^html://} $note]} { 395 set note [string range $note 7 end] 396 } else { 397 regexp {&} $note {\007} note 398 regexp {<} $note {\<} note 399 regexp {>} $note {\>} note 400 regexp {\007} $note {\&} note 401 regexp "\n\n" $note {<br/>} note 402 set note "<html><body>$note</body></html>" 403 } 404 set notes [$itk_interior.panes pane 1] 405 $itk_component(notes) load $note -in [file join [_top tooldir] docs] 406 $itk_interior.panes visibility 1 on 407 } else { 408 $itk_interior.panes visibility 1 off 409 } 410 } 411 412 # ---------------------------------------------------------------------- 413 # USAGE: _top image|note|tooldir 375 414 # 376 415 # Used internally to get the topmost image currently being displayed. 377 416 # ---------------------------------------------------------------------- 378 itcl::body Rappture::ImageResult::_top image {} {417 itcl::body Rappture::ImageResult::_top {option} { 379 418 set top $_topmost 380 419 if {"" == $top} { … … 382 421 } 383 422 if {"" != $top} { 384 return [$top tkimage] 423 switch -- $option { 424 image { return [$top tkimage] } 425 note { return [$top hints note] } 426 tooldir { return [$top hints tooldir] } 427 default { error "bad option \"$option\": should be image, note, tooldir" } 428 } 385 429 } 386 430 return "" … … 418 462 reset { 419 463 set _scale(current) $_scale(max) 464 set _scale(default) 1 420 465 set _scale(x) 0 421 466 set _scale(y) 0 … … 423 468 in { 424 469 set _scale(current) [expr {$_scale(current)*0.5}] 470 set _scale(default) 0 425 471 } 426 472 out { … … 442 488 } 443 489 } 490 set _scale(default) 0 444 491 } 445 492 } -
trunk/gui/scripts/note.tcl
r761 r785 150 150 set html "<html><body><p>[_escapeChars $html]</p></body></html>" 151 151 } 152 $itk_component(html) load $html - file$file152 $itk_component(html) load $html -in $file 153 153 } 154 154 default { -
trunk/gui/scripts/panes.tcl
r428 r785 33 33 public method insert {pos args} 34 34 public method pane {pos} 35 public method visibility {pos {newval ""}} 35 36 public method fraction {pos {newval ""}} 36 37 public method hilite {state sash} … … 44 45 private variable _dispatcher "" ;# dispatcher for !events 45 46 private variable _panes "" ;# list of pane frames 47 private variable _visibility "" ;# list of visibilities for panes 46 48 private variable _counter 0 ;# counter for auto-generated names 47 private variable _frac 1.0 ;# list of fractions49 private variable _frac 0.0 ;# list of fractions 48 50 } 49 51 … … 74 76 75 77 lappend _panes $pname 78 lappend _visibility 1 79 set _frac 0.5 76 80 77 81 eval itk_initialize $args … … 128 132 frame $itk_interior.$pname 129 133 } 130 lappend _panes $pname 131 132 # fix the fractional sizes 133 set f $params(-fraction) 134 set _frac [list [expr {1-$f}] $f] 134 set _panes [linsert $_panes $pos $pname] 135 set _visibility [linsert $_visibility $pos 1] 136 set _frac [linsert $_frac $pos $params(-fraction)] 135 137 136 138 # fix sash characteristics … … 157 159 158 160 # ---------------------------------------------------------------------- 161 # USAGE: visibility <pos> ?<newval>? 162 # 163 # Clients use this to get/set the visibility of the pane at position 164 # <pos>. 165 # ---------------------------------------------------------------------- 166 itcl::body Rappture::Panes::visibility {pos {newval ""}} { 167 if {"" == $newval} { 168 return [lindex $_visibility $pos] 169 } 170 if {![string is boolean $newval]} { 171 error "bad value \"$newval\": should be boolean" 172 } 173 if {$pos == "end" || ($pos >= 0 && $pos < [llength $_visibility])} { 174 set _visibility [lreplace $_visibility $pos $pos [expr {$newval}]] 175 $_dispatcher event -idle !layout 176 } else { 177 error "bad index \"$pos\": out of range" 178 } 179 } 180 181 # ---------------------------------------------------------------------- 159 182 # USAGE: fraction <pos> ?<newval>? 160 183 # … … 170 193 } 171 194 if {$pos == "end" || ($pos >= 0 && $pos < [llength $_frac])} { 172 # if there are other panes, adjust their size according to this 173 if {[llength $_frac] > 1} { 174 set oldval [lindex $_frac $pos] 175 set delta [expr {double($oldval-$newval)/([llength $_frac]-1)}] 176 for {set i 0} {$i < [llength $_frac]} {incr i} { 177 set v [lindex $_frac $i] 178 set _frac [lreplace $_frac $i $i [expr {$v+$delta}]] 179 } 180 } 181 set _frac [lreplace $_frac $pos $pos $newval] 195 set len [llength $_frac] 196 set _frac [lreplace $_frac $pos $pos xxx] 197 set total 0 198 foreach f $_frac { 199 if {"xxx" != $f} { 200 set total [expr {$total+$f}] 201 } 202 } 203 for {set i 0} {$i < $len} {incr i} { 204 set f [lindex $_frac $i] 205 if {"xxx" == $f} { 206 set f $newval 207 } else { 208 set f [expr {$f/$total - $newval/double($len-1)}] 209 } 210 set _frac [lreplace $_frac $i $i $f] 211 } 182 212 $_dispatcher event -idle !layout 183 213 } else { … … 243 273 set frac 0.95 244 274 } 245 246 set _frac [list $frac [expr {1-$frac}]] 275 if {[llength $_frac] == 2} { 276 set _frac [list $frac [expr {1-$frac}]] 277 } else { 278 set i [expr {[lsearch $_panes $pname]-1}] 279 if {$i >= 0} { 280 set _frac [lreplace $_frac $i $i $frac] 281 } 282 } 247 283 _fixLayout 248 284 … … 267 303 itcl::body Rappture::Panes::_fixLayout {args} { 268 304 set h [winfo height $itk_component(hull)] 269 foreach p [lrange $_panes 1 end] { 270 set h [expr {$h - [winfo height $itk_component(${p}sash)]}] 271 } 272 305 306 set plist "" 307 set flist "" 308 foreach p $_panes f $_frac v $_visibility { 309 set sash ${p}sash 310 if {$v} { 311 # this pane is visible -- make room for it 312 lappend plist $p 313 lappend flist $f 314 if {[info exists itk_component($sash)]} { 315 set h [expr {$h - [winfo height $itk_component($sash)]}] 316 } 317 } else { 318 # this pane is not visible -- remove sash 319 if {[info exists itk_component($sash)]} { 320 place forget $itk_component($sash) 321 } 322 place forget $itk_component($p) 323 } 324 } 325 326 # normalize the fractions so they add up to 1 327 set total 0 328 foreach f $flist { set total [expr {$total+$f}] } 329 set newflist "" 330 foreach f $flist { 331 lappend newflist [expr {double($f)/$total}] 332 } 333 set flist $newflist 334 335 # lay out the various panes 273 336 set y 0 274 foreach p $ _panes f $_frac{337 foreach p $plist f $flist { 275 338 set sash ${p}sash 276 339 if {[info exists itk_component($sash)]} {
Note: See TracChangeset
for help on using the changeset viewer.