Changeset 1225 for trunk


Ignore:
Timestamp:
Nov 20, 2008 5:17:50 AM (15 years ago)
Author:
dkearney
Message:

adjusting loader so users can say where they want to load the elements of the example xml try. this is done using the <copy> stanza. you can <copy> the data from the <from> location in the example directory's xml file being loaded to the <to> position in the main xml file. this feature is used in some of the photonicsdb applications where there are multiple layers of materials, you need each layer to have access to the whole list of materials, but you dont want to create a specific material example xml file for each layer. instead you can use use one example xml file and copy it to different locations in the tree.

in a loader it looks like this:

<loader>

<about>

<label>Material</label>
<description>Choose the material for layer 1.</description>

</about>
<example>*.xml</example>
<copy>

<from>input.note</from>
<to>input.group(tabs).group(layer1).note</to>

</copy>

</loader>

this may break the loader for some applications, i'm not sure how yet.

Location:
trunk/gui/scripts
Files:
2 edited

Legend:

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

    r1207 r1225  
    270270            set currentpath $path.$_type2curpath($type)
    271271        } else {
    272             # default incase i forgot an inpuit type in _type2curpath
     272            # default incase i forgot an input type in _type2curpath
    273273            set currentpath $path.current
    274274        }
    275275
    276276        # copy new value to the XML tree
    277         [tool] xml copy $currentpath from $newobj $currentpath
     277        # we only copy the values if they existed in newobj
     278        # so we don't overwrite values that were set in previous loads.
     279        # this is needed for when the users specify copy.from and copy.to
     280        # in a loader. in this case, _path2widget holds a list of all
     281        # widgets. if there are two loaders loading two different widgets,
     282        # and each loader uses the copy from/to functionality,
     283        # the second load could wipe out the values set in the first load
     284        # because on the second load, the copied paths from the first load no
     285        # longer exist in newobj and blanks are copied to the paths
     286        # in [tool] xml set by the first loader. the solution is to check
     287        # newobj and see if the path exists. if the path exists, then we copy
     288        # it over to [tool] xml, otherwise we ignore it.
     289        if {"" != [$newobj element -as component $currentpath]} {
     290            [tool] xml copy $currentpath from $newobj $currentpath
     291        }
    278292
    279293        # also copy to the widget associated with the tree
  • trunk/gui/scripts/loader.tcl

    r1077 r1225  
    4242    private variable _dnpaths ""  ;# list of download element paths
    4343    private common _dnpath2state  ;# maps download path => yes/no state
     44    private variable _copyfrom "" ;# copy xml objects from here in example lib
     45    private variable _copyto ""   ;# copy xml objects here in example lib
     46    private variable _label2file  ;# maps combobox labels to filenames
    4447}
    4548
     
    199202                    if {![info exists entries($label)]} {
    200203                        set entries($label) $obj
     204                        set _label2file($label) [file tail $fname]
    201205                    }
    202206
     
    215219    }
    216220
     221    set _copyfrom [$_owner xml get $path.copy.from]
     222    set _copyto [$_owner xml get $path.copy.to]
     223
    217224    #
    218225    # Assign the default value to this widget, if there is one.
     
    336343        $itk_component(combo) component entry configure -state disabled
    337344    } elseif {$obj != "" && $itk_option(-tool) != ""} {
     345        if {("" != $_copyfrom) && ("" != $_copyto)} {
     346            $obj copy $_copyto from $_copyfrom
     347        }
     348        $_owner xml put $_path.file $_label2file($newval)
    338349        $itk_option(-tool) load $obj
    339350        set _lastlabel $newval
Note: See TracChangeset for help on using the changeset viewer.