Skip to content

IDLE: configdialog/fonts: change font when select by key up/down #75053

Closed

Description

@mlouielu
mannequin
BPO 30870
Nosy @terryjreedy, @serhiy-storchaka, @mlouielu
PRs
  • bpo-30870: IDLE: Change sample font when select by key-up/down #2617
  • [3.6] bpo-30870: IDLE: Change sample font when select by key-up/down … #2640
  • bpo-30870: IDLE -- fix logic error in eae2537. #2660
  • [3.6] bpo-30870: IDLE -- fix logic error in eae2537. (GH-2660) #2661
  • bpo-30870: IDLE: Add configdialog fontlist unittest #2666
  • [3.6] bpo-30870: IDLE: Add configdialog fontlist selection unittest (… #2701
  • Files
  • tests.py
  • 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 = <Date 2017-07-21.02:34:32.545>
    created_at = <Date 2017-07-07.07:51:29.389>
    labels = ['expert-IDLE', 'type-feature', '3.7']
    title = 'IDLE: configdialog/fonts: change font when select by key up/down'
    updated_at = <Date 2017-07-21.02:34:32.544>
    user = 'https://github.com/mlouielu'

    bugs.python.org fields:

    activity = <Date 2017-07-21.02:34:32.544>
    actor = 'terry.reedy'
    assignee = 'terry.reedy'
    closed = True
    closed_date = <Date 2017-07-21.02:34:32.545>
    closer = 'terry.reedy'
    components = ['IDLE']
    creation = <Date 2017-07-07.07:51:29.389>
    creator = 'louielu'
    dependencies = []
    files = ['47006']
    hgrepos = []
    issue_num = 30870
    keywords = []
    message_count = 21.0
    messages = ['297867', '298003', '298004', '298006', '298017', '298075', '298076', '298121', '298122', '298123', '298124', '298127', '298130', '298132', '298138', '298197', '298252', '298260', '298324', '298328', '298760']
    nosy_count = 3.0
    nosy_names = ['terry.reedy', 'serhiy.storchaka', 'louielu']
    pr_nums = ['2617', '2640', '2660', '2661', '2666', '2701']
    priority = 'normal'
    resolution = 'fixed'
    stage = 'resolved'
    status = 'closed'
    superseder = None
    type = 'enhancement'
    url = 'https://bugs.python.org/issue30870'
    versions = ['Python 3.6', 'Python 3.7']

    Activity

    1. mlouielu commented on Jul 7, 2017

      mlouielumannequin
      MannequinAuthor

      Add event for KeyRelease-Up and KeyRelease-Down to change sample font.

      Current code only changed font when using button-click on listbox.

    2. added
      type-feature
      on Jul 8, 2017
    3. terryjreedy commented on Jul 9, 2017

      @terryjreedy
      Member

      New changeset bb2bae8 by terryjreedy (Louie Lu) in branch 'master':
      bpo-30870: IDLE: Change sample font when select by key-up/down (bpo-2617)
      bb2bae8

    4. terryjreedy commented on Jul 9, 2017

      @terryjreedy
      Member

      If one scrolls with the mousewheel or scrollbar, the selection does not change and the example should not change, and I presume it will not with the patch. If one presses up or down, the selection does change, just as if one clicked, and the example should change. I consider it a bug that it does not. Good catch.

    5. terryjreedy commented on Jul 9, 2017

      @terryjreedy
      Member

      New changeset 7ab3342 by terryjreedy in branch '3.6':
      [3.6] bpo-30870: IDLE: Change sample font when select by key-up/down (GH-2617) (bpo-2640)
      7ab3342

    6. terryjreedy commented on Jul 10, 2017

      @terryjreedy
      Member

      We already know that setting StringVar font_name triggers a change to changes. We also know that manually clicking or Up or Down triggers <<ListBoxSelect>>, which sets font_name and redraws the box. The challenge is to do something that will trigger the virtual event. Then we can write a test methods something like

          def test_sample(self):
              fontlist = configure.fontlist
              if fontlist.size():
                  name0 = fontlist.get(0).lower()
                  # fontlist.selection_set(0)  # or something
                  print('\n', changes)  # temp to testing that changes changes
                  self.assertEqual(changes['main']['EditorWindow']['font'], name0)
      But selection_set does not trigger the event.  After fiddling around with various bindings event_generate()s and update()s and update_idletasks(), I concluded, again, that either event_generate or its documentation is badly broken.  The only thing I got to work in hours of experiments is this:
      
      import tkinter as tk
      root = tk.Tk()
      seq = '<ButtonRelease-1>'
      root.bind(seq, lambda event: print('generated', event))
      root.update_idletasks()  # or update()
      root.event_generate(seq)
      # update here fails

      Adding a widget and binding to the widget always failed.

      Here is my attempt using Serhiy's simulate_mouse_click. (This goes in test_configdialog.FontTabTest.

          def test_sample(self):
              fontlist = configure.fontlist
              if fontlist.size():
                  name0 = fontlist.get(0).lower()
                  fontlist.see(0)
                  x, y, dx, dy = fontlist.bbox(0)
                  fontlist.bind('<ButtonRelease-1>', lambda event: print(event))
                  mouse_click(fontlist, x + dx//2, y + dy//2)
                  fontlist.update()
                  print('\n', changes)  # temporary, see if changes has anything
                  self.assertEqual(changes['main']['EditorWindow']['font'], name0)

      Serhiy, do you have any idea why I cannot get event_generate to work for a listbox, even with your function? I have tried somewhere close to 20 variations.

    7. terryjreedy commented on Jul 10, 2017

      @terryjreedy
      Member

      Serhiy, I tried tkinter.test.support.simulate_mouse_click to test this patch but it seems not to work. Code at end of previous message. Any idea on how to fix?

    8. serhiy-storchaka commented on Jul 10, 2017

      @serhiy-storchaka
      Member

      It isn't my. It was added by Guilherme in r69050.

      I'll take a look at code tomorrow.

    9. serhiy-storchaka commented on Jul 11, 2017

      @serhiy-storchaka
      Member

      I don't know how to make the testing code working.

    10. terryjreedy commented on Jul 11, 2017

      @terryjreedy
      Member

      My manual test procedure was faulty. Without a unit test, I should have asked for another person to verify.

    11. terryjreedy commented on Jul 11, 2017

      @terryjreedy
      Member

      I believe I read somewhere (SO?) that root.withdraw sometimes affects the effectiveness of event_generate. I will try de-iconifying for just this.

    12. terryjreedy commented on Jul 11, 2017

      @terryjreedy
      Member

      New changeset 5b62b35 by terryjreedy in branch 'master':
      bpo-30870: IDLE -- fix logic error in eae2537. (bpo-2660)
      5b62b35

    13. terryjreedy commented on Jul 11, 2017

      @terryjreedy
      Member

      New changeset 953e527 by terryjreedy in branch '3.6':
      [3.6] bpo-30870: IDLE -- fix logic error in eae2537. (GH-2660) (bpo-2661)
      953e527

    14. mlouielu commented on Jul 11, 2017

      mlouielumannequin
      MannequinAuthor

      It just get wierd, I can't do event_generate with Terry, too.

      Attach poc.py that should print out a 'testing', but it didn't.

    15. mlouielu commented on Jul 11, 2017

      mlouielumannequin
      MannequinAuthor

      It seem setUpModule will smash out the test, I've add a trust-will-work test inside the test_configdialog.py:

      class Test(unittest.TestCase):
          def setUp(self):
              self.root = tkinter.Tk()
      
          def test_test(self):
              self.root.bind('<KeyRelease-Up>', lambda x: print('testing'))
              self.root.update()
              self.root.event_generate('<KeyRelease-Up>')

      This will print out testing when commet out setUpModule's root = Tk() line. But if this line is running, then the trust-test won't print out testing

    16. mlouielu commented on Jul 11, 2017

      mlouielumannequin
      MannequinAuthor

      configdialog misuse self.withdraw at init, it should be self.wm_withdraw, bpo-30900 fix this problem. After that, it should be a success to use event_generate in configdialog unittest with no self.withdraw.

    17. terryjreedy commented on Jul 12, 2017

      @terryjreedy
      Member

      The new gui tests passed on Travis (linux), which I strongly suspect does not run gui tests. The generate key test failed on Appveyor (Windows), which means is does run gui tests. It also failed on my machine: generate key release did not work. The generate click test does pass on both Appveyor and my machine, which is progress.

      Adding config.fontlist.focus_force() before the key event worked. Louie, I will push that along with other edits tomorrow. I will try exposing the window just for the tests.

    18. terryjreedy commented on Jul 13, 2017

      @terryjreedy
      Member

      Serhiy: question about tkinter.wantobjects.

      ConfigDialog sets the font options of label font_sample and text text_highlight_sample with a font tuple such as font=('courier', 12, '').

      In the test, I expected retrieval of the font option with
      sample_font = dialog.font_sample['font']
      hilight_font = dialog.text_highlight_sample['font']
      to return tuples, but I get a string: '{courier new} 10 normal'.

      I checked and root.wantobjects() is returning the default True. Should not the options be returned as tuples?

    19. terryjreedy commented on Jul 13, 2017

      @terryjreedy
      Member

      PR2666 adds 4% test coverage. 40% left to go. I expect some tests will cover more lines with less code.

      I am working on a test for set_font_sample.

    20. terryjreedy commented on Jul 14, 2017

      @terryjreedy
      Member

      New changeset 9b622fb by terryjreedy (Louie Lu) in branch 'master':
      bpo-30870: IDLE: Add configdialog fontlist selection unittest (bpo-2666)
      9b622fb

    21. terryjreedy commented on Jul 14, 2017

      @terryjreedy
      Member

      New changeset 42abf7f by terryjreedy in branch '3.6':
      [3.6] bpo-30870: IDLE: Add configdialog fontlist selection unittest (GH-2666) (bpo-2701)
      42abf7f

    22. terryjreedy commented on Jul 21, 2017

      @terryjreedy
      Member

      I am closing this as basically complete. I opened bpo-30981 to add and perhaps complete font page tests.

    23. 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

    3.7 (EOL)topic-IDLEtype-feature

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions