homepage

This issue tracker has been migrated to GitHub , and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Author terry.reedy
Recipients louielu, terry.reedy
Date 2017年07月10日.01:53:55
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1499651636.37.0.600562781358.issue30870@psf.upfronthosting.co.za>
In-reply-to
Content
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.
History
Date User Action Args
2017年07月10日 01:53:56terry.reedysetrecipients: + terry.reedy, louielu
2017年07月10日 01:53:56terry.reedysetmessageid: <1499651636.37.0.600562781358.issue30870@psf.upfronthosting.co.za>
2017年07月10日 01:53:56terry.reedylinkissue30870 messages
2017年07月10日 01:53:55terry.reedycreate

AltStyle によって変換されたページ (->オリジナル) /