Ignore:
Timestamp:
Jun 25, 2012, 3:43:37 PM (12 years ago)
Author:
mmc
Message:

Fixed an error in the builder "preview" mode related to the reorganization of
the Analyzer code and changed component names.

Fixed the "periodicelement" type in the builder to save/load properly and
offer drop-down lists for default value and other properties.

Location:
trunk/lang/tcl/scripts
Files:
3 added
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/lang/tcl/scripts/Makefile.in

    r2698 r3056  
    6161
    6262TYPEFILES       = \
     63                $(srcdir)/types/atomactive.tcl \
     64                $(srcdir)/types/atomelem.tcl \
     65                $(srcdir)/types/atomprops.tcl \
    6366                $(srcdir)/types/boolean.tcl \
    6467                $(srcdir)/types/choices.tcl \
  • trunk/lang/tcl/scripts/objects/periodicelement/periodicelement.rp

    r2638 r3056  
    1818    help http://rappture.org/wiki/rp_xml_ele_periodicelement
    1919
    20     attr active -title "Active Elements" \
    21         -type string -path default -only input \
    22         -tooltip "Specifies the set of elements that can be selected.\n\nCan be a list of element symbols or groups: actinoid, alkali-metal, alkaline-earth-metal, halogen, lanthanoid, metalloid, noble-gas, other-non-metal, post-transition-metal, transition-metal, or unknown."
    23     attr inactive -title "Inactive Elements" \
    24         -type string -path default -only input \
    25         -tooltip "Specifies the set of elements that can't be selected.\n\nCan be a list of element symbols or groups: actinoid, alkali-metal, alkaline-earth-metal, halogen, lanthanoid, metalloid, noble-gas, other-non-metal, post-transition-metal, transition-metal, or unknown."
     20    attr default -title "Default Value" -type atomelem -path default -only input -tooltip "Sets the value that this input has when the program first starts.  This value is used by default unless the user explicitly changes it."
    2621
    27     attr returnvalue -title "Return value" -type string -path default -only input -tooltip "Specifies the return value: name, symbol, number, or weight."
     22    attr returnvalue -title "Return value" -type atomprops -path returnvalue -only input -tooltip "Specifies how the selected element is reported to your program: name, symbol, number, or weight."
    2823
    29     attr default -title "Default Value" -type string -path default -only input -tooltip "Sets the value that this input has when the program first starts.  This value is used by default unless the user explicitly changes it."
     24    attr active -title "Allowed Elements" \
     25        -type atomactive -path active -only input -tooltip "Specifies the set of elements that can be selected.\n\nCan allow or disallow one or more groups of elements on the periodic table: actinoid, alkali-metal, alkaline-earth-metal, halogen, lanthanoid, metalloid, noble-gas, other-non-metal, post-transition-metal, transition-metal, or unknown."
    3026
    3127    check default {
    32         if {[llength $attr(options)] > 0} {
    33             if {[string length [string trim $attr(default)]] == 0} {
    34                 return [list error "Must have a default value for this periodicelement."]
     28        set defval [string trim $attr(default)]
     29        if {[string length $defval] == 0} {
     30            return [list error "Must have a default value for this periodicelement."]
     31        }
     32
     33        # make sure that the given value is a valid element type
     34        if {[Rappture::PeriodicTable::FindElement $defval] eq ""} {
     35            return [list error "Bad value \"$defval\": must be a known element in the periodic table."]
     36        }
     37
     38        # make sure that the given value isn't in conflict with allowed values
     39        if {$attr(active) ne "" && [regexp {^(active|inactive): (.+)} $attr(active) match polarity vlist]} {
     40            set found [eval Rappture::PeriodicTable::ElementIsType $attr(default) [split $vlist ,]]
     41            if { (!$found && $polarity eq "active")
     42                  || ($found && $polarity eq "inactive") } {
     43                return [list error "Default value \"$attr(default)\" is not one of the allowed values"]
    3544            }
     45        }
     46    }
    3647
    37             # make sure that the default is really a choice
    38             set defval [string trim $attr(default)]
    39             set found 0
    40             foreach rec $attr(options) {
    41                 set label [string trim [lindex $rec 0]]
    42                 set value [string trim [lindex $rec 1]]
    43                 if {$defval eq $label || $defval eq $value} {
    44                     set found 1
    45                     break
    46                 }
    47             }
    48             if {!$found} {
    49                 return [list error "Default value must be a label or value for one of the current periodicelements."]
    50             }
     48    check returnvalue {
     49        if {[string length [string trim $attr(returnvalue)]] == 0} {
     50            return [list error "Must choose at least one return value to report the selected element to your program."]
    5151        }
    5252    }
Note: See TracChangeset for help on using the changeset viewer.