Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
mlouielu mannequin opened this issue Jul 7, 2017 · 21 comments
Closed

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

mlouielu mannequin opened this issue Jul 7, 2017 · 21 comments
Assignees
Labels
3.7 (EOL) end of life topic-IDLE type-feature A feature request or enhancement

Comments

@mlouielu
Copy link
Mannequin

mlouielu mannequin commented Jul 7, 2017

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']

    @mlouielu
    Copy link
    Mannequin Author

    mlouielu mannequin commented Jul 7, 2017

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

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

    @mlouielu mlouielu mannequin added the 3.7 (EOL) end of life label Jul 7, 2017
    @mlouielu mlouielu mannequin assigned terryjreedy Jul 7, 2017
    @mlouielu mlouielu mannequin added the topic-IDLE label Jul 7, 2017
    @terryjreedy terryjreedy added the type-feature A feature request or enhancement label Jul 8, 2017
    @terryjreedy
    Copy link
    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

    @terryjreedy
    Copy link
    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.

    @terryjreedy
    Copy link
    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

    @terryjreedy
    Copy link
    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.

    @terryjreedy
    Copy link
    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?

    @serhiy-storchaka
    Copy link
    Member

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

    I'll take a look at code tomorrow.

    @serhiy-storchaka
    Copy link
    Member

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

    @terryjreedy
    Copy link
    Member

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

    @terryjreedy
    Copy link
    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.

    @terryjreedy
    Copy link
    Member

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

    @terryjreedy
    Copy link
    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

    @mlouielu
    Copy link
    Mannequin Author

    mlouielu mannequin commented Jul 11, 2017

    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.

    @mlouielu
    Copy link
    Mannequin Author

    mlouielu mannequin commented Jul 11, 2017

    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

    @mlouielu
    Copy link
    Mannequin Author

    mlouielu mannequin commented Jul 11, 2017

    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.

    @terryjreedy
    Copy link
    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.

    @terryjreedy
    Copy link
    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?

    @terryjreedy
    Copy link
    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.

    @terryjreedy
    Copy link
    Member

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

    @terryjreedy
    Copy link
    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

    @terryjreedy
    Copy link
    Member

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

    @ezio-melotti ezio-melotti transferred this issue from another repository Apr 10, 2022
    Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
    Labels
    3.7 (EOL) end of life topic-IDLE type-feature A feature request or enhancement
    Projects
    None yet
    Development

    No branches or pull requests

    2 participants