deferToThread implemented

git-svn-id: svn://svn.cy55.de/Zope3/src/loops/trunk@2070 fd906abe-77d9-0310-91a1-e0d9ade77398
This commit is contained in:
tschmid 2007-09-26 06:40:32 +00:00
parent 41e98f0bef
commit 52538479d8

View file

@ -9,19 +9,17 @@ Tobias Schmid 26.07.2007
""" """
import win32com.client import win32com.client
import ctypes
import win32api, win32process, win32con
import re import re
from email.mime.multipart import MIMEMultipart from email.mime.multipart import MIMEMultipart
from threading import Thread
# imports for handling the outlook dialog
import ctypes
import win32api, win32process, win32con
from watsup.winGuiAuto import findTopWindow, findControl, findControls, clickButton, \ from watsup.winGuiAuto import findTopWindow, findControl, findControls, clickButton, \
getComboboxItems, selectComboboxItem, setCheckBox getComboboxItems, selectComboboxItem, setCheckBox
from twisted.internet.defer import Deferred from twisted.internet.defer import Deferred
from twisted.internet.task import coiterate from twisted.internet.task import coiterate
from twisted.internet import threads
from zope.interface import implements from zope.interface import implements
from loops.agent.interfaces import IResource from loops.agent.interfaces import IResource
@ -51,9 +49,11 @@ class CrawlingJob(BaseCrawlingJob):
self.deferred = Deferred() self.deferred = Deferred()
return self.deferred return self.deferred
def finished(self, result): def finished(self, result):
self.deferred.callback(self.collected) self.deferred.callback(self.collected)
def crawlOutlook(self): def crawlOutlook(self):
outlookFound = 0 outlookFound = 0
try: try:
@ -84,8 +84,8 @@ class CrawlingJob(BaseCrawlingJob):
print 'MSOutlook.loadInbox() ===> starting' print 'MSOutlook.loadInbox() ===> starting'
# try to handle the Outlook dialog # try to handle the Outlook dialog
handle = HandleOutlookDialog() #d = threads.deferToThread(self.handleOutlookDialog)
handle.start() #d.addCallback(self.printResult)
# catch Inbox folder # catch Inbox folder
onMAPI = oOutlookApp.GetNamespace("MAPI") onMAPI = oOutlookApp.GetNamespace("MAPI")
@ -260,54 +260,10 @@ class CrawlingJob(BaseCrawlingJob):
print '-> dialog found and handled' print '-> dialog found and handled'
break break
def printResult(self):
print '--> Outlook dialog handled'
class HandleOutlookDialog(Thread):
def __init_(self):
Thread.__init__(self)
def run(self):
hwnd = None
while True:
hwnd = ctypes.windll.user32.FindWindowExA(None, hwnd, None, None)
#print 'searching....'
if hwnd == None:
break
else:
val = u"\0" * 1024
ctypes.windll.user32.GetWindowTextW(hwnd, val, len(val))
val = val.replace(u"\000", u"")
if val and repr(val) == "u'Microsoft Office Outlook'":
print repr(val)
print '===> MSOutlook dialog box found'
# get the Main Control
form = findTopWindow(wantedText='Microsoft Office Outlook')
#print 'Control', form
controls = findControls(form)
#print 'Controls', str(controls)
# get the check box
checkBox = findControl(form, wantedText='Zugriff')
#print 'CheckBox', checkBox
setCheckBox(checkBox, 1)
# get the combo box
comboBox = findControl(form, wantedClass='ComboBox')
#print 'ComboBox', comboBox
items = getComboboxItems(comboBox)
#print 'ComboBox-Items', str(items)
selectComboboxItem(comboBox, items[1])#'10 Minuten'
# finally get the button and click it
button = findControl(form, wantedText = 'Erteilen')
print 'Erteilen Button', button
clickButton(button)
print '-> dialog found and handled'
break
class OutlookResource(object): class OutlookResource(object):
implements(IResource) implements(IResource)