This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

classification
Title: Add new methods to trace Tkinter variables
Type: enhancement Stage: resolved
Components: Tkinter Versions: Python 3.6, Python 3.5, Python 2.7
process
Status: closed Resolution: fixed
Dependencies: Superseder:
Assigned To: serhiy.storchaka Nosy List: python-dev, serhiy.storchaka, terry.reedy
Priority: normal Keywords: patch

Created on 2014-07-31 14:47 by serhiy.storchaka, last changed 2022-04-11 14:58 by admin. This issue is now closed.

Files
File name Uploaded Description Edit
tkinter_trace_variable_3.patch serhiy.storchaka, 2014-08-17 16:42 review
tkinter_trace_variable_4.patch serhiy.storchaka, 2014-08-18 12:43 review
tkinter_trace_variable_5.patch serhiy.storchaka, 2016-06-19 07:47 review
tkinter_trace_variable_6.patch serhiy.storchaka, 2016-06-25 20:36 review
Messages (13)
msg224407 - (view) Author: Serhiy Storchaka (serhiy.storchaka) * (Python committer) Date: 2014-07-31 14:47
Command used to monitor Tcl variable access ("trace variable", "trace vdelete", "trace vinfo") are deprecated and will likely be removed in a future version of Tcl. Replacements ("trace add variable", "trace remove variable", "trace info variable") use slightly different syntax (operations are specified as a list of words "array", "read", "write" and "unset" instead of a string containing characters "a", "r", "w" and "u"). Therefore we need new set of methods.

Proposed preliminary patch adds trace_add, trace_remove and trace_info methods to the Variable class. It will be changed after applying issue22068 patch. Tests for old methods will be backported to older Python versions.
msg225449 - (view) Author: Serhiy Storchaka (serhiy.storchaka) * (Python committer) Date: 2014-08-17 16:42
Synchronized with the tip.
msg225479 - (view) Author: Terry J. Reedy (terry.reedy) * (Python committer) Date: 2014-08-18 00:51
trace_add:

"list or tuple" (of such strings.)  Can we say 'sequence' (or even set or iterable) or is the requirement specifically tuple or list?

