chrstphrchvz / perl-tcl-ptk

Tcl::pTk - Interface to Tcl/Tk with Perl/Tk compatible syntax
https://metacpan.org/pod/Tcl::pTk
Other
8 stars 2 forks source link

trace callback not entered when variable accessed from Tcl #22

Open chrstphrchvz opened 3 years ago

chrstphrchvz commented 3 years ago

From https://rt.cpan.org/Ticket/Display.html?id=128677:

I noticed that the floor plan canvas demo (floor.pl) is partially broken: typing a valid room number does not cause the room to light up. Hovering over rooms still causes the entry to change though.

I tried experimenting with entry.t and trace.t, and compared behaviors under Perl/Tk and Tcl::pTk to see what might be missing. In Perl/Tk, if the text in an entry widget with a traced textvariable changes (due to the user typing, or programmatically changing it e.g. via $e1->insert()), the trace callback is entered and is responsible for updating the textvariable (by returning a value). But in Tcl::pTk, any changes made by the widget from Tcl code or user interaction will directly update the textvariable without entering the callback; the callback is only entered when the textvariable is read or written from Perl code.

A TODO test was added to t/trace.t in 1.08_02 for this issue: 838f409

I am still not sure how this can be addressed. I would think Tcl's trace add variable … is needed, but also that this approach would require rewriting Tcl::pTk::Trace and Tcl::pTk::Tie::Watch (which seem copied as-is from Perl/Tk).