source: branches/blt4/gui/scripts/periodictable.tcl @ 1759

Last change on this file since 1759 was 1652, checked in by gah, 14 years ago
File size: 21.7 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 6"
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 -outline -cursor
295}
296itk::usual Scrollset {
297}
298
299# ----------------------------------------------------------------------
300# CONSTRUCTOR
301# ----------------------------------------------------------------------
302itcl::body Rappture::PeriodicTable::constructor {args} {
303    Rappture::dispatcher _dispatcher
304    $_dispatcher register !rebuild
305    $_dispatcher dispatch $this !rebuild "[itcl::code $this Redraw]; list"
306    foreach { name number symbol weight row column type } $_tableData {
307        set _table($name) [list name $name number $number symbol $symbol \
308                weight $weight row $row column $column type $type]
309        set _state($name) "normal"
310    }
311    itk_component add scroller {
312        blt::scrollset $itk_interior.sc -yscrollbar $itk_interior.sc.ys \
313            -window $itk_interior.sc.table
314    }
315    blt::tk::scrollbar $itk_interior.sc.ys
316    pack $itk_component(scroller) -expand yes -fill both
317    itk_component add table {
318        canvas $itk_component(scroller).table \
319            -highlightthickness 0
320    } {
321        usual
322        rename -background -textbackground textBackground Background
323        ignore -highlightthickness -highlightbackground -highlightcolor
324        keep -relief
325    }
326
327    # add bindings so the table can react to selections
328    bind RappturePeriodicTable-$this <ButtonRelease-1> [itcl::code $this _react]
329    bind RappturePeriodicTable-$this <KeyPress-Return> [itcl::code $this _react]
330    bind RappturePeriodicTable-$this <KeyPress-space> [itcl::code $this _react]
331    bind RappturePeriodicTable-$this <KeyPress-Escape> [itcl::code $this unpost]
332
333    set btags [bindtags $itk_component(table)]
334    set i [lsearch $btags [winfo class $itk_component(table)]]
335    if {$i < 0} {
336        set i end
337    }
338    set btags [linsert $btags [expr {$i+1}] RappturePeriodicTable-$this]
339    bindtags $itk_component(table) $btags
340   
341    eval itk_initialize $args
342    Redraw
343}
344
345#
346# active <list of elements>
347#
348#       Enables zero or more elements in the periodic table so that
349#       they can be selected.  All elements are first disabled.  Each
350#       argument can one of the following forms:
351#       1. element name.
352#       2. element symbol.
353#       3. element number.
354#       4. type of element.  The argument is expanded into all
355#          elements of that type.
356#
357itcl::body Rappture::PeriodicTable::active { list } {
358    set c $itk_component(table)
359    foreach elem [array names _table] {
360        set _state($elem) "disabled"
361        $c bind $elem <Enter> {}
362        $c bind $elem <Leave> {}
363        $c bind $elem <ButtonRelease-1> {}
364    }
365    # Expand any arguments that represent a group of elements.
366    set arglist {}
367    foreach arg $list {
368        if { [info exists _types($arg)] } {
369            set arglist [concat $arglist $_types($arg)]
370        } else {
371            lappend arglist $arg
372        }
373    }
374    foreach arg $arglist {
375        set elem [FindElement $arg]
376        if { $elem == "" } {
377            puts stderr "unknown element \"$arg\""
378        } else {
379            set _state($elem) "normal"
380            $c bind $elem <Enter> \
381                [itcl::code $this Activate %W $elem %X %Y]
382            $c bind $elem <Leave> [itcl::code $this Deactivate %W $elem]
383            $c bind $elem <ButtonRelease-1> [itcl::code $this value $elem]
384        }
385    }
386    $_dispatcher event -idle !rebuild
387}
388
389#
390# inactive <list of elements>
391#
392#       Disables zero or more elements in the periodic table so that
393#       they can't be selected.  All elements are first enabled.  Each
394#       argument can one of the following forms:
395#       1. element name.
396#       2. element symbol.
397#       3. element number.
398#       4. type of element.  The argument is expanded into all
399#          elements of that type.
400#
401itcl::body Rappture::PeriodicTable::inactive { list } {
402    set c $itk_component(table)
403    foreach elem [array names _table] {
404        set _state($elem) "normal"
405        $c bind $elem <Enter> \
406            [itcl::code $this Activate %W $elem %X %Y]
407        $c bind $elem <Leave> [itcl::code $this Deactivate %W $elem]
408        $c bind $elem <ButtonRelease-1> [itcl::code $this value $elem]
409    }
410    # Expand any arguments that represent a group of elements.
411    set arglist {}
412    foreach arg $list {
413        if { [info exists _types($arg)] } {
414            set arglist [concat $arglist $_types($arg)]
415        } else {
416            lappend arglist $arg
417        }
418    }
419    foreach arg $arglist {
420        set elem [FindElement $arg]
421        if { $elem == "" } {
422            puts stderr "unknown element \"$arg\""
423        } else {
424            set _state($elem) "disabled"
425            $c bind $elem <Enter> {}
426            $c bind $elem <Leave> {}
427            $c bind $elem <ButtonRelease-1> {}
428        }
429    }
430    $_dispatcher event -idle !rebuild
431}
432
433# ----------------------------------------------------------------------
434# USAGE: get ?-symbol|-name|-all? ?name?
435#
436# Queries one or more values from the drop-down list.  With no args,
437# it returns a list of all values and labels in the list.  If the
438# index is specified, then it returns the value or label (or both)
439# for the specified index.
440# ----------------------------------------------------------------------
441itcl::body Rappture::PeriodicTable::get { args } {
442    set first [lindex $args 0]
443    set choices {-symbol -weight -number -name -all}
444    set format "-name"
445    if {[string index $first 0] == "-"} {
446        if {[lsearch $choices $first] < 0} {
447            error "bad option \"$first\": should be [join [lsort $choices] {, }]"
448        }
449        set format $first
450        set args [lrange $args 1 end]
451    }
452    # return the whole list or just a single value
453    if {[llength $args] > 1} {
454        error "wrong # args: should be [join [lsort $choices] {, }]"
455    }
456    if {[llength $args] == 0} {
457        set name $_current
458    } else {
459        set name [lindex $args 0]
460    }
461    set elem [FindElement $name]
462    if { $elem == "" || $_state($elem) == "disabled" } {
463        return ""
464    }
465    array set info $_table($elem)
466    # scan through and build up the return list
467    switch -- $format {
468        -name   { set value $info(name)   }
469        -symbol { set value $info(symbol) }
470        -weight { set value $info(weight) }
471        -number { set value $info(number) }
472        -all {
473            foreach key { symbol name number weight } {
474                lappend value $key $info($key)
475            }
476        }
477    }
478    return $value
479}
480
481# ----------------------------------------------------------------------
482# USAGE: select <name>
483#
484# Used to manipulate the selection in the table.
485#
486# ----------------------------------------------------------------------
487itcl::body Rappture::PeriodicTable::select { what } {
488    set elem [FindElement $what]
489    if { $elem == "" } {
490        set elem "Hydrogen"
491    }
492    set _current $elem
493    $_dispatcher event -idle !rebuild
494}
495
496# ----------------------------------------------------------------------
497# USAGE: _adjust ?<widget>?
498#
499# This method is invoked each time the dropdown is posted to adjust
500# its size and contents.  If the <widget> is specified, it is the
501# controlling widget.
502# ----------------------------------------------------------------------
503itcl::body Rappture::PeriodicTable::_adjust {{widget ""}} {
504    chain $widget
505
506    focus $itk_component(table)
507}
508
509# ----------------------------------------------------------------------
510# USAGE: _react
511#
512# Invoked automatically when the user has selected something from
513# the listbox.  Unposts the drop-down and generates an event letting
514# the client know that the selection has changed.
515# ----------------------------------------------------------------------
516itcl::body Rappture::PeriodicTable::_react {} {
517    unpost
518    event generate $itk_component(hull) <<PeriodicTableSelect>>
519}
520
521itcl::body Rappture::PeriodicTable::Activate { canvas id x y } {
522    set c $itk_component(table)
523    array set info $_table($id)
524    set type $info(type)
525    set fg $_colors($type-activeforeground)
526    set bg $_colors($type-activebackground)
527    $c itemconfigure $id-rect -outline black -width 1 -fill $bg
528    $c itemconfigure $id-number -fill white
529    $c itemconfigure $id-symbol -fill white
530    ::Rappture::Tooltip::text $c \
531        "$info(name) ($info(symbol))\nNumber: $info(number)\nWeight: $info(weight)"
532    ::Rappture::Tooltip::tooltip pending $c @$x,$y
533}
534
535itcl::body Rappture::PeriodicTable::Deactivate { canvas id } {
536    set c $itk_component(table)
537    array set info $_table($id)
538    set type $info(type)
539    set fg $_colors($type-foreground)
540    set bg $_colors($type-background)
541    $c itemconfigure $id-rect -outline $fg -width 1 -fill $bg
542    $c itemconfigure $id-number -fill $fg
543    $c itemconfigure $id-symbol -fill $fg
544    ::Rappture::Tooltip::tooltip cancel
545}
546
547itcl::body Rappture::PeriodicTable::value {{value "" }} {
548    if { $value != "" } {
549        set _current $value
550    }
551}
552
553# ----------------------------------------------------------------------
554# USAGE: Redraw
555#
556# Invoked automatically when the user has selected something from
557# the canvas.  Unposts the drop-down and generates an event letting
558# the client know that the selection has changed.
559# ----------------------------------------------------------------------
560itcl::body Rappture::PeriodicTable::Redraw {} {
561    set sqwidth [winfo pixels . 0.22i]
562    set sqheight [winfo pixels . 0.22i]
563set xoffset 4
564set yoffset 4
565set last ""
566    set c $itk_component(table)
567    $c delete all
568    foreach name [array names _table] {
569        array set info $_table($name)
570        set x1 [expr ($info(column)-1)*$sqwidth+$xoffset]
571        set y1 [expr ($info(row)-1)*$sqheight+$yoffset]
572        set x2 [expr ($info(column)*$sqwidth)-2+$xoffset]
573        set y2 [expr ($info(row)*$sqheight)-2+$yoffset]
574        set type $info(type)
575        if { $_state($name) == "disabled" } {
576            set fg $_colors($type-disabledforeground)
577            set bg $_colors($type-disabledbackground)
578        } else {
579            set fg $_colors($type-foreground)
580            set bg $_colors($type-background)
581        }
582        $c create rectangle $x1 $y1 $x2 $y2 -outline $fg -fill $bg \
583            -tags $info(name)-rect
584        if { $info(symbol) != "*" } {
585            $c create text [expr ($x2+$x1)/2+1] [expr ($y2+$y1)/2+4] \
586                -anchor c -fill $fg \
587                -text [string range $info(symbol) 0 4] \
588                -font "Arial 6" -tags $info(name)-symbol
589            $c create text [expr $x2-2] [expr $y1+2] -anchor ne \
590                -text $info(number) -fill $fg \
591                -font "math1 4" -tags $info(name)-number
592        }
593        $c create rectangle $x1 $y1 $x2 $y2 -outline "" -fill "" \
594            -tags $info(name)
595        if { $_state($name) == "normal" } {
596        $c bind $info(name) <Enter> \
597            [itcl::code $this Activate %W $info(name) %X %Y]
598        $c bind $info(name) <Leave> [itcl::code $this Deactivate %W $info(name)]
599        $c bind $info(name) <ButtonRelease-1> [itcl::code $this value $info(name)]
600        }
601    }
602    update
603    foreach { x1 y1 x2 y2 } [$c bbox all] break
604    set width [expr $x2-$x1+$xoffset*2]
605    set height [expr $y2-$y1+$yoffset*2]
606    $c configure -height $height -width $width -background white
607}
608
609# ----------------------------------------------------------------------
610# USAGE: select <name>
611#
612# Used to manipulate the selection in the table.
613#
614# ----------------------------------------------------------------------
615itcl::body Rappture::PeriodicTable::FindElement { what } {
616    foreach name [array names _table] {
617        array set info $_table($name)
618        if { $what == $info(name) || $what == $info(number) ||
619             $what == $info(symbol) } {
620            break
621        }
622        array unset info
623    }
624    if { [info exists info] } {
625        return $info(name)
626    }
627    return ""
628}
629                                                               
Note: See TracBrowser for help on using the repository browser.