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
Comments
Add event for KeyRelease-Up and KeyRelease-Down to change sample font. Current code only changed font when using button-click on listbox. |
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 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. |
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? |
It isn't my. It was added by Guilherme in r69050. I'll take a look at code tomorrow. |
I don't know how to make the testing code working. |
My manual test procedure was faulty. Without a unit test, I should have asked for another person to verify. |
I believe I read somewhere (SO?) that root.withdraw sometimes affects the effectiveness of event_generate. I will try de-iconifying for just this. |
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. |
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 |
configdialog misuse |
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. |
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 I checked and root.wantobjects() is returning the default True. Should not the options be returned as tuples? |
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. |
I am closing this as basically complete. I opened bpo-30981 to add and perhaps complete font page tests. |
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:
bugs.python.org fields:
The text was updated successfully, but these errors were encountered: