• canvas/tkpath load/save

    From Mark Summerfield@m.n.summerfield@gmail.com to comp.lang.tcl on Wed Nov 19 09:37:49 2025
    From Newsgroup: comp.lang.tcl

    I'm considering experimenting with canvas or more likely with tkpath.
    I
    want to create an interactive GUI program so that I can create
    shapes and modify their properties.
    So I need to be able to save all the items that are created and to
    be able to load them back in again.

    With the tk text widget saving can be done using the dump command and
    loading isn't too difficult to do.

    But I can't see an equivalent for canvas or for tkpath.

    Do canvas or tkpath have support for loading/saving?

    (If they don't I can envisage creating my own file format that
    keeps track of each item but I don't want to reinvent if this is
    already present.)
    --- Synchronet 3.21a-Linux NewsLink 1.2
  • From Arjen@user153@newsgrouper.org.invalid to comp.lang.tcl on Wed Nov 19 11:57:54 2025
    From Newsgroup: comp.lang.tcl


    Mark Summerfield <m.n.summerfield@gmail.com> posted:

    I'm considering experimenting with canvas or more likely with tkpath.
    I
    want to create an interactive GUI program so that I can create
    shapes and modify their properties.
    So I need to be able to save all the items that are created and to
    be able to load them back in again.

    With the tk text widget saving can be done using the dump command and
    loading isn't too difficult to do.

    But I can't see an equivalent for canvas or for tkpath.

    Do canvas or tkpath have support for loading/saving?

    (If they don't I can envisage creating my own file format that
    keeps track of each item but I don't want to reinvent if this is
    already present.)

    The canvas (and tkpath as well, I guess) offers introspection so that you can indeed save the contents and load it in again. A source of inspiration might be tkpaint (see the Wiki), though I do not know the current status.

    Regards,

    Arjen
    --- Synchronet 3.21a-Linux NewsLink 1.2
  • From Mark Summerfield@m.n.summerfield@gmail.com to comp.lang.tcl on Thu Nov 20 07:49:56 2025
    From Newsgroup: comp.lang.tcl

    On Wed, 19 Nov 2025 11:57:54 GMT, Arjen wrote:

    Mark Summerfield <m.n.summerfield@gmail.com> posted:

    I'm considering experimenting with canvas or more likely with tkpath.
    I
    want to create an interactive GUI program so that I can create
    shapes and modify their properties.
    So I need to be able to save all the items that are created and to
    be able to load them back in again.

    With the tk text widget saving can be done using the dump command and
    loading isn't too difficult to do.

    But I can't see an equivalent for canvas or for tkpath.

    Do canvas or tkpath have support for loading/saving?

    (If they don't I can envisage creating my own file format that
    keeps track of each item but I don't want to reinvent if this is
    already present.)

    The canvas (and tkpath as well, I guess) offers introspection so that you can indeed save the contents and load it in again. A source of inspiration might be tkpaint (see the Wiki), though I do not know the current status.

    Regards,

    Arjen

    Unfortunately none of the links on that page https://wiki.tcl-lang.org/page/Tkpaint work.

    I'll see how far I get on my own.

    Thanks.
    --- Synchronet 3.21a-Linux NewsLink 1.2
  • From Ralf Fassel@ralfixx@gmx.de to comp.lang.tcl on Thu Nov 20 10:36:27 2025
    From Newsgroup: comp.lang.tcl

    * Mark Summerfield <m.n.summerfield@gmail.com>
    | On Wed, 19 Nov 2025 11:57:54 GMT, Arjen wrote:
    | > The canvas (and tkpath as well, I guess) offers introspection so that you can
    | > indeed save the contents and load it in again. A source of inspiration might
    | > be tkpaint (see the Wiki), though I do not know the current status. --<snip-snip>--

    | Unfortunately none of the links on that page
    | https://wiki.tcl-lang.org/page/Tkpaint work.

    | I'll see how far I get on my own.

    For the canvas:
    loop
    canvas list all => all currently defined objects in stacking order
    canvas type id => oval rect ...
    canvas coords id => where is it
    canvas itemconfigure id => what does it look like

    should get you some way.

    Can't say for tkpath, but the procedure would be similar.

    HTH
    R'
    --- Synchronet 3.21a-Linux NewsLink 1.2
  • From Harald Oehlmann@wortkarg3@yahoo.com to comp.lang.tcl on Thu Nov 20 10:54:00 2025
    From Newsgroup: comp.lang.tcl

    Am 20.11.2025 um 10:36 schrieb Ralf Fassel:
    * Mark Summerfield <m.n.summerfield@gmail.com>
    | On Wed, 19 Nov 2025 11:57:54 GMT, Arjen wrote:
    | > The canvas (and tkpath as well, I guess) offers introspection so that you can
    | > indeed save the contents and load it in again. A source of inspiration might
    | > be tkpaint (see the Wiki), though I do not know the current status. --<snip-snip>--

    | Unfortunately none of the links on that page
    | https://wiki.tcl-lang.org/page/Tkpaint work.

    | I'll see how far I get on my own.

    For the canvas:
    loop
    canvas list all => all currently defined objects in stacking order
    canvas type id => oval rect ...
    canvas coords id => where is it
    canvas itemconfigure id => what does it look like

    should get you some way.

    Can't say for tkpath, but the procedure would be similar.

    HTH
    R'

    Maybe directly ping René Zaumseil or Manfred Rosenberger.
    To my knowledge, tk path emphasis a lot of svg compatibility.It is
    possible to save a svg file.
    It might also possible to load it.

    Take care,
    Harald
    --- Synchronet 3.21a-Linux NewsLink 1.2
  • From Ian@gay@sfuu.ca to comp.lang.tcl on Thu Nov 20 11:35:45 2025
    From Newsgroup: comp.lang.tcl

    Mark Summerfield wrote:

    On Wed, 19 Nov 2025 11:57:54 GMT, Arjen wrote:

    Mark Summerfield <m.n.summerfield@gmail.com> posted:

    I'm considering experimenting with canvas or more likely with
    tkpath. I
    want to create an interactive GUI program so that I can create
    shapes and modify their properties.
    So I need to be able to save all the items that are created and to
    be able to load them back in again.

    With the tk text widget saving can be done using the dump command
    and loading isn't too difficult to do.

    But I can't see an equivalent for canvas or for tkpath.

    Do canvas or tkpath have support for loading/saving?

    (If they don't I can envisage creating my own file format that
    keeps track of each item but I don't want to reinvent if this is
    already present.)

    The canvas (and tkpath as well, I guess) offers introspection so that
    you can indeed save the contents and load it in again. A source of
    inspiration might be tkpaint (see the Wiki), though I do not know the
    current status.

    Regards,

    Arjen

    Unfortunately none of the links on that page https://wiki.tcl-lang.org/page/Tkpaint work.

    I'll see how far I get on my own.

    Thanks.

    In my experience it's not a good idea to use canvas or text widgets as
    memory. It's simpler to have some data structure in real memory to
    contain all the information, and use the text or canvas simply as a
    display device, driven by a routine that accesses the real memory.
    --
    *********** To reply by e-mail, make w single in address **************
    --- Synchronet 3.21a-Linux NewsLink 1.2
  • From Emiliano@emiliano@example.invalid to comp.lang.tcl on Thu Nov 20 20:23:56 2025
    From Newsgroup: comp.lang.tcl

    On Thu, 20 Nov 2025 10:36:27 +0100
    Ralf Fassel <ralfixx@gmx.de> wrote:

    [...]
    For the canvas:
    loop
    canvas list all => all currently defined objects in stacking order
    canvas type id => oval rect ...
    canvas coords id => where is it
    canvas itemconfigure id => what does it look like

    should get you some way.

    Except for window items, where it would take a bit more work, this code
    works well serializing/deserializing canvas items:

    # start
    proc canvas_dump {c} {
    lmap item [$c find all] {
    set type [$c type $item]
    # skip if item type is window
    if {$type eq "window"} continue
    set res [list $type [$c coords $item]]
    foreach opt [$c itemconfigure $item] {
    lappend res [lindex $opt 0] [lindex $opt end]
    }
    set res
    }
    }

    proc canvas_restore {c dump} {
    foreach item $dump {
    $c create {*}$item
    }
    }
    # end

    This will copy items *appearance* from a canvas to another, but will
    not copy behaviour. You have to instrospect bindings, at both canvas
    and items level (tags and id's), to get a better copy.

    Regards.
    --
    Emiliano <emiliano@example.invalid>
    --- Synchronet 3.21a-Linux NewsLink 1.2
  • From Ralf Fassel@ralfixx@gmx.de to comp.lang.tcl on Fri Nov 21 11:48:27 2025
    From Newsgroup: comp.lang.tcl

    * Emiliano <emiliano@example.invalid>
    --<snip-snip>--
    | Except for window items, where it would take a bit more work, this code
    | works well serializing/deserializing canvas items:
    --<snip-snip>--
    | This will copy items *appearance* from a canvas to another, but will
    | not copy behaviour. You have to instrospect bindings, at both canvas
    | and items level (tags and id's), to get a better copy.

    Ah, right, window items, bindings etc. There always is more to it than
    it seems at the first glance :-)

    R'
    --- Synchronet 3.21a-Linux NewsLink 1.2
  • From Olivier@user1108@newsgrouper.org.invalid to comp.lang.tcl on Fri Nov 21 15:01:55 2025
    From Newsgroup: comp.lang.tcl


    Mark Summerfield <m.n.summerfield@gmail.com> posted:

    Do canvas or tkpath have support for loading/saving?

    (If they don't I can envisage creating my own file format that
    keeps track of each item but I don't want to reinvent if this is
    already present.)

    Ulis had made such work before : https://wiki.tcl-lang.org/page/Serializing+a+canvas+widget
    (and should work for windows)
    TkPaint is much more complex because it manages options : colors, zoom, grid, .... and has specific
    specific tools : deform, rectangle with round corners ...
    Some parts were inspired by Impress : https://www.ntlug.org/~ccox/impress/ which was sophisticated at the time.
    --- Synchronet 3.21a-Linux NewsLink 1.2
  • From Mark Summerfield@m.n.summerfield@gmail.com to comp.lang.tcl on Fri Nov 21 17:32:22 2025
    From Newsgroup: comp.lang.tcl

    On Thu, 20 Nov 2025 20:23:56 -0300, Emiliano wrote:

    On Thu, 20 Nov 2025 10:36:27 +0100
    Ralf Fassel <ralfixx@gmx.de> wrote:

    [...]
    For the canvas:
    loop
    canvas list all => all currently defined objects in stacking order
    canvas type id => oval rect ...
    canvas coords id => where is it
    canvas itemconfigure id => what does it look like

    should get you some way.

    Except for window items, where it would take a bit more work, this code
    works well serializing/deserializing canvas items:

    # start
    proc canvas_dump {c} {
    lmap item [$c find all] {
    set type [$c type $item]
    # skip if item type is window
    if {$type eq "window"} continue
    set res [list $type [$c coords $item]]
    foreach opt [$c itemconfigure $item] {
    lappend res [lindex $opt 0] [lindex $opt end]
    }
    set res
    }
    }

    proc canvas_restore {c dump} {
    foreach item $dump {
    $c create {*}$item
    }
    }
    # end

    This will copy items *appearance* from a canvas to another, but will
    not copy behaviour. You have to instrospect bindings, at both canvas
    and items level (tags and id's), to get a better copy.

    Regards.

    Thank you and the others who have replied.

    In the end I came to the same conclusion about canvas as Ian and have
    created a SQLite database to store my canvas items data, especially
    since I want to support undo/redo. (I don't agree about tk's text
    widget though; I can dump & load that just fine.)

    I've also decided to start out with canvas rather than tkpath.

    However, one problem I've hit straight away is that I can't work out
    how to get and set a canvas item's z-order -- or stacking order in
    canvas terminology. (I am only interested in shapes, not nested
    widgets or windows.) I know I can raise and lower and can use
    `canvas find all` to get an ordering, so I guess I'll have to
    do it that way.
    --- Synchronet 3.21a-Linux NewsLink 1.2