Folie 1 Vortrag > Andreas Schreiber> Automatisierung von Windows-Anwendungen mit Python > Datum Automatisierung von Windows-Anwendungen Python for Windows PyCologne (12.08.2009, Köln) Andreas Schreiber <[email protected]> http://andreas-schreiber.net | http://www.pycologne.de
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Transcript
Folie 1Vortrag > Andreas Schreiber> Automatisierung von Windows-Anwendungen mit Python > Datum
Folie 12Vortrag > Andreas Schreiber> Automatisierung von Windows-Anwendungen mit Python > Datum
Generierung eines Python-Moduls mit makepy
Beispiel PowerPoint
91493440-5A91-11CF-8700-00AA0060263Bx0x2x8.py
Folie 13Vortrag > Andreas Schreiber> Automatisierung von Windows-Anwendungen mit Python > Datum
Generierung eines Python-Moduls mit makepyBeispiel-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
Folie 14Vortrag > Andreas Schreiber> Automatisierung von Windows-Anwendungen mit Python > Datum
Browsen der Schnittstellen mit combrowse
Folie 15Vortrag > Andreas Schreiber> Automatisierung von Windows-Anwendungen mit Python > Datum
Browsen der Schnittstellen mit combrowse
PowerPoint
Folie 16Vortrag > Andreas Schreiber> Automatisierung von Windows-Anwendungen mit Python > Datum
Browsen der Schnittstellen mit combrowse
Slides
Add Slide
Parameter
Folie 17Vortrag > Andreas Schreiber> Automatisierung von Windows-Anwendungen mit Python > Datum
Folie 27Vortrag > Andreas Schreiber> Automatisierung von Windows-Anwendungen mit Python > Datum
EventsEvent-Schleife: Auf Events warten
# Listen for eventsimport threading, pythoncomstopEvent = threading.Event()while True: pythoncom.PumpWaitingMessages() # Necessary so that python doesn't hog CPU stopEvent.wait(.2) if stopEvent.isSet(): stopEvent.clear() break
Folie 28Vortrag > Andreas Schreiber> Automatisierung von Windows-Anwendungen mit Python > Datum
Add-Ins
Erstellen von Add-Ins
Ermitteln einer CLSID für das Add-In
Cut & Paste der Add-In Klassendefinition
Überschreiben von Methoden der Add-In Klasse
Registrieren des Add-Ins
import pywintypesclsid = pywintypes.CreateGuid()
Folie 29Vortrag > Andreas Schreiber> Automatisierung von Windows-Anwendungen mit Python > Datum
def OnSlideShowNextSlide(self, Wn): i = powerpoint.ActivePresentation. SlideShowWindow.View.Slide.SlideIndex for shape in powerpoint.ActivePresentation. Slides[i-1].NotesPage.Shapes: if shape.TextFrame.HasText: notes = shape.TextFrame.TextRange.Text api.PostUpdate(notes)
Folie 33Vortrag > Andreas Schreiber> Automatisierung von Windows-Anwendungen mit Python > Datum
Twitter in PowerPointImplementation using Python’s win32com (2)
Dispatch PowerPoint with event handler and listen for events
from win32com.client import DispatchWithEventspowerpoint = DispatchWithEvents('PowerPoint.Application', EventManager)powerpoint.Visible = 1
# Listen for eventsimport threading, pythoncomstopEvent = threading.Event()while True: pythoncom.PumpWaitingMessages() stopEvent.wait(.2) if stopEvent.isSet(): stopEvent.clear() break
Source: Roy Han’s PyCon 2008 tutorial “Automating Windows Applications with win32com” http://tr.im/q43o
Folie 34Vortrag > Andreas Schreiber> Automatisierung von Windows-Anwendungen mit Python > Datum
Quellen und Literatur
Folie 35Vortrag > Andreas Schreiber> Automatisierung von Windows-Anwendungen mit Python > Datum
Quellen
Tutorial Automating Windows Applications with win32com