source: trunk/lang/tcl/scripts/types/units.tcl @ 2154

Last change on this file since 2154 was 2154, checked in by mmc, 14 years ago

Added a definition for the "choice" object, along with the "choices" editor
for specifying values.

Numerous fixes to the object system: Cleaned up the palettes for all
objects so they can be used to warn about things like output objects on
the input side. Marked may attributes as "input only" via the new -only
option for attributes. Fixed the label/description checks so that they
occur properly when inherited from the "base" object class.

File size: 3.4 KB
Line 
1# ----------------------------------------------------------------------
2#  EDITOR: units attribute values
3#
4#  Used within the Instant Rappture builder to edit units for numbers.
5#
6# ======================================================================
7#  AUTHOR:  Michael McLennan, Purdue University
8#  Copyright (c) 2004-2010  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# ======================================================================
13itcl::class AttrUnits {
14    constructor {win args} {
15        Rappture::getopts args params {
16        }
17
18        Rappture::Combobox $win.val -width 10 -editable yes
19        pack $win.val -side left
20        $win.val choices insert end \
21          m   "Length Units" \
22          m   "  m - meters" \
23          in  "  in - inches" \
24          ft  "  ft - feet" \
25          yd  "  yd - yards" \
26          mi  "  mi - miles" \
27          s   "Time Units" \
28          s   "  s - seconds" \
29          min "  min - minutes" \
30          h   "  h - hours" \
31          d   "  d - days" \
32          Hz  "  Hz - Hertz" \
33          K   "Temperature Units" \
34          K   "  K - Kelvin" \
35          F   "  F - Fahrenheit" \
36          C   "  C - Celcius" \
37          eV  "Energy Units" \
38          eV  "  eV - electron Volts" \
39          J   "  J - Joules" \
40          V   "  V - volts" \
41          m3  "Volume Units" \
42          m3  "  cubic meter" \
43          gal "  gal - US gallon" \
44          L   "  L - liter" \
45          deg "Angle Units" \
46          deg "  deg - degrees" \
47          rad "  rad - radians" \
48          g   "Mass Units" \
49          g   "  g - grams" \
50          N   "Force Units" \
51          N   "  N - Newtons" \
52          Pa  "Pressure Units" \
53          Pa  "  Pa - Pascals" \
54          atm "  atm - atmospheres" \
55          pis "  psi - pounds per square inch" \
56          T   "Magnetic Units" \
57          T   "  T - Teslas" \
58          G   "  G - Gauss"
59
60        set _win $win
61    }
62
63    public method check {} {
64        set val [$_win.val translate [$_win.val value]]
65        if {"" != $val} {
66            return ""
67        }
68        set val [$_win.val value]
69        if {"" != [Rappture::Units::description $val]} {
70            return ""
71        }
72        return [list error "Bad value \"$val\": should be valid system of units"]
73    }
74
75    public method load {val} {
76        set newval [$_win.val translate $val]
77        if {"" != $newval} {
78            $_win.val value $newval
79        } else {
80            $_win.val value $val
81        }
82    }
83
84    public method save {var} {
85        upvar $var value
86
87        set err [lindex [check] 1]
88        if {[string length $err] > 0} {
89            Rappture::Tooltip::cue $_win $err
90            return 0
91        }
92
93        set val [$_win.val value]
94        set newval [$_win.val translate $val]
95        if {"" != $newval} {
96            set value $newval
97        } else {
98            set value $val
99        }
100        return 1
101    }
102
103    public method edit {} {
104        focus -force $_win.val
105        $_win.val component entry selection from 0
106        $_win.val component entry selection to end
107    }
108
109    public proc import {xmlobj path} {
110        set val [$xmlobj get $path]
111        return $val
112    }
113
114    public proc export {xmlobj path value} {
115        $xmlobj put $path $value
116    }
117
118    private variable _win ""       ;# containing frame
119}
Note: See TracBrowser for help on using the repository browser.