source: trunk/gui/scripts/periodictable.tcl @ 2753

Last change on this file since 2753 was 2753, checked in by gah, 12 years ago
File size: 26.6 KB
Line 
1
2# ----------------------------------------------------------------------
3#  COMPONENT: periodictable - drop-down list of items
4#
5#  This is a drop-down listbox, which might be used in conjunction
6#  with a combobox.
7#
8# ======================================================================
9#  AUTHOR:  Michael McLennan, Purdue University
10#  Copyright (c) 2004-2005  Purdue Research Foundation
11#
12#  See the file "license.terms" for information on usage and
13#  redistribution of this file, and for a DISCLAIMER OF ALL WARRANTIES.
14# ======================================================================
15package require Itk
16
17option add *PeriodicTable.textBackground white widgetDefault
18option add *PeriodicTable.outline black widgetDefault
19option add *PeriodicTable.borderwidth 1 widgetDefault
20option add *PeriodicTable.relief flat widgetDefault
21option add *PeriodicTable.font "Arial 8"
22
23itcl::class Rappture::PeriodicTable {
24    inherit Rappture::Dropdown
25
26    constructor {args} { # defined below }
27
28    public method active { list }
29    public method inactive { list }
30    public method get {args}
31    public method select {name}
32    public method value { {name ""} }
33
34    private variable _table
35    private variable _dispatcher ""
36    private variable _current ""
37    private variable _state
38
39    protected method _adjust {{widget ""}}
40
41    protected method _react {}
42    protected method Redraw {}
43    protected method Activate { widget id x y }
44    protected method Deactivate { widget id }
45    protected method FindElement { string }
46    private common _colors
47    array set _colors {
48        actinoid-activebackground                       \#cd679a
49        actinoid-activeforeground                       white
50        actinoid-disabledbackground                     \#ff99cc 
51        actinoid-disabledforeground                     \#D97DAB
52        actinoid-background                             \#ff99cc
53        actinoid-foreground                             black
54        alkali-metal-activebackground                   \#cd3434
55        alkali-metal-activeforeground                   white
56        alkali-metal-disabledbackground                 \#ff6666
57        alkali-metal-disabledforeground                 \#D04747
58        alkali-metal-background                         \#ff6666
59        alkali-metal-foreground                         black
60        alkaline-earth-metal-activebackground           \#cdac7b
61        alkaline-earth-metal-activeforeground           white
62        alkaline-earth-metal-disabledbackground         \#ffdead
63        alkaline-earth-metal-disabledforeground         \#C19A64
64        alkaline-earth-metal-background                 \#ffdead
65        alkaline-earth-metal-foreground                 black
66        halogen-activebackground                        \#cdcd67
67        halogen-activeforeground                        white
68        halogen-disabledbackground                      \#ffff99
69        halogen-disabledforeground                      \#D5D562
70        halogen-background                              \#ffff99
71        halogen-foreground                              black
72        lanthanoid-activebackground                     \#cd8dcd
73        lanthanoid-activeforeground                     white
74        lanthanoid-disabledbackground                   \#ffbfff
75        lanthanoid-disabledforeground                   \#D884D8
76        lanthanoid-background                           \#ffbfff
77        lanthanoid-foreground                           black
78        metalloid-activebackground                      \#9a9a67
79        metalloid-activeforeground                      white
80        metalloid-disabledbackground                    \#cccc99
81        metalloid-disabledforeground                    \#92922C
82        metalloid-background                            \#cccc99
83        metalloid-foreground                            black
84        noble-gas-activebackground                      \#8ecdcd
85        noble-gas-activeforeground                      white
86        noble-gas-disabledbackground                    \#c0ffff
87        noble-gas-disabledforeground                    \#7FC1C1
88        noble-gas-background                            \#c0ffff
89        noble-gas-foreground                            black
90        other-non-metal-activebackground                \#6ecd6e
91        other-non-metal-activeforeground                white
92        other-non-metal-disabledbackground              \#a0ffa0
93        other-non-metal-disabledforeground              \#6ACD6A
94        other-non-metal-background                      \#a0ffa0
95        other-non-metal-foreground                      black
96        post-transition-metal-activebackground          \#9a9a9a       
97        post-transition-metal-activeforeground          white
98        post-transition-metal-disabledbackground        \#cccccc
99        post-transition-metal-disabledforeground        \#999999
100        post-transition-metal-background                \#cccccc
101        post-transition-metal-foreground                black
102        transition-metal-activebackground               \#cd8e8e
103        transition-metal-activeforeground               white
104        transition-metal-disabledbackground             \#ffc0c0
105        transition-metal-disabledforeground             \#C77E7E
106        transition-metal-background                     \#ffc0c0
107        transition-metal-foreground                     black
108        unknown-activebackground                        \#cdcdcd
109        unknown-activeforeground                        white
110        unknown-disabledbackground                      \#ffffff
111        unknown-disabledforeground                      \#B9B9B9
112        unknown-background                              \#ffffff
113        unknown-foreground                              black
114    }
115    private common _tableData {
116        Hydrogen        1  H  1.0079    1 1     other-non-metal
117        Helium          2  He 4.0026    1 18    noble-gas
118        Lithium         3  Li 6.941(2)  2 1     alkali-metal
119        Beryllium       4  Be 9.0122    2 2     alkaline-earth-metal
120        Boron           5  B  10.811(7) 2 13    metalloid
121        Carbon          6  C  12.011    2 14    other-non-metal
122        Nitrogen        7  N  14.007    2 15    other-non-metal
123        Oxygen          8  O  15.999    2 16    other-non-metal
124        Fluorine        9  F  18.998    2 17    halogen
125        Neon            10 Ne 20.180    2 18    noble-gas
126       
127        Sodium          11 Na 22.990    3 1     alkali-metal
128        Magnesium       12 Mg 24.305    3 2     alkaline-earth-metal
129        Aluminium       13 Al 26.982    3 13    post-transition-metal
130        Silicon         14 Si 28.086    3 14    metalloid
131        Phosphorus      15 P  30.974    3 15    other-non-metal
132        Sulfur          16 S  32.066(6) 3 16    other-non-metal
133        Chlorine        17 Cl 35.453    3 17    halogen
134        Argon           18 Ar 39.948(1) 3 18    noble-gas
135       
136        Potassium       19 K  39.098    4 1     alkali-metal
137        Calcium         20 Ca 40.078(4) 4 2     alkaline-earth-metal
138        Scandium        21 Sc 44.956    4 3     transition-metal
139        Titanium        22 Ti 47.867(1) 4 4     transition-metal
140        Vanadium        23 V  50.942(1) 4 5     transition-metal
141        Chromium        24 Cr 51.996    4 6     transition-metal
142        Manganese       25 Mn 54.938    4 7     transition-metal
143        Iron            26 Fe 55.845(2) 4 8     transition-metal
144        Cobalt          27 Co 58.933    4 9     transition-metal
145        Nickel          28 Ni 58.693    4 10    transition-metal
146        Copper          29 Cu 63.546(3) 4 11    transition-metal
147        Zinc            30 Zn 65.39(2)  4 12    transition-metal
148        Gallium         31 Ga 69.723(1) 4 13    post-transition-metal
149        Germanium       32 Ge 72.61(2)  4 14    metalloid
150        Arsenic         33 As 74.922    4 15    metalloid
151        Selenium        34 Se 78.96(3)  4 16    other-non-metal
152        Bromine         35 Br 79.904(1) 4 17    halogen
153        Krypton         36 Kr 83.80(1)  4 18    noble-gas
154       
155        Rubidium        37 Rb 85.468    5 1     alkali-metal
156        Strontium       38 Sr 87.62(1)  5 2     alkaline-earth-metal
157        Yttrium         39 Y  88.906    5 3     transition-metal
158        Zirconium       40 Zr 91.224(2) 5 4     transition-metal
159        Niobium         41 Nb 92.906    5 5     transition-metal
160        Molybdenum      42 Mo 95.94(1)  5 6     transition-metal
161        Technetium      43 Tc [97.907]  5 7     transition-metal
162        Ruthenium       44 Ru 101.07(2) 5 8     transition-metal
163        Rhodium         45 Rh 102.906   5 9     transition-metal
164        Palladium       46 Pd 106.42(1) 5 10    transition-metal
165        Silver          47 Ag 107.868   5 11    transition-metal
166        Cadmium         48 Cd 112.411(8) 5 12   transition-metal
167        Indium          49 In 114.818(3) 5 13   post-transition-metal
168        Tin             50 Sn 118.710(7) 5 14   post-transition-metal
169        Antimony        51 Sb 121.760(1) 5 15   metalloid
170        Tellurium       52 Te 127.60(3) 5 16    metalloid
171        Iodine          53 I  126.904   5 17    halogen
172        Xenon           54 Xe 131.29(2) 5 18    noble-gas
173       
174        Cesium          55 Cs 132.905   6 1     alkali-metal
175        Barium          56 Ba 137.327(7) 6 2    alkaline-earth-metal
176        Lanthanides     57-71 * *       6 3     lanthanoid
177        Hafnium         72 Hf 178.49(2) 6 4     transition-metal
178        Tantalum        73 Ta 180.948   6 5     transition-metal
179        Tungsten        74 W  183.84(1) 6 6     transition-metal
180        Rhenium         75 Re 186.207(1) 6 7    transition-metal
181        Osmium          76 Os 190.23(3) 6 8     transition-metal
182        Iridium         77 Ir 192.217(3) 6 9    transition-metal
183        Platinum        78 Pt 195.084(9) 6 10   transition-metal
184        Gold            79 Au 196.967 6 11      transition-metal
185        Mercury         80 Hg 200.59(2) 6 12    transition-metal
186        Thallium        81 Tl 204.383   6 13    post-transition-metal
187        Lead            82 Pb 207.2(1) 6 14     post-transition-metal
188        Bismuth         83 Bi 208.980   6 15    post-transition-metal
189        Polonium        84 Po [208.982] 6 16    metalloid
190        Astatine        85 At [209.987] 6 17    halogen
191        Radon           86 Rn [222.018] 6 18    noble-gas
192       
193        Francium        87 Fr [223.020] 7 1     alkali-metal
194        Radium          88 Ra [226.0254] 7 2    alkaline-earth-metal
195        Actinides       89-103 * * 7 3          actinoid
196        Rutherfordium   104 Rf [263.113] 7 4    transition-metal
197        Dubnium         105 Db [262.114] 7 5    transition-metal
198        Seaborgium      106 Sg [266.122] 7 6    transition-metal
199        Bohrium         107 Bh [264.1247] 7 7   transition-metal
200        Hassium         108 Hs [269.134] 7 8    transition-metal
201        Meitnerium      109 Mt [268.139] 7 9    transition-metal
202        Darmstadtium    110 Ds [272.146] 7 10   transition-metal
203        Roentgenium     111 Rg [272.154] 7 11   transition-metal
204        Ununbium        112 Uub [277]   7 12    transition-metal
205        Ununtrium       113 Uut [284] 7 13      post-transition-metal
206        Ununquadium     114 Uuq [289] 7 14      post-transition-metal
207        Ununpentium     115 Uup [288] 7 15      post-transition-metal
208        Ununhexium      116 Uuh [292]  7 16     post-transition-metal
209        Ununseptium     117 Uus ? 7 17          unknown
210        Ununoctium      118 Uuo [294] 7 18      unknown
211       
212        Lanthanum       57 La 138.905 8 3       lanthanoid
213        Cerium          58 Ce 140.116(1) 8 4    lanthanoid
214        Praseodymium    59 Pr 140.908 8 5       lanthanoid
215        Neodymium       60 Nd 144.242(3) 8 6    lanthanoid
216        Promethium      61 Pm [144.913] 8 7     lanthanoid
217        Samarium        62 Sm 150.36(2) 8 8     lanthanoid
218        Europium        63 Eu 151.964(1) 8 9    lanthanoid
219        Gadolinium      64 Gd 157.25(3) 8 10    lanthanoid
220        Terbium         65 Tb 158.925   8 11    lanthanoid
221        Dysprosium      66 Dy 162.500(1) 8 12   lanthanoid
222        Holmium         67 Ho 164.930 8 13      lanthanoid
223        Erbium          68 Er 167.259(3) 8 14   lanthanoid
224        Thulium         69 Tm 168.934   8 15    lanthanoid
225        Ytterbium       70 Yb 173.04(3) 8 16    lanthanoid
226        Lutetium        71 Lu 174.967(1) 8 17   lanthanoid
227       
228        Actinium        89 Ac [227.027] 9 3     actinoid
229        Thorium         90 Th 232.038   9 4     actinoid
230        Protactinium    91 Pa 231.036 9 5       actinoid
231        Uranium         92 U 238.029 9 6        actinoid
232        Neptunium       93 Np [237.048] 9 7     actinoid
233        Plutonium       94 Pu [244.064] 9 8     actinoid
234        Americium       95 Am [243.061] 9 9     actinoid
235        Curium          96 Cm [247.070] 9 10    actinoid
236        Berkelium       97 Bk [247.070] 9 11    actinoid
237        Californium     98 Cf [251.080] 9 12    actinoid
238        Einsteinium     99 Es [252.083] 9 13    actinoid
239        Fermium         100 Fm [257.095] 9 14   actinoid
240        Mendelevium     101 Md [258.098] 9 15   actinoid
241        Nobelium        102 No [259.101] 9 16   actinoid
242        Lawrencium      103 Lr [262.110] 9 17   actinoid
243    }
244    private common _types
245    array set _types {
246        actinoid {
247            Actinides Actinium Americium Berkelium Californium Curium
248            Einsteinium Fermium Mendelevium Neptunium Plutonium Protactinium
249            Thorium Uranium Lawrencium Nobelium
250        }
251        alkali-metal {
252            Cesium Francium Lithium Potassium Rubidium Sodium           
253        }
254        alkaline-earth-metal {
255            Barium Beryllium Calcium Magnesium Radium Strontium
256        }
257        halogen {
258            Astatine Bromine Chlorine Fluorine Iodine           
259        }
260        lanthanoid {
261            Cerium Erbium Europium Gadolinium Holmium Lanthanides Lanthanum     
262            Lutetium Neodymium Praseodymium Promethium Samarium Terbium
263            Thulium Ytterbium Dysprosium       
264        }
265        metalloid {
266            Arsenic Boron Germanium Polonium Silicon Tellurium Antimony
267        }
268        noble-gas {
269            Argon Helium Krypton Neon Radon Xenon
270        }
271        other-non-metal {
272            Carbon Hydrogen Nitrogen Sulfur Oxygen Phosphorus Selenium 
273        }
274        post-transition-metal {
275            Aluminium Bismuth Gallium Indium Lead Thallium Tin Ununhexium
276            Ununpentium Ununquadium Ununtrium   
277        }
278        transition-metal {
279            Chromium Cobalt Copper Dubnium Gold Hafnium Hassium Iridium         
280            Iron Manganese Meitnerium Mercury Molybdenum Nickel Niobium         
281            Osmium Palladium Rhenium Rhodium Roentgenium Ruthenium
282            Rutherfordium Scandium Seaborgium Silver Tantalum Technetium
283            Titanium Tungsten Ununbium Vanadium Yttrium Zinc Zirconium
284            Bohrium Cadmium Darmstadtium Platinum       
285        }
286        unknown {
287            Ununoctium 
288            Ununseptium
289        }
290    }
291}
292   
293itk::usual PeriodicTable {
294    keep -background -outline -cursor
295}
296
297# ----------------------------------------------------------------------
298# CONSTRUCTOR
299# ----------------------------------------------------------------------
300itcl::body Rappture::PeriodicTable::constructor {args} {
301    Rappture::dispatcher _dispatcher
302    $_dispatcher register !rebuild
303    $_dispatcher dispatch $this !rebuild "[itcl::code $this Redraw]; list"
304    foreach { name number symbol weight row column type } $_tableData {
305        set _table($name) [list name $name number $number symbol $symbol \
306                weight $weight row $row column $column type $type]
307        set _state($name) "normal"
308    }
309    itk_component add scroller {
310        Rappture::Scroller $itk_interior.sc \
311            -xscrollmode off -yscrollmode auto
312    }
313    pack $itk_component(scroller) -expand yes -fill both
314
315    itk_component add table {
316        canvas $itk_component(scroller).table \
317            -highlightthickness 0
318    } {
319        usual
320        rename -background -textbackground textBackground Background
321        ignore -highlightthickness -highlightbackground -highlightcolor
322        keep -relief
323    }
324    $itk_component(scroller) contents $itk_component(table)
325
326    # add bindings so the table can react to selections
327    bind RappturePeriodicTable-$this <ButtonRelease-1> [itcl::code $this _react]
328    bind RappturePeriodicTable-$this <KeyPress-Return> [itcl::code $this _react]
329    bind RappturePeriodicTable-$this <KeyPress-space> [itcl::code $this _react]
330    bind RappturePeriodicTable-$this <KeyPress-Escape> [itcl::code $this unpost]
331
332    set btags [bindtags $itk_component(table)]
333    set i [lsearch $btags [winfo class $itk_component(table)]]
334    if {$i < 0} {
335        set i end
336    }
337    set btags [linsert $btags [expr {$i+1}] RappturePeriodicTable-$this]
338    bindtags $itk_component(table) $btags
339   
340    eval itk_initialize $args
341    Redraw
342}
343
344#
345# active <list of elements>
346#
347#       Enables zero or more elements in the periodic table so that
348#       they can be selected.  All elements are first disabled.  Each
349#       argument can one of the following forms:
350#       1. element name.
351#       2. element symbol.
352#       3. element number.
353#       4. type of element.  The argument is expanded into all
354#          elements of that type.
355#
356itcl::body Rappture::PeriodicTable::active { list } {
357    set c $itk_component(table)
358    foreach elem [array names _table] {
359        set _state($elem) "disabled"
360        $c bind $elem <Enter> {}
361        $c bind $elem <Leave> {}
362        $c bind $elem <ButtonRelease-1> {}
363    }
364    # Expand any arguments that represent a group of elements.
365    set arglist {}
366    foreach arg $list {
367        if { [info exists _types($arg)] } {
368            set arglist [concat $arglist $_types($arg)]
369        } else {
370            lappend arglist $arg
371        }
372    }
373    foreach arg $arglist {
374        set elem [FindElement $arg]
375        if { $elem == "" } {
376            puts stderr "unknown element \"$arg\""
377        } else {
378            set _state($elem) "normal"
379            $c bind $elem <Enter> \
380                [itcl::code $this Activate %W $elem %X %Y]
381            $c bind $elem <Leave> [itcl::code $this Deactivate %W $elem]
382            $c bind $elem <ButtonRelease-1> [itcl::code $this value $elem]
383        }
384    }
385    $_dispatcher event -idle !rebuild
386}
387
388#
389# inactive <list of elements>
390#
391#       Disables zero or more elements in the periodic table so that
392#       they can't be selected.  All elements are first enabled.  Each
393#       argument can one of the following forms:
394#       1. element name.
395#       2. element symbol.
396#       3. element number.
397#       4. type of element.  The argument is expanded into all
398#          elements of that type.
399#
400itcl::body Rappture::PeriodicTable::inactive { list } {
401    set c $itk_component(table)
402    foreach elem [array names _table] {
403        set _state($elem) "normal"
404        $c bind $elem <Enter> \
405            [itcl::code $this Activate %W $elem %X %Y]
406        $c bind $elem <Leave> [itcl::code $this Deactivate %W $elem]
407        $c bind $elem <ButtonRelease-1> [itcl::code $this value $elem]
408    }
409    # Expand any arguments that represent a group of elements.
410    set arglist {}
411    foreach arg $list {
412        if { [info exists _types($arg)] } {
413            set arglist [concat $arglist $_types($arg)]
414        } else {
415            lappend arglist $arg
416        }
417    }
418    foreach arg $arglist {
419        set elem [FindElement $arg]
420        if { $elem == "" } {
421            puts stderr "unknown element \"$arg\""
422        } else {
423            set _state($elem) "disabled"
424            $c bind $elem <Enter> {}
425            $c bind $elem <Leave> {}
426            $c bind $elem <ButtonRelease-1> {}
427        }
428    }
429    $_dispatcher event -idle !rebuild
430}
431
432# ----------------------------------------------------------------------
433# USAGE: get ?-symbol|-name|-all? ?name?
434#
435# Queries one or more values from the drop-down list.  With no args,
436# it returns a list of all values and labels in the list.  If the
437# index is specified, then it returns the value or label (or both)
438# for the specified index.
439# ----------------------------------------------------------------------
440itcl::body Rappture::PeriodicTable::get { args } {
441    set first [lindex $args 0]
442    set choices {-symbol -weight -number -name -all}
443    set format "-name"
444    if {[string index $first 0] == "-"} {
445        if {[lsearch $choices $first] < 0} {
446            error "bad option \"$first\": should be [join [lsort $choices] {, }]"
447        }
448        set format $first
449        set args [lrange $args 1 end]
450    }
451    # return the whole list or just a single value
452    if {[llength $args] > 1} {
453        error "wrong # args: should be [join [lsort $choices] {, }]"
454    }
455    if {[llength $args] == 0} {
456        set name $_current
457    } else {
458        set name [lindex $args 0]
459    }
460    set elem [FindElement $name]
461    if { $elem == "" || $_state($elem) == "disabled" } {
462        if { $elem != "" } {
463            puts stderr "element $elem is disabled"
464        }
465        return ""
466    }
467    array set info $_table($elem)
468    # scan through and build up the return list
469    switch -- $format {
470        -name   { set value $info(name)   }
471        -symbol { set value $info(symbol) }
472        -weight { set value $info(weight) }
473        -number { set value $info(number) }
474        -all {
475            foreach key { symbol name number weight } {
476                lappend value $key $info($key)
477            }
478        }
479    }
480    return $value
481}
482
483# ----------------------------------------------------------------------
484# USAGE: select <name>
485#
486# Used to manipulate the selection in the table.
487#
488# ----------------------------------------------------------------------
489itcl::body Rappture::PeriodicTable::select { what } {
490    set elem [FindElement $what]
491    if { $elem == "" } {
492        set elem "Hydrogen"
493    }
494    set _current $elem
495    $_dispatcher event -idle !rebuild
496}
497
498# ----------------------------------------------------------------------
499# USAGE: _adjust ?<widget>?
500#
501# This method is invoked each time the dropdown is posted to adjust
502# its size and contents.  If the <widget> is specified, it is the
503# controlling widget.
504# ----------------------------------------------------------------------
505itcl::body Rappture::PeriodicTable::_adjust {{widget ""}} {
506    chain $widget
507
508    focus $itk_component(table)
509}
510
511# ----------------------------------------------------------------------
512# USAGE: _react
513#
514# Invoked automatically when the user has selected something from
515# the listbox.  Unposts the drop-down and generates an event letting
516# the client know that the selection has changed.
517# ----------------------------------------------------------------------
518itcl::body Rappture::PeriodicTable::_react {} {
519    unpost
520    event generate $itk_component(hull) <<PeriodicTableSelect>>
521}
522
523itcl::body Rappture::PeriodicTable::Activate { canvas id x y } {
524    set c $itk_component(table)
525    array set info $_table($id)
526    set type $info(type)
527    set fg $_colors($type-activeforeground)
528    set bg $_colors($type-activebackground)
529    $c itemconfigure $id-rect -outline black -width 1 -fill $bg
530    $c itemconfigure $id-number -fill white
531    $c itemconfigure $id-symbol -fill white
532    ::Rappture::Tooltip::text $c \
533        "$info(name) ($info(symbol))\nNumber: $info(number)\nWeight: $info(weight)"
534    ::Rappture::Tooltip::tooltip pending $c @$x,$y
535}
536
537itcl::body Rappture::PeriodicTable::Deactivate { canvas id } {
538    set c $itk_component(table)
539    array set info $_table($id)
540    set type $info(type)
541    set fg $_colors($type-foreground)
542    set bg $_colors($type-background)
543    $c itemconfigure $id-rect -outline $fg -width 1 -fill $bg
544    $c itemconfigure $id-number -fill $fg
545    $c itemconfigure $id-symbol -fill $fg
546    ::Rappture::Tooltip::tooltip cancel
547}
548
549itcl::body Rappture::PeriodicTable::value {{value "" }} {
550    if { $value != "" } {
551        set _current $value
552    }
553}
554
555# ----------------------------------------------------------------------
556# USAGE: Redraw
557#
558# Invoked automatically when the user has selected something from
559# the canvas.  Unposts the drop-down and generates an event letting
560# the client know that the selection has changed.
561# ----------------------------------------------------------------------
562itcl::body Rappture::PeriodicTable::Redraw {} {
563set sqwidth 24
564set sqheight 24
565set xoffset 4
566set yoffset 4
567set last ""
568    set c $itk_component(table)
569    $c delete all
570    foreach name [array names _table] {
571        array set info $_table($name)
572        set x1 [expr ($info(column)-1)*$sqwidth+$xoffset]
573        set y1 [expr ($info(row)-1)*$sqheight+$yoffset]
574        set x2 [expr ($info(column)*$sqwidth)-2+$xoffset]
575        set y2 [expr ($info(row)*$sqheight)-2+$yoffset]
576        set type $info(type)
577        if { $_state($name) == "disabled" } {
578            set fg $_colors($type-disabledforeground)
579            set bg $_colors($type-disabledbackground)
580        } else {
581            set fg $_colors($type-foreground)
582            set bg $_colors($type-background)
583        }
584        $c create rectangle $x1 $y1 $x2 $y2 -outline $fg -fill $bg \
585            -tags $info(name)-rect
586        if { $info(symbol) != "*" } {
587            $c create text [expr ($x2+$x1)/2+1] [expr ($y2+$y1)/2+4] \
588                -anchor c -fill $fg \
589                -text [string range $info(symbol) 0 4] \
590                -font "Arial 8 bold" -tags $info(name)-symbol
591            $c create text [expr $x2-2] [expr $y1+2] -anchor ne \
592                -text $info(number) -fill $fg \
593                -font "math1 6" -tags $info(name)-number
594        }
595        $c create rectangle $x1 $y1 $x2 $y2 -outline "" -fill "" \
596            -tags $info(name)
597        if { $_state($name) == "normal" } {
598        $c bind $info(name) <Enter> \
599            [itcl::code $this Activate %W $info(name) %X %Y]
600        $c bind $info(name) <Leave> [itcl::code $this Deactivate %W $info(name)]
601        $c bind $info(name) <ButtonRelease-1> [itcl::code $this value $info(name)]
602        }
603    }
604    update
605    foreach { x1 y1 x2 y2 } [$c bbox all] break
606    set width [expr $x2-$x1+$xoffset*2]
607    set height [expr $y2-$y1+$yoffset*2]
608    $c configure -height $height -width $width -background white
609}
610
611# ----------------------------------------------------------------------
612# USAGE: FindElement
613#
614# Used to manipulate the selection in the table.
615#
616# ----------------------------------------------------------------------
617itcl::body Rappture::PeriodicTable::FindElement { what } {
618    foreach name [array names _table] {
619        array unset info
620        array set info $_table($name)
621        if { $what == $info(name) || $what == $info(number) ||
622             $what == $info(symbol) } {
623            return $info(name)
624        }
625    }
626    parray info
627    return ""
628}
629                                                               
Note: See TracBrowser for help on using the repository browser.