Quantified Self mit Wearable Devices und Smartphone-Sensoren
Automatisierung von Windows-Anwendungen
1. Automatisierung von Windows-Anwendungen Python for Windows PyCologne (12.08.2009, Köln) Andreas Schreiber <Andreas.Schreiber@dlr.de> http://andreas-schreiber.net | http://www.pycologne.de
2.
3.
4.
5.
6.
7. „ Hello World“ Microsoft Word from win32com import client word = client.Dispatch( "Word.Application" ) word.Visible = 1 doc = word.Documents.Add() doc.Content.Text = "Hello World"
8.
9.
10.
11.
12.
13. Generierung eines Python-Moduls mit makepy Beispiel-Ausschnitt: PowerPoint Slides Add class Slides(DispatchBaseClass): CLSID = IID( '{91493469-5A91-11CF-8700-00AA0060263B}' ) coclass_clsid = None # Result is of type Slide def Add(self, Index=defaultNamedNotOptArg, Layout=defaultNamedNotOptArg): ret = self._oleobj_.InvokeTypes(2004, LCID, 1 , ( 13 , 0 ), (( 3 , 1 ), ( 3 , 1 )),Index , Layout) if ret is not None : # See if this IUnknown is really an IDispatch try : ret = ret.QueryInterface(pythoncom.IID_IDispatch) except pythoncom.error: return ret ret = Dispatch(ret, 'Add' , '{91493445-5A91-11CF-8700-00AA0060263B}' , UnicodeToString=0) return ret
26. Events Applikation mit Event-Handler anfordern („Dispatch“) # Dispatch Excel with event handler from win32com.client import DispatchWithEvents excel = DispatchWithEvents( 'Excel.Application' , EventManager) excel.Visible = 1
27. Events Event-Schleife: Auf Events warten # Listen for events import threading, pythoncom stopEvent = threading.Event() while True : pythoncom.PumpWaitingMessages() # Necessary so that python doesn't hog CPU stopEvent.wait( .2 ) if stopEvent.isSet(): stopEvent.clear() break