1 |
578 |
markom |
#
|
2 |
|
|
# Feedback
|
3 |
|
|
# ----------------------------------------------------------------------
|
4 |
|
|
# Implements a Feedback widget, to display feedback on the status of an
|
5 |
|
|
# process to the user. Display is given as a percentage and as a
|
6 |
|
|
# thermometer type bar. Options exist for adding a label and controlling its
|
7 |
|
|
# position.
|
8 |
|
|
#
|
9 |
|
|
# ----------------------------------------------------------------------
|
10 |
|
|
# AUTHOR: Kris Raney EMAIL: kraney@spd.dsccc.com
|
11 |
|
|
#
|
12 |
|
|
# @(#) $Id: feedback.itk,v 1.1.1.1 2002-01-16 10:24:50 markom Exp $
|
13 |
|
|
# ----------------------------------------------------------------------
|
14 |
|
|
# Copyright (c) 1996 DSC Technologies Corporation
|
15 |
|
|
# ======================================================================
|
16 |
|
|
# Permission to use, copy, modify, distribute and license this software
|
17 |
|
|
# and its documentation for any purpose, and without fee or written
|
18 |
|
|
# agreement with DSC, is hereby granted, provided that the above copyright
|
19 |
|
|
# notice appears in all copies and that both the copyright notice and
|
20 |
|
|
# warranty disclaimer below appear in supporting documentation, and that
|
21 |
|
|
# the names of DSC Technologies Corporation or DSC Communications
|
22 |
|
|
# Corporation not be used in advertising or publicity pertaining to the
|
23 |
|
|
# software without specific, written prior permission.
|
24 |
|
|
#
|
25 |
|
|
# DSC DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING
|
26 |
|
|
# ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, AND NON-
|
27 |
|
|
# INFRINGEMENT. THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, AND THE
|
28 |
|
|
# AUTHORS AND DISTRIBUTORS HAVE NO OBLIGATION TO PROVIDE MAINTENANCE,
|
29 |
|
|
# SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS. IN NO EVENT SHALL
|
30 |
|
|
# DSC BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR
|
31 |
|
|
# ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS,
|
32 |
|
|
# WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTUOUS ACTION,
|
33 |
|
|
# ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
|
34 |
|
|
# SOFTWARE.
|
35 |
|
|
# ======================================================================
|
36 |
|
|
|
37 |
|
|
# Acknowledgements:
|
38 |
|
|
#
|
39 |
|
|
# Special thanks go to Sam Shen(SLShen@lbl.gov), as this code is based on his
|
40 |
|
|
# feedback.tcl code from tk inspect. The original code is copyright 1995
|
41 |
|
|
# Lawrence Berkeley Laboratory.
|
42 |
|
|
#
|
43 |
|
|
# This software is copyright (C) 1994 by the Lawrence Berkeley Laboratory.
|
44 |
|
|
#
|
45 |
|
|
# Redistribution and use in source and binary forms, with or without
|
46 |
|
|
# modification, are permitted provided that: (1) source code distributions
|
47 |
|
|
# retain the above copyright notice and this paragraph in its entirety, (2)
|
48 |
|
|
# distributions including binary code include the above copyright notice and
|
49 |
|
|
# this paragraph in its entirety in the documentation or other materials
|
50 |
|
|
# provided with the distribution, and (3) all advertising materials mentioning
|
51 |
|
|
# features or use of this software display the following acknowledgement:
|
52 |
|
|
# ``This product includes software developed by the University of California,
|
53 |
|
|
# Lawrence Berkeley Laboratory and its contributors.'' Neither the name of
|
54 |
|
|
# the University nor the names of its contributors may be used to endorse
|
55 |
|
|
# or promote products derived from this software without specific prior
|
56 |
|
|
# written permission.
|
57 |
|
|
#
|
58 |
|
|
# THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR IMPLIED
|
59 |
|
|
# WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF
|
60 |
|
|
# MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
|
61 |
|
|
|
62 |
|
|
#
|
63 |
|
|
# Default resources.
|
64 |
|
|
#
|
65 |
|
|
option add *Feedback.borderWidth 2 widgetDefault
|
66 |
|
|
option add *Feedback.labelPos n widgetDefault
|
67 |
|
|
option add *Feedback.barHeight 20 widgetDefault
|
68 |
|
|
option add *Feedback.troughColor White widgetDefault
|
69 |
|
|
option add *Feedback.barColor Blue widgetDefault
|
70 |
|
|
|
71 |
|
|
#
|
72 |
|
|
# Usual options.
|
73 |
|
|
#
|
74 |
|
|
itk::usual Feedback {
|
75 |
|
|
keep -background -cursor -foreground
|
76 |
|
|
}
|
77 |
|
|
|
78 |
|
|
# ------------------------------------------------------------------
|
79 |
|
|
# FEEDBACK
|
80 |
|
|
# ------------------------------------------------------------------
|
81 |
|
|
class iwidgets::Feedback {
|
82 |
|
|
inherit iwidgets::Labeledwidget
|
83 |
|
|
|
84 |
|
|
constructor {args} {}
|
85 |
|
|
destructor {}
|
86 |
|
|
|
87 |
|
|
itk_option define -steps steps Steps 10
|
88 |
|
|
|
89 |
|
|
public {
|
90 |
|
|
method reset {}
|
91 |
|
|
method step {{inc 1}}
|
92 |
|
|
}
|
93 |
|
|
|
94 |
|
|
private {
|
95 |
|
|
method _display
|
96 |
|
|
|
97 |
|
|
variable _barwidth 0
|
98 |
|
|
variable _stepval 0
|
99 |
|
|
}
|
100 |
|
|
}
|
101 |
|
|
|
102 |
|
|
#
|
103 |
|
|
# Provide a lowercased access method for the Dialogshell class.
|
104 |
|
|
#
|
105 |
|
|
proc ::iwidgets::feedback {pathName args} {
|
106 |
|
|
uplevel ::iwidgets::Feedback $pathName $args
|
107 |
|
|
}
|
108 |
|
|
|
109 |
|
|
# ------------------------------------------------------------------
|
110 |
|
|
# CONSTRUCTOR
|
111 |
|
|
# ------------------------------------------------------------------
|
112 |
|
|
body iwidgets::Feedback::constructor {args} {
|
113 |
|
|
itk_component add trough {
|
114 |
|
|
frame $itk_interior.trough -relief sunken
|
115 |
|
|
} {
|
116 |
|
|
usual
|
117 |
|
|
keep -borderwidth
|
118 |
|
|
rename -background -troughcolor troughColor TroughColor
|
119 |
|
|
rename -height -barheight barHeight Height
|
120 |
|
|
}
|
121 |
|
|
|
122 |
|
|
itk_component add bar {
|
123 |
|
|
frame $itk_component(trough).bar -relief raised
|
124 |
|
|
} {
|
125 |
|
|
usual
|
126 |
|
|
keep -borderwidth
|
127 |
|
|
rename -background -barcolor barColor BarColor
|
128 |
|
|
rename -height -barheight barHeight Height
|
129 |
|
|
}
|
130 |
|
|
pack $itk_component(bar) -side left -fill y -anchor w
|
131 |
|
|
|
132 |
|
|
itk_component add percentage {
|
133 |
|
|
label $itk_interior.percentage -text "0%"
|
134 |
|
|
}
|
135 |
|
|
grid $itk_component(trough) -row 1 -column 0 -sticky sew -padx 2 -pady 2
|
136 |
|
|
grid $itk_component(percentage) -row 2 -column 0 -sticky nsew -padx 2 -pady 2
|
137 |
|
|
grid rowconfigure $itk_interior 0 -weight 1
|
138 |
|
|
grid rowconfigure $itk_interior 1 -weight 1
|
139 |
|
|
grid columnconfigure $itk_interior 0 -weight 1
|
140 |
|
|
|
141 |
|
|
eval itk_initialize $args
|
142 |
|
|
}
|
143 |
|
|
|
144 |
|
|
# ------------------------------------------------------------------
|
145 |
|
|
# DESTRUCTOR
|
146 |
|
|
# ------------------------------------------------------------------
|
147 |
|
|
body iwidgets::Feedback::destructor {} {
|
148 |
|
|
}
|
149 |
|
|
|
150 |
|
|
# ------------------------------------------------------------------
|
151 |
|
|
# OPTIONS
|
152 |
|
|
# ------------------------------------------------------------------
|
153 |
|
|
|
154 |
|
|
# ------------------------------------------------------------------
|
155 |
|
|
# OPTION: -steps
|
156 |
|
|
#
|
157 |
|
|
# Set the total number of steps.
|
158 |
|
|
# ------------------------------------------------------------------
|
159 |
|
|
configbody iwidgets::Feedback::steps {
|
160 |
|
|
step 0
|
161 |
|
|
}
|
162 |
|
|
|
163 |
|
|
# ------------------------------------------------------------------
|
164 |
|
|
# METHODS
|
165 |
|
|
# ------------------------------------------------------------------
|
166 |
|
|
|
167 |
|
|
# -----------------------------------------------------------------------------
|
168 |
|
|
# PROTECTED METHOD: _display
|
169 |
|
|
#
|
170 |
|
|
# Displays the bar in the trough with the width set using the current number
|
171 |
|
|
# of steps.
|
172 |
|
|
# -----------------------------------------------------------------------------
|
173 |
|
|
body iwidgets::Feedback::_display {} {
|
174 |
|
|
set troughwidth [winfo width $itk_component(trough)]
|
175 |
|
|
set _barwidth [expr $troughwidth.0/$itk_option(-steps)]
|
176 |
|
|
set fraction [expr int((1.0*$_stepval)/$itk_option(-steps)*100.0)]
|
177 |
|
|
|
178 |
|
|
$itk_component(percentage) config -text "$fraction%"
|
179 |
|
|
$itk_component(bar) config -width [expr $_barwidth*$_stepval]
|
180 |
|
|
|
181 |
|
|
update
|
182 |
|
|
}
|
183 |
|
|
|
184 |
|
|
# ------------------------------------------------------------------
|
185 |
|
|
# METHOD: reset
|
186 |
|
|
#
|
187 |
|
|
# Resets the status bar to 0
|
188 |
|
|
# ------------------------------------------------------------------
|
189 |
|
|
body iwidgets::Feedback::reset {} {
|
190 |
|
|
set _stepval 0
|
191 |
|
|
_display
|
192 |
|
|
}
|
193 |
|
|
|
194 |
|
|
# ------------------------------------------------------------------
|
195 |
|
|
# METHOD: step ?inc?
|
196 |
|
|
#
|
197 |
|
|
# Increase the value of the status bar by inc. Default to 1
|
198 |
|
|
# ------------------------------------------------------------------
|
199 |
|
|
body iwidgets::Feedback::step {{inc 1}} {
|
200 |
|
|
|
201 |
|
|
if {$_stepval >= $itk_option(-steps)} {
|
202 |
|
|
return
|
203 |
|
|
}
|
204 |
|
|
|
205 |
|
|
incr _stepval $inc
|
206 |
|
|
_display
|
207 |
|
|
}
|