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/fonts: change font when select by key up/down #75053
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=<Date2017-07-21.02:34:32.545>created_at=<Date2017-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=<Date2017-07-21.02:34:32.544>user='https://github.com/mlouielu'
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.
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
deftest_sample(self):
fontlist=configure.fontlistiffontlist.size():
name0=fontlist.get(0).lower()
# fontlist.selection_set(0) # or somethingprint('\n', changes) # temp to testing that changes changesself.assertEqual(changes['main']['EditorWindow']['font'], name0)
Butselection_setdoesnottriggertheevent. Afterfiddlingaroundwithvariousbindingsevent_generate()sandupdate()sandupdate_idletasks(), Iconcluded, again, thateitherevent_generateoritsdocumentationisbadlybroken. TheonlythingIgottoworkinhoursofexperimentsisthis:
importtkinterastkroot=tk.Tk()
seq='<ButtonRelease-1>'root.bind(seq, lambdaevent: 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.
deftest_sample(self):
fontlist=configure.fontlistiffontlist.size():
name0=fontlist.get(0).lower()
fontlist.see(0)
x, y, dx, dy=fontlist.bbox(0)
fontlist.bind('<ButtonRelease-1>', lambdaevent: print(event))
mouse_click(fontlist, x+dx//2, y+dy//2)
fontlist.update()
print('\n', changes) # temporary, see if changes has anythingself.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.
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?
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 commented on Jul 11, 2017
mlouielumannequin
MannequinAuthor
More actions
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.
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.
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?
Activity
mlouielu commentedon 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.
terryjreedy commentedon Jul 9, 2017
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 commentedon Jul 9, 2017
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 commentedon Jul 9, 2017
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 commentedon Jul 10, 2017
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
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.
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 commentedon Jul 10, 2017
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 commentedon Jul 10, 2017
It isn't my. It was added by Guilherme in r69050.
I'll take a look at code tomorrow.
serhiy-storchaka commentedon Jul 11, 2017
I don't know how to make the testing code working.
terryjreedy commentedon Jul 11, 2017
My manual test procedure was faulty. Without a unit test, I should have asked for another person to verify.
terryjreedy commentedon Jul 11, 2017
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 commentedon Jul 11, 2017
New changeset 5b62b35 by terryjreedy in branch 'master':
bpo-30870: IDLE -- fix logic error in eae2537. (bpo-2660)
5b62b35
terryjreedy commentedon Jul 11, 2017
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 commentedon 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 commentedon Jul 11, 2017
It seem setUpModule will smash out the test, I've add a trust-will-work test inside the test_configdialog.py:
This will print out
testingwhen commet out setUpModule'sroot = Tk()line. But if this line is running, then the trust-test won't print outtestingmlouielu commentedon Jul 11, 2017
configdialog misuse
self.withdrawat init, it should beself.wm_withdraw, bpo-30900 fix this problem. After that, it should be a success to use event_generate in configdialog unittest with noself.withdraw.terryjreedy commentedon Jul 12, 2017
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 commentedon Jul 13, 2017
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 commentedon Jul 13, 2017
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 commentedon Jul 14, 2017
New changeset 9b622fb by terryjreedy (Louie Lu) in branch 'master':
bpo-30870: IDLE: Add configdialog fontlist selection unittest (bpo-2666)
9b622fb
terryjreedy commentedon Jul 14, 2017
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 commentedon Jul 21, 2017
I am closing this as basically complete. I opened bpo-30981 to add and perhaps complete font page tests.