Skip to content

crash when redraw with Plotchart on window resize event #14

Description

@buthanoid

I use Tklib (I manually dl it and package require it).

I draw a plot in a canvas. I want my plot to resize when the window resize. So I use a bind on the Configure event, and I empty the canvas and redraw the plot.

however it sometimes fails, therefore I had to add a try catch to prevent a crash. Surely there is a better way of doing this.

using TclTk

# git clone git@github.com:tcltk/tklib.git
tcl_eval("lappend auto_path \"tklib/modules/\" ")

tcl_eval("package require Plotchart")

toplevel1 = Toplevel()

canvas1 = nothing

function create_canvas1()
    global canvas1
    canvas1 = Canvas(toplevel1)
    canvas1.pack(side=:left, expand=true, fill=:both)
end

function redraw_canvas1()
    global canvas1
    try
        tcl_eval("$canvas1 delete all")

        vx = (0:10)
        vy = (vx .^2)

        tcl_eval("set plot1 [::Plotchart::createXYPlot $canvas1 {0 10 1} {0 100 10}]")

        for (x,y) in zip(vx,vy)
            tcl_eval(string("\$plot1 plot courbe1 ", x, " ", y))
        end

    catch err
        @error err
        if !isnothing(canvas1)
            tcl_exec("::destroy", canvas1)
        end
        create_canvas1()
        redraw_canvas1()
    end
end

create_canvas1()
redraw_canvas1()

cb_handler_toplevel1_resize = TclCallback(args -> redraw_canvas1())
tcl_exec(:bind, toplevel1, "<Configure>", (cb_handler_toplevel1_resize.name,))

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Fields

    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions