Changeset 761 for trunk/gui/scripts/valueresult.tcl
- Timestamp:
- Jun 8, 2007, 5:16:22 PM (17 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/gui/scripts/valueresult.tcl
r676 r761 16 16 option add *ValueResult.font \ 17 17 -*-helvetica-medium-r-normal-*-12-* widgetDefault 18 option add *ValueResult.boldFont \19 -*-helvetica-bold-r-normal-*-12-* widgetDefault20 18 21 19 itcl::class Rappture::ValueResult { … … 30 28 public method download {option args} 31 29 32 set _dataobj "" ;# data object currently being displayed 30 protected method _rebuild {} 31 32 private variable _dispatcher "" ;# dispatcher for !events 33 34 private variable _dlist "" ;# list of data objects being displayed 35 private variable _dobj2color ;# maps data object => color 36 private variable _dobj2raise ;# maps data object => raise flag 0/1 37 private variable _dobj2desc ;# maps data object => description 33 38 } 34 39 … … 41 46 # ---------------------------------------------------------------------- 42 47 itcl::body Rappture::ValueResult::constructor {args} { 43 itk_component add label { 44 label $itk_interior.l 45 } 46 pack $itk_component(label) -side left 47 48 itk_component add value { 49 label $itk_interior.value -anchor w 50 } { 51 usual 52 rename -font -boldfont boldFont Font 53 ignore -foreground 54 } 55 pack $itk_component(value) -side left -expand yes -fill both 48 Rappture::dispatcher _dispatcher 49 $_dispatcher register !rebuild 50 $_dispatcher dispatch $this !rebuild "[itcl::code $this _rebuild]; list" 51 52 itk_component add scroller { 53 Rappture::Scroller $itk_interior.scroller \ 54 -xscrollmode auto -yscrollmode auto 55 } 56 pack $itk_component(scroller) -expand yes -fill both 57 58 itk_component add html { 59 Rappture::HTMLviewer $itk_component(scroller).html 60 } 61 $itk_component(scroller) contents $itk_component(html) 56 62 57 63 eval itk_initialize $args … … 69 75 array set params { 70 76 -color "" 71 -brightness ""77 -brightness 0 72 78 -width "" 73 79 -linestyle "" 74 -raise ""80 -raise 0 75 81 -description "" 76 82 } … … 86 92 } 87 93 88 $itk_component(label) configure -text ""89 $itk_component(value) configure -text ""90 91 94 if {"" != $dataobj} { 92 set label [$dataobj get about.label]93 if {"" != $label && [string index $label end] != ":"} {94 append label ":"95 }96 $itk_component(label) configure -text $label97 98 95 # find the value and assign it with the proper coloring 99 96 if {"" != $params(-color) && "" != $params(-brightness) … … 102 99 $params(-color) $params(-brightness)] 103 100 } 104 if {$params(-color) != ""} { 105 $itk_component(value) configure -foreground $params(-color) 106 } else { 107 $itk_component(value) configure -foreground $itk_option(-foreground) 108 } 109 $itk_component(value) configure -text [$dataobj get current] 110 } 111 set _dataobj $dataobj 101 102 set pos [lsearch -exact $dataobj $_dlist] 103 if {$pos < 0} { 104 lappend _dlist $dataobj 105 set _dobj2color($dataobj) $params(-color) 106 set _dobj2raise($dataobj) $params(-raise) 107 set _dobj2desc($dataobj) $params(-description) 108 $_dispatcher event -idle !rebuild 109 } 110 } 112 111 } 113 112 … … 119 118 # ---------------------------------------------------------------------- 120 119 itcl::body Rappture::ValueResult::get {} { 121 return $_dataobj 120 # put the dataobj list in order according to -raise options 121 set dlist $_dlist 122 foreach obj $dlist { 123 if {[info exists _dobj2raise($obj)] && $_dobj2raise($obj)} { 124 set i [lsearch -exact $dlist $obj] 125 if {$i >= 0} { 126 set dlist [lreplace $dlist $i $i] 127 lappend dlist $obj 128 } 129 } 130 } 131 return $dlist 122 132 } 123 133 … … 129 139 # ---------------------------------------------------------------------- 130 140 itcl::body Rappture::ValueResult::delete {args} { 131 $itk_component(label) configure -text "" 132 $itk_component(value) configure -text "" 133 set _dataobj "" 141 if {[llength $args] == 0} { 142 set args $_dlist 143 } 144 145 # delete all specified objects 146 set changed 0 147 foreach obj $args { 148 set pos [lsearch -exact $_dlist $obj] 149 if {$pos >= 0} { 150 set _dlist [lreplace $_dlist $pos $pos] 151 catch {unset _dobj2color($obj)} 152 catch {unset _dobj2raise($obj)} 153 catch {unset _dobj2desc($obj)} 154 set changed 1 155 } 156 } 157 158 # if anything changed, then rebuild the plot 159 if {$changed} { 160 $_dispatcher event -idle !rebuild 161 } 134 162 } 135 163 … … 167 195 } 168 196 now { 169 set lstr [$itk_component(label) cget -text] 170 set vstr [$itk_component(value) cget -text] 171 return [list .txt "$lstr $vstr"] 197 if {[llength $_dlist] == 1} { 198 set lstr [$_dlist get about.label] 199 set mesg "$lstr [$_dlist get current]" 200 } else { 201 set mesg "" 202 foreach obj $_dlist { 203 set lstr [$obj get about.label] 204 append mesg "$lstr [$obj get current]\n" 205 if {[string length $_dobj2desc($obj)] > 0} { 206 foreach line [split $_dobj2desc($obj) \n] { 207 append mesg " * $line\n" 208 } 209 append mesg "\n" 210 } 211 } 212 } 213 return [list .txt $mesg] 172 214 } 173 215 default { … … 176 218 } 177 219 } 220 221 # ---------------------------------------------------------------------- 222 # USAGE: _rebuild 223 # 224 # Used internally to rebuild the contents of this widget 225 # whenever the data within it changes. Shows the value 226 # for the topmost data object in its associated color. 227 # ---------------------------------------------------------------------- 228 itcl::body Rappture::ValueResult::_rebuild {} { 229 set html "<html><body>" 230 231 set obj [lindex $_dlist 0] 232 if {"" != $obj} { 233 set label [$obj get about.label] 234 if {"" != $label && [string index $label end] != ":"} { 235 append label ":" 236 } 237 append html "<h3>$label</h3>\n" 238 } 239 240 foreach obj $_dlist { 241 if {$_dobj2raise($obj)} { 242 set bold0 "<b>" 243 set bold1 "</b>" 244 set bg "background:#ffffcc; border:1px solid #cccccc;" 245 } else { 246 set bold0 "" 247 set bold1 "" 248 set bg "" 249 } 250 if {$_dobj2color($obj) != ""} { 251 set color0 "<font style=\"color: $_dobj2color($obj)\">" 252 set color1 "</font>" 253 } else { 254 set color0 "" 255 set color1 "" 256 } 257 258 append html "<div style=\"margin:8px; padding:4px; $bg\">${bold0}${color0}[$obj get current]${color1}${bold1}" 259 if {$_dobj2raise($obj) && [string length $_dobj2desc($obj)] > 0} { 260 foreach line [split $_dobj2desc($obj) \n] { 261 append html "<li style=\"margin-left:12px;\">$line</li>\n" 262 } 263 } 264 append html "</div>" 265 } 266 append html "</body></html>" 267 $itk_component(html) load $html 268 }
Note: See TracChangeset
for help on using the changeset viewer.