Skip to content

IDLE configdialog: reduce multiple references to Var names #71575

Open

Description

@terryjreedy
BPO 27388
Nosy @terryjreedy, @csabella
Dependencies
  • bpo-22115: Add new methods to trace Tkinter variables
  • Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.

    Show more details

    GitHub fields:

    assignee = 'https://github.com/terryjreedy'
    closed_at = None
    created_at = <Date 2016-06-26.02:23:35.928>
    labels = ['expert-IDLE', 'type-feature', '3.10']
    title = 'IDLE configdialog: reduce multiple references to Var names'
    updated_at = <Date 2020-06-07.22:02:26.163>
    user = 'https://github.com/terryjreedy'

    bugs.python.org fields:

    activity = <Date 2020-06-07.22:02:26.163>
    actor = 'terry.reedy'
    assignee = 'terry.reedy'
    closed = False
    closed_date = None
    closer = None
    components = ['IDLE']
    creation = <Date 2016-06-26.02:23:35.928>
    creator = 'terry.reedy'
    dependencies = ['22115']
    files = []
    hgrepos = []
    issue_num = 27388
    keywords = []
    message_count = 3.0
    messages = ['269271', '296497', '296608']
    nosy_count = 2.0
    nosy_names = ['terry.reedy', 'cheryl.sabella']
    pr_nums = []
    priority = 'normal'
    resolution = None
    stage = 'test needed'
    status = 'open'
    superseder = None
    type = 'enhancement'
    url = 'https://bugs.python.org/issue27388'
    versions = ['Python 3.10']

    Activity

    1. terryjreedy commented on Jun 26, 2016

      @terryjreedy
      MemberAuthor

      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:

      1. create the Var
      2. 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):
      3. include Var in for loop tuple, to remove callback with
        "var.trace_remove('write', var.trace_info()[0][1])"
        In callback definition:
      4. 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

      def add_traced_var(varname):
          """Create var; bind to varname, append to list, and trace with callback.
      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,

      def VarChanged_spaceNum(self, *params):
          value = self.spaceNum.get()
          self.AddChangedItem('main', 'Indent', 'num-spaces', value)

      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.

    2. self-assigned this
      on Jun 26, 2016
    3. csabella commented on Jun 20, 2017

      @csabella
      Contributor

      Created a pull request for this - "The varnames, like method names, are internal to configdialog and can lowercased (PEP-8) and otherwised changed."

    4. terryjreedy commented on Jun 22, 2017

      @terryjreedy
      MemberAuthor

      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.

    5. transferred this issue fromon Apr 10, 2022
    Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

    Metadata

    Metadata

    Assignees

    Labels

    Projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions