Changeset 1207 for trunk


Ignore:
Timestamp:
Nov 5, 2008 12:15:09 PM (16 years ago)
Author:
dkearney
Message:

adding functionality to more dynamically change the contents of a note. this is helpful if you have a loader to choose materials, and a note for each material. when the user changes the material, the contents of the note (which describes the material) can change as well. this is used in the dev version of photonicsdb

Location:
trunk/gui/scripts
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/gui/scripts/controlOwner.tcl

    r1159 r1207  
    4040    private variable _path2widget    ;# maps path => widget on this page
    4141    private variable _owner2paths    ;# for notify: maps owner => interests
     42    private variable _type2curpath   ;# maps type(path) => path's current value
    4243    private variable _callbacks      ;# for notify: maps owner/path => callback
    4344    private variable _dependencies   ;# maps path => other paths dep on this
    4445}
    45                                                                                
     46
    4647# ----------------------------------------------------------------------
    4748# CONSTRUCTOR
     
    5354        set _path [lindex $parts 1]
    5455        $_owner _slave add $this
     56    }
     57
     58    # we are adding this so notes can be used
     59    # in coordination with loaders inside the load function
     60    array set _type2curpath {
     61        choice current
     62        boolean current
     63        image current
     64        integer current
     65        loader current
     66        note contents
     67        number current
     68        string current
    5569    }
    5670}
     
    248262        # the following elements do not accept "current" tags, skip them
    249263        set type [[tool] xml element -as type $path]
    250         if {[lsearch {group separator control note} $type] >= 0} {
     264        if {[lsearch {group separator control} $type] >= 0} {
    251265            continue
    252266        }
    253267
     268        set type [[tool] xml element -as type $path]
     269        if {[info exists _type2curpath($type)]} {
     270            set currentpath $path.$_type2curpath($type)
     271        } else {
     272            # default incase i forgot an inpuit type in _type2curpath
     273            set currentpath $path.current
     274        }
     275
    254276        # copy new value to the XML tree
    255         [tool] xml copy $path.current from $newobj $path.current
     277        [tool] xml copy $currentpath from $newobj $currentpath
    256278
    257279        # also copy to the widget associated with the tree
    258         if {"" != [$newobj element -as type $path.current]} {
    259             set val [$newobj get $path.current]
     280        if {"" != [$newobj element -as type $path]} {
     281            set val [$newobj get $currentpath]
    260282            if {[string length $val] > 0
    261                   || [llength [$newobj children $path.current]] == 0} {
     283                  || [llength [$newobj children $currentpath]] == 0} {
    262284                $_path2widget($path) value $val
    263285            } else {
    264                 set obj [$newobj element -as object $path.current]
     286                set obj [$newobj element -as object $currentpath]
    265287                $_path2widget($path) value $obj
    266288            }
  • trunk/gui/scripts/note.tcl

    r785 r1207  
    8080# ----------------------------------------------------------------------
    8181itcl::body Rappture::Note::value {args} {
    82     error "can't set value"
     82    set onlycheck 0
     83    set i [lsearch -exact $args -check]
     84    if {$i >= 0} {
     85        set onlycheck 1
     86        set args [lreplace $args $i $i]
     87    }
     88
     89    if {[llength $args] == 1} {
     90        if {$onlycheck} {
     91            # someday we may add validation...
     92            return
     93        }
     94        set newval [lindex $args 0]
     95        _setContents $newval
     96        return $newval
     97
     98    } elseif {[llength $args] != 0} {
     99        error "wrong # args: should be \"value ?-check? ?newval?\""
     100    }
     101
     102    #
     103    # Query the value and return.
     104    #
     105    error "don't know how to check value of <note>"
     106    return
    83107}
    84108
Note: See TracChangeset for help on using the changeset viewer.