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

Last change on this file since 551 was 464, checked in by mmc, 18 years ago

Added popup options for the "download" button. Right now this works
only for <curve> objects. You can select between CSV and PDF output.
Will add other formats later.

Fixed a few "after cancel" errors that were happening when you switch
between inputs in the structure demo.

Fixed the colors and fonts for the new bug report window.

File size: 6.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-*-*-120-* widgetDefault
18option add *ValueResult.boldFont \
19    -*-helvetica-bold-r-normal-*-*-120-* widgetDefault
20
21itcl::class Rappture::ValueResult {
22    inherit itk::Widget
23
24    constructor {args} { # defined below }
25
26    public method add {dataobj {settings ""}}
27    public method get {}
28    public method delete {args}
29    public method scale {args}
30    public method download {option args}
31
32    set _dataobj ""  ;# data object currently being displayed
33}
34                                                                               
35itk::usual ValueResult {
36    keep -background -foreground -cursor -font
37}
38
39# ----------------------------------------------------------------------
40# CONSTRUCTOR
41# ----------------------------------------------------------------------
42itcl::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
56
57    eval itk_initialize $args
58}
59
60# ----------------------------------------------------------------------
61# USAGE: add <dataobj> ?<settings>?
62#
63# Clients use this to add a data object to the plot.  If the optional
64# <settings> are specified, then the are applied to the data.  Allowed
65# settings are -color and -brightness, -width, -linestyle and -raise.
66# (Many of these are ignored.)
67# ----------------------------------------------------------------------
68itcl::body Rappture::ValueResult::add {dataobj {settings ""}} {
69    array set params {
70        -color ""
71        -brightness ""
72        -width ""
73        -linestyle ""
74        -raise ""
75        -description ""
76    }
77    foreach {opt val} $settings {
78        if {![info exists params($opt)]} {
79            error "bad setting \"$opt\": should be [join [lsort [array names params]] {, }]"
80        }
81        set params($opt) $val
82    }
83    if {$params(-color) == "auto" || $params(-color) == "autoreset"} {
84        # can't handle -autocolors yet
85        set params(-color) black
86    }
87
88    $itk_component(label) configure -text ""
89    $itk_component(value) configure -text ""
90
91    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
98        # find the value and assign it with the proper coloring
99        if {"" != $params(-color) && "" != $params(-brightness)
100              && $params(-brightness) != 0} {
101            set params(-color) [Rappture::color::brightness \
102                $params(-color) $params(-brightness)]
103        }
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
112}
113
114# ----------------------------------------------------------------------
115# USAGE: get
116#
117# Clients use this to query the list of objects being plotted, in
118# order from bottom to top of this result.
119# ----------------------------------------------------------------------
120itcl::body Rappture::ValueResult::get {} {
121    return $_dataobj
122}
123
124# ----------------------------------------------------------------------
125# USAGE: delete ?<curve1> <curve2> ...?
126#
127# Clients use this to delete a curve from the plot.  If no curves
128# are specified, then all curves are deleted.
129# ----------------------------------------------------------------------
130itcl::body Rappture::ValueResult::delete {args} {
131    $itk_component(label) configure -text ""
132    $itk_component(value) configure -text ""
133    set _dataobj ""
134}
135
136# ----------------------------------------------------------------------
137# USAGE: scale ?<curve1> <curve2> ...?
138#
139# Sets the default limits for the overall plot according to the
140# limits of the data for all of the given <curve> objects.  This
141# accounts for all curves--even those not showing on the screen.
142# Because of this, the limits are appropriate for all curves as
143# the user scans through data in the ResultSet viewer.
144# ----------------------------------------------------------------------
145itcl::body Rappture::ValueResult::scale {args} {
146    # nothing to do for values
147}
148
149# ----------------------------------------------------------------------
150# USAGE: download coming
151# USAGE: download controls <downloadCommand>
152# USAGE: download now
153#
154# Clients use this method to create a downloadable representation
155# of the plot.  Returns a list of the form {ext string}, where
156# "ext" is the file extension (indicating the type of data) and
157# "string" is the data itself.
158# ----------------------------------------------------------------------
159itcl::body Rappture::ValueResult::download {option args} {
160    switch $option {
161        coming {
162            # nothing to do
163        }
164        controls {
165            # no controls for this download yet
166            return ""
167        }
168        now {
169            set lstr [$itk_component(label) cget -text]
170            set vstr [$itk_component(value) cget -text]
171            return [list .txt "$lstr $vstr"]
172        }
173        default {
174            error "bad option \"$option\": should be coming, controls, now"
175        }
176    }
177}
Note: See TracBrowser for help on using the repository browser.