Ignore:
Timestamp:
Jun 8, 2007, 5:16:22 PM (17 years ago)
Author:
mmc
Message:

Added a new <note> object which can be used to add annotations to
the input side. Each <note> has a <contents> area which contains
a url for a web site or a file. All file urls are treated as
relative to the "docs" directory where the tool.xml is located.

Fixed the output for <number>, <integer>, <boolean>, and <choice>
so that it shows multiple values when "All" is pressed, and it
highlights the current value. Also fixed the download option for
this widget so that it works properly.

Fixed the energy level viewer so that its download option works.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/gui/scripts/valueresult.tcl

    r676 r761  
    1616option add *ValueResult.font \
    1717    -*-helvetica-medium-r-normal-*-12-* widgetDefault
    18 option add *ValueResult.boldFont \
    19     -*-helvetica-bold-r-normal-*-12-* widgetDefault
    2018
    2119itcl::class Rappture::ValueResult {
     
    3028    public method download {option args}
    3129
    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
    3338}
    3439                                                                               
     
    4146# ----------------------------------------------------------------------
    4247itcl::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)
    5662
    5763    eval itk_initialize $args
     
    6975    array set params {
    7076        -color ""
    71         -brightness ""
     77        -brightness 0
    7278        -width ""
    7379        -linestyle ""
    74         -raise ""
     80        -raise 0
    7581        -description ""
    7682    }
     
    8692    }
    8793
    88     $itk_component(label) configure -text ""
    89     $itk_component(value) configure -text ""
    90 
    9194    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 $label
    97 
    9895        # find the value and assign it with the proper coloring
    9996        if {"" != $params(-color) && "" != $params(-brightness)
     
    10299                $params(-color) $params(-brightness)]
    103100        }
    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    }
    112111}
    113112
     
    119118# ----------------------------------------------------------------------
    120119itcl::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
    122132}
    123133
     
    129139# ----------------------------------------------------------------------
    130140itcl::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    }
    134162}
    135163
     
    167195        }
    168196        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]
    172214        }
    173215        default {
     
    176218    }
    177219}
     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# ----------------------------------------------------------------------
     228itcl::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.