You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
IDLE configdialog: reduce multiple references to Var names #71575
ConfigDialog uses nearl 20 tkinter Vars, and I expect to add more. The name of each appears in at least 6 places.
In one of 'create tab frame' methods:
create the Var
use the Var with at least 1 tk widget
In AttachVarCallbacks method:
3, 4. attach trace with callback with derived name
self.varname.trace_add('write', self.VarChanged_varname)
In remove_var_callbacks method (with delete call already factored out):
include Var in for loop tuple, to remove callback with
"var.trace_remove('write', var.trace_info()[0][1])"
In callback definition:
def VarChanged_varname
The above uses the new trace method names that will be introduced in bpo-22115, which I expect will be applied first. (I might also replace
'VarChanged_' with 'var_changed_' or something shorter, but this is not relevant here.)
I propose to consolidate 1, 3, & 4 by replacing AttachVarCallbacks with
varname must match use in caller and callback def.
"""
var = tk.StringVar(self.root)
setattr(self, varname, var)
self.vars.append(var)
cbsuffix = 'font' if varname.startswith('font') else varname
var.trace_add('write', self.getattr('VarChanged_' + cbsuffix))
The cbsuffix local takes care of the complication that the 3 'fontWxyz' vars need the same callback. In any Var are not StringVars, add vartype parameter.
Each tab frame creation method would call add_traced_var within a varname loop. The current varname tuple for 5. would be replaced with self.vars, which should then be cleared. This will leave 3 name occurrences that must match instead of 6.
---
I believe 1-6 is complete. Varnames are translated to config item names within the callbacks, so do not have to match. For instance,
translated 'spaceNum' to 'num-spaces'. On the other hand, I an not sure why the difference. For back compatibility, config names are fixed. The varnames, like method names, are internal to configdialog and can lowercased (PEP-8) and otherwised changed.
---
For testing, I will embed the add and delete methods in a dummy class with a couple of dummy callbacks. Then add, introspect, delete, and introspect again.
I moved PR 2307 to a new issue, bpo-30728 Modernize configdialog. My comment that internal Var names "can lowercased (PEP-8) and otherwised changed" was anticipating such an issue. The point for this issue was to contrast Var names with the cross-version config names that we must not change.
I don't expect anyone else to fully understand this without a couple of hours of code study.
Once bpo-22115 was merged, I could have gone ahead. Since I did not, I should now wait for at least part of PR 2307 and bpo-30728 since the patch for this would break parts of the existing new patch. I could work on a new test though.
Activity
terryjreedy commentedon Jun 26, 2016
ConfigDialog uses nearl 20 tkinter Vars, and I expect to add more. The name of each appears in at least 6 places.
In one of 'create tab frame' methods:
In AttachVarCallbacks method:
3, 4. attach trace with callback with derived name
self.varname.trace_add('write', self.VarChanged_varname)
In remove_var_callbacks method (with delete call already factored out):
"var.trace_remove('write', var.trace_info()[0][1])"
In callback definition:
The above uses the new trace method names that will be introduced in bpo-22115, which I expect will be applied first. (I might also replace
'VarChanged_' with 'var_changed_' or something shorter, but this is not relevant here.)
I propose to consolidate 1, 3, & 4 by replacing AttachVarCallbacks with
The cbsuffix local takes care of the complication that the 3 'fontWxyz' vars need the same callback. In any Var are not StringVars, add vartype parameter.
Each tab frame creation method would call add_traced_var within a varname loop. The current varname tuple for 5. would be replaced with self.vars, which should then be cleared. This will leave 3 name occurrences that must match instead of 6.
---
I believe 1-6 is complete. Varnames are translated to config item names within the callbacks, so do not have to match. For instance,
translated 'spaceNum' to 'num-spaces'. On the other hand, I an not sure why the difference. For back compatibility, config names are fixed. The varnames, like method names, are internal to configdialog and can lowercased (PEP-8) and otherwised changed.
---
For testing, I will embed the add and delete methods in a dummy class with a couple of dummy callbacks. Then add, introspect, delete, and introspect again.
csabella commentedon Jun 20, 2017
Created a pull request for this - "The varnames, like method names, are internal to configdialog and can lowercased (PEP-8) and otherwised changed."
terryjreedy commentedon Jun 22, 2017
I moved PR 2307 to a new issue, bpo-30728 Modernize configdialog. My comment that internal Var names "can lowercased (PEP-8) and otherwised changed" was anticipating such an issue. The point for this issue was to contrast Var names with the cross-version config names that we must not change.
I don't expect anyone else to fully understand this without a couple of hours of code study.
Once bpo-22115 was merged, I could have gone ahead. Since I did not, I should now wait for at least part of PR 2307 and bpo-30728 since the patch for this would break parts of the existing new patch. I could work on a new test though.