source: trunk/gui/scripts/valueresult.tcl @ 761

Last change on this file since 761 was 761, checked in by mmc, 17 years ago

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 size: 9.1 KB
Line 
1# ----------------------------------------------------------------------
2#  COMPONENT: ValueResult - Log output for ResultSet
3#
4#  This widget is used to show text output in a ResultSet.  The log
5#  output from a tool, for example, is rendered as a ValueResult.
6# ======================================================================
7#  AUTHOR:  Michael McLennan, Purdue University
8#  Copyright (c) 2004-2005  Purdue Research Foundation
9#
10#  See the file "license.terms" for information on usage and
11#  redistribution of this file, and for a DISCLAIMER OF ALL WARRANTIES.
12# ======================================================================
13package require Itk
14package require BLT
15
16option add *ValueResult.font \
17    -*-helvetica-medium-r-normal-*-12-* widgetDefault
18
19itcl::class Rappture::ValueResult {
20    inherit itk::Widget
21
22    constructor {args} { # defined below }
23
24    public method add {dataobj {settings ""}}
25    public method get {}
26    public method delete {args}
27    public method scale {args}
28    public method download {option args}
29
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
38}
39                                                                               
40itk::usual ValueResult {
41    keep -background -foreground -cursor -font
42}
43
44# ----------------------------------------------------------------------
45# CONSTRUCTOR
46# ----------------------------------------------------------------------
47itcl::body Rappture::ValueResult::constructor {args} {
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)
62
63    eval itk_initialize $args
64}
65
66# ----------------------------------------------------------------------
67# USAGE: add <dataobj> ?<settings>?
68#
69# Clients use this to add a data object to the plot.  If the optional
70# <settings> are specified, then the are applied to the data.  Allowed
71# settings are -color and -brightness, -width, -linestyle and -raise.
72# (Many of these are ignored.)
73# ----------------------------------------------------------------------
74itcl::body Rappture::ValueResult::add {dataobj {settings ""}} {
75    array set params {
76        -color ""
77        -brightness 0
78        -width ""
79        -linestyle ""
80        -raise 0
81        -description ""
82    }
83    foreach {opt val} $settings {
84        if {![info exists params($opt)]} {
85            error "bad setting \"$opt\": should be [join [lsort [array names params]] {, }]"
86        }
87        set params($opt) $val
88    }
89    if {$params(-color) == "auto" || $params(-color) == "autoreset"} {
90        # can't handle -autocolors yet
91        set params(-color) black
92    }
93
94    if {"" != $dataobj} {
95        # find the value and assign it with the proper coloring
96        if {"" != $params(-color) && "" != $params(-brightness)
97              && $params(-brightness) != 0} {
98            set params(-color) [Rappture::color::brightness \
99                $params(-color) $params(-brightness)]
100        }
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    }
111}
112
113# ----------------------------------------------------------------------
114# USAGE: get
115#
116# Clients use this to query the list of objects being plotted, in
117# order from bottom to top of this result.
118# ----------------------------------------------------------------------
119itcl::body Rappture::ValueResult::get {} {
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
132}
133
134# ----------------------------------------------------------------------
135# USAGE: delete ?<curve1> <curve2> ...?
136#
137# Clients use this to delete a curve from the plot.  If no curves
138# are specified, then all curves are deleted.
139# ----------------------------------------------------------------------
140itcl::body Rappture::ValueResult::delete {args} {
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    }
162}
163
164# ----------------------------------------------------------------------
165# USAGE: scale ?<curve1> <curve2> ...?
166#
167# Sets the default limits for the overall plot according to the
168# limits of the data for all of the given <curve> objects.  This
169# accounts for all curves--even those not showing on the screen.
170# Because of this, the limits are appropriate for all curves as
171# the user scans through data in the ResultSet viewer.
172# ----------------------------------------------------------------------
173itcl::body Rappture::ValueResult::scale {args} {
174    # nothing to do for values
175}
176
177# ----------------------------------------------------------------------
178# USAGE: download coming
179# USAGE: download controls <downloadCommand>
180# USAGE: download now
181#
182# Clients use this method to create a downloadable representation
183# of the plot.  Returns a list of the form {ext string}, where
184# "ext" is the file extension (indicating the type of data) and
185# "string" is the data itself.
186# ----------------------------------------------------------------------
187itcl::body Rappture::ValueResult::download {option args} {
188    switch $option {
189        coming {
190            # nothing to do
191        }
192        controls {
193            # no controls for this download yet
194            return ""
195        }
196        now {
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]
214        }
215        default {
216            error "bad option \"$option\": should be coming, controls, now"
217        }
218    }
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# ----------------------------------------------------------------------
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 TracBrowser for help on using the repository browser.