Swank Canvas Widget Saving

swankguy I need a way to save the state of the Swank Canvas. Because I am also rendering information on the canvas that is not just simple canvas items I wanted a way to save the current content that was not just a text file of Tcl commands, or a Tcl array, but that would allow additional information and storage of multiple canvases. I'm working on code that will export/import the canvas as an XML file. The format is influenced by that for SVG, but uses a style consistent with the Tk/Swank canvas. This is definitely a work in progress that if continued will ultimately end up with a DTD or a schema (see A little XML Schema validator.

There is a lot of relevant discussion about ways of saving Tcl related information at Techniques for reading and writing application configuration files including a discussion of using XML files.

Here is example output from a script that saves a canvas.

<?xml version="1.0"?>
<canvas width="1000" height="800">
    <line coords="130.0 50.0 160.0 80.0 190.0 50.0" fill="red" smooth="5" dash="" dashphase="0.0"
        width="4.0" rotate="45.0000012522" shear="0.0 0.0" tags="" state="normal" node=""
        transformer="" capstyle="projecting" joinstyle="miter" arrow="none"
        arrowshape="10.0 20.0 8.0" endstyle="arrow" startstyle="square"/>
    <line coords="130.0 150.0 180.0 150.0" fill="black" smooth="" dash="6 4 2 4 2 4" dashphase="0.0"
        width="1.0" rotate="0.0" shear="0.0 0.0" tags="" state="normal" node="" transformer=""
        capstyle="projecting" joinstyle="miter" arrow="none" arrowshape="8.0 10.0 3.0"
        endstyle="none" startstyle="none"/>
    <line coords="50.0 250.0 80.0 280.0 110.0 250.0" fill="black" smooth="" dash="" dashphase="0.0"
        width="1.0" rotate="0.0" shear="0.0 0.0" tags="" state="normal" node="" transformer=""
        capstyle="projecting" joinstyle="miter" arrow="none" arrowshape="8.0 10.0 3.0"
        endstyle="none" startstyle="none"/>
    <symbols coords="50.0 350.0 80.0 380.0 110.0 350.0" symbol="cross" radius="2.0" rotate="0.0"
        shear="0.0 0.0" tags="" state="normal" node="" transformer=""/>
    <rectangle coords="50.0 550.0 90.0 590.0" width="1.0" texture="" gradient="" fill=""
        outline="black" tags="" transformer="" rotate="0.0" shear="0.0 0.0" state="normal" node="">
        <text textcolor="black" anchor="sw" font=""/>
    </rectangle>
    <rectangle coords="130.0 550.0 170.0 590.0" width="4.0" texture="" gradient="" fill="red"
        outline="blue" tags="" transformer="" rotate="45.0000012522" shear="0.0 0.0" state="normal"
        node="">
        <text textcolor="black" anchor="sw" font=""/>
    </rectangle>
    <rectangle coords="130.0 650.0 170.0 690.0" width="1.0" texture="" gradient="" fill="red"
        outline="black" tags="" transformer="" rotate="0.0" shear="0.0 0.0" state="normal" node="">
        <text textcolor="blue" anchor="c" font="Helvetica 16">Hello</text>
    </rectangle>
    <oval coords="50.0 750.0 90.0 770.0" fill="" outline="black" texture="" gradient="" rotate="0.0"
        shear="0.0 0.0" state="normal" tags="" width="1.0" node="" transformer="">
        <text textcolor="black" anchor="sw" font=""/>
    </oval>
    <oval coords="130.0 750.0 170.0 770.0" fill="red" outline="blue" texture="" gradient=""
        rotate="45.0000012522" shear="0.0 0.0" state="normal" tags="" width="4.0" node=""
        transformer="">
        <text textcolor="black" anchor="sw" font=""/>
    </oval>
    <arc coords="50.0 850.0 90.0 890.0" extent="90.0" start="0.0" style="arc" dash=""
        dashphase="0.0" fill="" outline="black" state="normal" rotate="0.0" shear="0.0 0.0" tags=""
        transformer="" width="1.0" node=""/>
    <polygon coords="130.0 950.0 160.0 980.0 190.0 950.0" dash="." dashphase="0.0" width="4.0"
        fill="red" outline="blue" rotate="45.0000012522" shear="0.0 0.0" tags="" state="normal"
        node="" transformer=""/>
    <segments coords="50.0 1050.0 60.0 1080.0 70.0 1080.0 80.0 1050.0 40.0 1060.0 100.0 1060.0"
        dash="" dashphase="0.0" width="1.0" fill="" outline="black" rotate="0.0" shear="0.0 0.0"
        tags="" state="normal" node="" transformer=""/>
</canvas>