self.onLoadServer(forceReload=True) # new thread: some msgnums changed
def onDeleteProgress(self, i, n, popup):
popup.changeText('%d of %d' % (i, n))
def getMessages(self, msgnums, after):
"""
threaded: prefetch all selected messages into cache now;
used by save, view, reply, and forward to prefill cache;
may overlap with other loadmsgs and sends, disables delete,load;
only runs "after" action if the fetch allowed and successful;
2.1: cache.getMessages tests if index in synch with server,
but we only test if we have to go to server, not if cached;
3.0: see messagecache note: now avoids potential fetch of mail
currently being fetched, if user clicks again while in progress;
any message being fetched by any other request in progress must
disable entire toLoad batch: else, need to wait for N other loads;
fetches are still allowed to overlap in time, as long as disjoint;
"""
if loadingHdrsBusy or deletingBusy:
showerror(appname, 'Cannot fetch message during load or delete')
else:
toLoad = [num for num in msgnums if not self.cache.isLoaded(num)]
if not toLoad:
after() # all already loaded
return # process now, no wait pop up
else:
if set(toLoad) & self.beingFetched: # 3.0: any in progress?
showerror(appname, 'Cannot fetch any message being fetched')
else:
self.beingFetched |= set(toLoad)
loadingMsgsBusy.incr()
from popuputil import BusyBoxNowait
popup = BusyBoxNowait(appname, 'Fetching message contents')
threadtools.startThread(
action = self.cache.getMessages,
args = (toLoad,),
context = (after, popup, toLoad),
onExit = self.onLoadMsgsExit,
onFail = self.onLoadMsgsFail,
onProgress = self.onLoadMsgsProgress)
def onLoadMsgsExit(self, after, popup, toLoad):
self.beingFetched -= set(toLoad)
popup.quit()
after()
loadingMsgsBusy.decr() # allow other actions after onExit done
def onLoadMsgsFail(self, exc_info, after, popup, toLoad):
self.beingFetched -= set(toLoad)
popup.quit()
showerror(appname, 'Fetch failed: \n%s\n%s' % exc_info[:2])
printStack(exc_info)
loadingMsgsBusy.decr()
1084 | Chapter 14: The PyMailGUI Client