In my previous entry, I devised a cheap trick for improving the overall responsiveness of egoClip. I've since noticed the irony of trying to accelerate a program by inserting a delay. I also noticed that it doesn't make for a perfectly live search field, but it's at least wickedly easy to use and beats the typical behavior of always blocking the UI thread until the work's done.
One conspicuous flaw is the requirement of a magic number: the length of the delay. Mainly this means it will fail when your computer's gummy.
I think the deep solution is not to write the program in this style:
Oh, the user wants me to do X, then I'll do that right now and ignore everything until I'm finished.But instead to write it entirely this way:
Oh, the user wants me to do X, then I'll make a note to later do X after I've done all more urgent work and if the user hasn't since asked me to do something that would erase all of X's effects.
So in egoClip, if I want to show a news item when the user double clicks on a headline, I might hook it up using:
headline_list_ctrl.Bind(wx.EVT_LIST_ITEM_ACTIVATED,
lambda e: queue.put(lambda i=e.GetIndex(): show_item(i),
priority='high',
affects=['shown item']))
The priority is high because the user is sitting there waiting for it. The affects list gives the queue the information it needs to remove overridden pending jobs.
This is a complex kind of queue, and it has to be thread-safe. Is there Python code for one of these? If not, I'll soon write it myself. Either way, stay tuned for code.
©2004-2008 Patrick Roberts | Burlington, Ontario, Canada