Does tk call the traceback function with any args it supplies(other than those passed in)? (In other words, is the callback affected by the #22214 proposal?)

*args is a tuple of objects, not parameters (names). I would just say "Additional arguments are passed to the traceback call".

trace_remove:

"Should be same as were specified in trace_add()." Is a subset not allowed to remove a subset of the registrations currently allowed?  Does trying to delete other modes raise TclError?  If both are so, I would say something like "Must be a subset of current trace modes.". 

"Additional parameters should be same as were specified in trace_add()."
Again, /parameters/arguments/. That aside, remembering and passing the arguments back seems like a bizarre requirement that makes not sense. What happens if one does not, or gets it wrong? It the args are really required exactly, then is seems that trace_add should return (cbname,) + args to be passed back to trace_remove as cbname_args.

Alternatively, could *args (and mode) be retrieved from trace_info?

trace_variable, _vdelete

" This method is deprecated and will likely be removed in a future version of Tcl."  Slightly more accurate would be "This deprecated method wraps a deprecated tcl method that will likely be removed in the future."
msg225490 - (view) Author: Serhiy Storchaka (serhiy.storchaka) * (Python committer) Date: 2014-08-18 12:43
> "list or tuple" (of such strings.)  Can we say 'sequence' (or even set or
> iterable) or is the requirement specifically tuple or list?

No. The call() method accepted only tuples, and since issue21525 it now 
supports lists.

> Does tk call the traceback function with any args it supplies(other than
> those passed in)? (In other words, is the callback affected by the #22214
> proposal?)

Tcl calls the traceback function with stringified arguments. No, this is not 
affected by the #22214 proposal. And only types which are supported by Tkinter 
(int, bool, float, str, bytes, tuple, list, Tcl_Obj) are allowed. But this 
behavior can be changed in future versions of Tcl..

> "Should be same as were specified in trace_add()." Is a subset not allowed
> to remove a subset of the registrations currently allowed?  Does trying to
> delete other modes raise TclError?  If both are so, I would say something
> like "Must be a subset of current trace modes.".

Unfortunately both are no. If you pass wrong mode, trace_remove() will 
silently finished, but next attempt to call a callback will raise TclError 
(because a command is already deleted). Fixed in next patch and should be 
backported.

> That aside, remembering and passing the
> arguments back seems like a bizarre requirement that makes not sense. What
> happens if one does not, or gets it wrong?

Same bad things as when pass wrong mode.

> It the args are really required
> exactly, then is seems that trace_add should return (cbname,) + args to be
> passed back to trace_remove as cbname_args.

Looks good.

> Alternatively, could *args (and mode) be retrieved from trace_info?

You can retrieve mode, cbname and (stringified) args from trace_info. Currently 
following code removes all callbacks from variable:

for mode, cbname_args in v.trace_info():
    v.trace_remove(mode, *cbname_args)

With next patch '*' is not needed.

Thank you for the review. Updated patch addresses all your comments.
msg268845 - (view) Author: Serhiy Storchaka (serhiy.storchaka) * (Python committer) Date: 2016-06-19 07:47
Updated patch provides simplified interface. The support of passing callback arguments is removed. This complicates an interface and is not needed since Python supports closure and the support of callback arguments was more limited (supported only limited set of types and arguments are converted to str).

Added an entry in What's News.
msg269092 - (view) Author: Terry J. Reedy (terry.reedy) * (Python committer) Date: 2016-06-22 22:53
I gather that 'add', 'delete', and 'info' replace 'variable', 'vdelete', and 'vinfo'.  Also see review.  Deprecation period should be fairly long.  Of course, a currently hypothetical tcl/tk 9.0 with old stuff gone would make it immediate for users of 9.0.

Applies cleanly and tests pass, but do not hardly interact with the patch.  More importantly, IDLE starts fresh, option dialog comes up and appears to work.  So old functions continue to work.

The real test from IDLE would be to recode configdialog to use the new functions and then test.  I am thinking about how to test configdialog enough that I am willing to refactor it for real.
msg269253 - (view) Author: Serhiy Storchaka (serhiy.storchaka) * (Python committer) Date: 2016-06-25 20:36
Thank you for your review Terry. Here is updated patch. IDLE now uses new API.
msg269272 - (view) Author: Terry J. Reedy (terry.reedy) * (Python committer) Date: 2016-06-26 02:26
What's New: patchcheck found trailing whitespace to remove; it contains some additions that appear to belong to another issue.

configdialog change looks good and dialog still works.

I am expecting to add more Vars sometime soon, though probably not in the next few days.  Before I do, I want to reduce the repetition of names and remove the repetition of trace_add calls.  I just opened #27388.
msg269276 - (view) Author: Serhiy Storchaka (serhiy.storchaka) * (Python committer) Date: 2016-06-26 05:41
Maybe omit the mention of the array mode since it can't be used with variables created with Tkinter wrapper?
msg269277 - (view) Author: Terry J. Reedy (terry.reedy) * (Python committer) Date: 2016-06-26 05:59
Good idea.  Anyone who knows enough to create one by calling into tcl, assuming that is possible, should know that the methods apply.  Everyone else, like me, will just be confused.
msg269280 - (view) Author: Roundup Robot (python-dev) (Python triager) Date: 2016-06-26 06:47
New changeset a201180c0f77 by Serhiy Storchaka in branch 'default':
Issue #22115: Added methods trace_add, trace_remove and trace_info in the
https://hg.python.org/cpython/rev/a201180c0f77
msg269288 - (view) Author: Roundup Robot (python-dev) (Python triager) Date: 2016-06-26 14:48
New changeset 77378dce6bcf by Serhiy Storchaka in branch '2.7':
Issue #22115: Fixed tracing Tkinter variables.
https://hg.python.org/cpython/rev/77378dce6bcf

New changeset 293ec9547334 by Serhiy Storchaka in branch '3.5':
Issue #22115: Fixed tracing Tkinter variables:
https://hg.python.org/cpython/rev/293ec9547334

New changeset c4839c36a71f by Serhiy Storchaka in branch 'default':
Issue #22115: Updated Misc/NEWS.
https://hg.python.org/cpython/rev/c4839c36a71f
msg269290 - (view) Author: Serhiy Storchaka (serhiy.storchaka) * (Python committer) Date: 2016-06-26 14:51
Backported fixes for old tracing methods. Unfortunately the tracing in the "u" mode doesn't work in 2.7. This is related to some differences in GC. I don't think this is important and close this issue.
History
Date User Action Args
2022-04-11 14:58:06adminsetgithub: 66313
2017-06-22 00:04:25terry.reedylinkissue27388 dependencies
2016-06-26 14:51:23serhiy.storchakasetstatus: open -> closed
versions: + Python 2.7, Python 3.5
messages: + msg269290

resolution: fixed
stage: patch review -> resolved
2016-06-26 14:48:18python-devsetmessages: + msg269288
2016-06-26 06:47:23python-devsetnosy: + python-dev
messages: + msg269280
2016-06-26 05:59:47terry.reedysetmessages: + msg269277
2016-06-26 05:41:23serhiy.storchakasetmessages: + msg269276
2016-06-26 02:26:20terry.reedysetmessages: + msg269272
2016-06-25 20:36:26serhiy.storchakasetfiles: + tkinter_trace_variable_6.patch

messages: + msg269253
2016-06-22 22:53:48terry.reedysetmessages: + msg269092
2016-06-19 07:47:35serhiy.storchakasetfiles: + tkinter_trace_variable_5.patch
assignee: serhiy.storchaka
messages: + msg268845

versions: + Python 3.6, - Python 3.5
2014-08-18 12:43:50serhiy.storchakasetfiles: + tkinter_trace_variable_4.patch

messages: + msg225490
2014-08-18 00:51:07terry.reedysetmessages: + msg225479
2014-08-17 16:43:23serhiy.storchakasetfiles: - tkinter_trace_variable_2.patch
2014-08-17 16:42:35serhiy.storchakasetfiles: + tkinter_trace_variable_3.patch

messages: + msg225449
stage: patch review
2014-08-01 23:00:44terry.reedysetnosy: + terry.reedy
2014-07-31 14:47:51serhiy.storchakacreate