SlideShare uma empresa Scribd logo
1 de 36
Baixar para ler offline
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
Automatisierung von Windows-Anwendungen Um was geht es? ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],Modul  win32com Module  win32/*
COM Component Object Model   ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
COM COM-Interface ,[object Object],[object Object],// Standardschnittstelle aller COM-Komponenten  [  object,  uuid(00000000-0000-0000-C000-000000000046)  ]  interface IUnknown {  [restricted]  HRESULT _stdcall QueryInterface([in] GUID* rrid, [out] void** ppvObj);  [restricted]  unsigned long _stdcall AddRef();  [restricted]  unsigned long _stdcall Release();  }
COM Automatisierung und Clients ,[object Object],[object Object],[object Object],[object Object],[object Object],Client Component Client Component COM Client Process Server Process
Pywin32 Python for Windows extensions ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
„ Hello World“ Microsoft Word from  win32com  import  client word = client.Dispatch( &quot;Word.Application&quot; ) word.Visible =  1   doc = word.Documents.Add()  doc.Content.Text =  &quot;Hello World&quot;
Automatisierung von Applikationen ,[object Object],[object Object]
Ermittlung der ProgID ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],from  win32com.client  import  Dispatch  excel = Dispatch( „Excel.Application&quot; )
Beispiele für ProgIDs ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
Methoden der Applikation ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
Generierung eines Python-Moduls mit makepy ,[object Object],[object Object]
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
Browsen der Schnittstellen mit combrowse
Browsen der Schnittstellen mit combrowse PowerPoint
Browsen der Schnittstellen mit combrowse Slides Add Slide Parameter
Alternativer Browser Type Library Browser tlbrowse.py
Beispiel from  win32com  import  client ppt = client.Dispatch( „Powerpoint.Application&quot; ) ppt.Visible =  1   ppt.ActivePresentation.Slides.Add( 1 , 1 ) Index Layout
Debugging
Debugging Python Trace Collector ,[object Object]
Grundlegende Automatisierungen ,[object Object],[object Object],[object Object]
Events ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
Events Event-Handler definieren ,[object Object],[object Object],class  EventManager(object): def  OnSheetBeforeDoubleClick(self, sheet, target, cancel): print  „Do   something“ # something pass class  EventManager(object): def OnSlideShowNextSlide(self, Wn): print  „Do   something“ # something pass
Events Welche Events gibt es? – Beispiel Excel ,[object Object],OnGetTypeInfo OnWorkbookAddinInstall OnSheetBeforeRightClick OnSheetFollowHyperlink OnWorkbookBeforePrint OnWorkbookBeforeXmlExport OnWorkbookDeactivate  OnSheetSelectionChange OnInvoke OnSheetActivate OnWorkbookAddinUninstall OnAddRef OnQueryInterface OnWorkbookSync OnSheetChange OnGetTypeInfoCount OnWorkbookBeforeSave OnWorkbookAfterXmlExport OnWorkbookPivotTableCloseConnection OnSheetCalculate OnWorkbookPivotTableOpenConnection OnSheetBeforeDoubleClick OnSheetDeactivate OnWindowDeactivate OnRelease OnWindowResize OnSheetPivotTableUpdate OnWorkbookOpen OnWorkbookBeforeXmlImport OnWindowActivate OnNewWorkbook OnWorkbookNewSheet OnWorkbookAfterXmlImport OnWorkbookBeforeClose OnGetIDsOfNames
Events Welche Events gibt es? – Beispiel PowerPoint ,[object Object],OnPresentationBeforeSave OnColorSchemeChanged OnSlideShowNextSlide OnSlideShowNextClick OnPresentationOpen OnPresentationSave OnWindowBeforeRightClick OnSlideShowBegin OnWindowBeforeDoubleClick OnWindowSelectionChange OnNewPresentation OnWindowDeactivate OnPresentationClose OnAfterPresentationOpen OnAfterNewPresentation OnSlideShowNextBuild OnPresentationNewSlide OnPresentationSync OnSlideSelectionChanged OnWindowActivate OnSlideShowEnd OnPresentationPrint
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
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
Add-Ins ,[object Object],[object Object],[object Object],[object Object],[object Object],import  pywintypes clsid = pywintypes.CreateGuid()
Add-Ins Klasse Addin class  Addin(object): _com_interfaces_ = [ '_IDTExtensibility2' ] _public_methods_ = [] _reg_clsctx_ = pythoncom.CLSCTX_INPROC_SERVER _reg_clsid_ =  '{2F1E606F-2A7B-46F9-AF6A-267C0036C348}' _reg_progid_ =  'Python.Test.Addin' _reg_policy_spec_ =  'win32com.server.policy.EventHandlerPolicy' def  __init__( self ):  import  win32traceutil;  self .application =  None def  OnConnection( self , application, connectMode, addin, custom): print  'OnConnection' , application, connectMode, addin, custom def  OnDisconnection( self , mode, custom): print  'OnDisconnection ' ‚ mode, custom def  OnAddInsUpdate( self , custom): print  'OnAddInsUpdate' , custom def  OnStartupComplete( self , custom): print  'OnStartupComplete' , custom def  OnBeginShutdown( self , custom): print  'OnBeginShutdown' , custom
Demos
Demo Twitter in PowerPoint ,[object Object],[object Object],python-twitter
Twitter in PowerPoint Implementation using Python’s win32com (1)  ,[object Object],import  twitter api = twitter.Api(username= 'python_demo' , password= '*' ) class  EventManager(object): 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)
Twitter in PowerPoint Implementation using Python’s win32com (2)  ,[object Object],from  win32com.client  import  DispatchWithEvents powerpoint = DispatchWithEvents( 'PowerPoint.Application' , EventManager) powerpoint.Visible = 1 # Listen for events import  threading, pythoncom stopEvent = 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
Quellen und Literatur
Quellen ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
Literatur Python Programming on Win32 ,[object Object]

Mais conteúdo relacionado

Semelhante a Automatisierung von Windows-Anwendungen

Ionic 2 - Hybridapps auf Steroiden
Ionic 2 - Hybridapps auf SteroidenIonic 2 - Hybridapps auf Steroiden
Ionic 2 - Hybridapps auf SteroidenHendrik Lösch
 
Python in der Luft- und Raumfahrt
Python in der Luft- und RaumfahrtPython in der Luft- und Raumfahrt
Python in der Luft- und RaumfahrtAndreas Schreiber
 
BASTA! 2017 Jubiläumskonferenz - Warum warten auf die IDE!?
BASTA! 2017 Jubiläumskonferenz - Warum warten auf die IDE!?BASTA! 2017 Jubiläumskonferenz - Warum warten auf die IDE!?
BASTA! 2017 Jubiläumskonferenz - Warum warten auf die IDE!?Robin Sedlaczek
 
B1 Acocon Lotus Day 08.09.2009
B1 Acocon Lotus Day 08.09.2009B1 Acocon Lotus Day 08.09.2009
B1 Acocon Lotus Day 08.09.2009Andreas Schulte
 
Abläufe mit PHP und Phing automatisieren
Abläufe mit PHP und Phing automatisierenAbläufe mit PHP und Phing automatisieren
Abläufe mit PHP und Phing automatisierenChristian Münch
 
ScriptRunner - Eine Einführung
ScriptRunner - Eine EinführungScriptRunner - Eine Einführung
ScriptRunner - Eine EinführungHeiko Brenn
 
Von Typo3 zu Plone - Ein Migrationsbericht
Von Typo3 zu Plone - Ein MigrationsberichtVon Typo3 zu Plone - Ein Migrationsbericht
Von Typo3 zu Plone - Ein MigrationsberichtAndreas Schiweck
 
Open Source BPM - iteratec Architekturtag
Open Source BPM - iteratec ArchitekturtagOpen Source BPM - iteratec Architekturtag
Open Source BPM - iteratec Architekturtagcamunda services GmbH
 
YAFOWIL - Webformulare in Python ohne Kopfschmerzen
YAFOWIL - Webformulare in Python ohne KopfschmerzenYAFOWIL - Webformulare in Python ohne Kopfschmerzen
YAFOWIL - Webformulare in Python ohne KopfschmerzenJens Klein
 
PAVONE Espresso Workflow für Java EE
PAVONE Espresso Workflow für Java EEPAVONE Espresso Workflow für Java EE
PAVONE Espresso Workflow für Java EEUdo Sill
 
ADC Core 2017 - Warum warten auf die IDE?
ADC Core 2017 - Warum warten auf die IDE?ADC Core 2017 - Warum warten auf die IDE?
ADC Core 2017 - Warum warten auf die IDE?Robin Sedlaczek
 
C/ C++ for Notes & Domino Developers
C/ C++ for Notes & Domino DevelopersC/ C++ for Notes & Domino Developers
C/ C++ for Notes & Domino DevelopersUlrich Krause
 
Kuck mal, Node.js! Einstieg für .NET Entwickler mit Visual Studio Code und Ty...
Kuck mal, Node.js! Einstieg für .NET Entwickler mit Visual Studio Code und Ty...Kuck mal, Node.js! Einstieg für .NET Entwickler mit Visual Studio Code und Ty...
Kuck mal, Node.js! Einstieg für .NET Entwickler mit Visual Studio Code und Ty...Gregor Biswanger
 
ICIS User Group - Oberflächentests mittels LCT deklarativ angehen
ICIS User Group - Oberflächentests mittels LCT deklarativ angehenICIS User Group - Oberflächentests mittels LCT deklarativ angehen
ICIS User Group - Oberflächentests mittels LCT deklarativ angehenKai Donato
 
Wie kommt die Milch eigentlich in die Buchhaltung? Reisekostenabrechnung am S...
Wie kommt die Milch eigentlich in die Buchhaltung? Reisekostenabrechnung am S...Wie kommt die Milch eigentlich in die Buchhaltung? Reisekostenabrechnung am S...
Wie kommt die Milch eigentlich in die Buchhaltung? Reisekostenabrechnung am S...Christian Kiesewetter
 
Einstieg in Xamarin und Xamarin.Forms, DDC 2018
Einstieg in Xamarin und Xamarin.Forms, DDC 2018Einstieg in Xamarin und Xamarin.Forms, DDC 2018
Einstieg in Xamarin und Xamarin.Forms, DDC 2018André Krämer
 
Open icf (open identity connector framework) @ forgerock deutsch
Open icf (open identity connector framework) @ forgerock   deutschOpen icf (open identity connector framework) @ forgerock   deutsch
Open icf (open identity connector framework) @ forgerock deutschHanns Nolan
 

Semelhante a Automatisierung von Windows-Anwendungen (20)

Was ist neu in .NET 4.5?
Was ist neu in .NET 4.5?Was ist neu in .NET 4.5?
Was ist neu in .NET 4.5?
 
Ionic 2 - Hybridapps auf Steroiden
Ionic 2 - Hybridapps auf SteroidenIonic 2 - Hybridapps auf Steroiden
Ionic 2 - Hybridapps auf Steroiden
 
Python in der Luft- und Raumfahrt
Python in der Luft- und RaumfahrtPython in der Luft- und Raumfahrt
Python in der Luft- und Raumfahrt
 
BASTA! 2017 Jubiläumskonferenz - Warum warten auf die IDE!?
BASTA! 2017 Jubiläumskonferenz - Warum warten auf die IDE!?BASTA! 2017 Jubiläumskonferenz - Warum warten auf die IDE!?
BASTA! 2017 Jubiläumskonferenz - Warum warten auf die IDE!?
 
B1 Acocon Lotus Day 08.09.2009
B1 Acocon Lotus Day 08.09.2009B1 Acocon Lotus Day 08.09.2009
B1 Acocon Lotus Day 08.09.2009
 
Ionic 3
Ionic 3Ionic 3
Ionic 3
 
Abläufe mit PHP und Phing automatisieren
Abläufe mit PHP und Phing automatisierenAbläufe mit PHP und Phing automatisieren
Abläufe mit PHP und Phing automatisieren
 
ScriptRunner - Eine Einführung
ScriptRunner - Eine EinführungScriptRunner - Eine Einführung
ScriptRunner - Eine Einführung
 
Von Typo3 zu Plone - Ein Migrationsbericht
Von Typo3 zu Plone - Ein MigrationsberichtVon Typo3 zu Plone - Ein Migrationsbericht
Von Typo3 zu Plone - Ein Migrationsbericht
 
SignalR
SignalRSignalR
SignalR
 
Open Source BPM - iteratec Architekturtag
Open Source BPM - iteratec ArchitekturtagOpen Source BPM - iteratec Architekturtag
Open Source BPM - iteratec Architekturtag
 
YAFOWIL - Webformulare in Python ohne Kopfschmerzen
YAFOWIL - Webformulare in Python ohne KopfschmerzenYAFOWIL - Webformulare in Python ohne Kopfschmerzen
YAFOWIL - Webformulare in Python ohne Kopfschmerzen
 
PAVONE Espresso Workflow für Java EE
PAVONE Espresso Workflow für Java EEPAVONE Espresso Workflow für Java EE
PAVONE Espresso Workflow für Java EE
 
ADC Core 2017 - Warum warten auf die IDE?
ADC Core 2017 - Warum warten auf die IDE?ADC Core 2017 - Warum warten auf die IDE?
ADC Core 2017 - Warum warten auf die IDE?
 
C/ C++ for Notes & Domino Developers
C/ C++ for Notes & Domino DevelopersC/ C++ for Notes & Domino Developers
C/ C++ for Notes & Domino Developers
 
Kuck mal, Node.js! Einstieg für .NET Entwickler mit Visual Studio Code und Ty...
Kuck mal, Node.js! Einstieg für .NET Entwickler mit Visual Studio Code und Ty...Kuck mal, Node.js! Einstieg für .NET Entwickler mit Visual Studio Code und Ty...
Kuck mal, Node.js! Einstieg für .NET Entwickler mit Visual Studio Code und Ty...
 
ICIS User Group - Oberflächentests mittels LCT deklarativ angehen
ICIS User Group - Oberflächentests mittels LCT deklarativ angehenICIS User Group - Oberflächentests mittels LCT deklarativ angehen
ICIS User Group - Oberflächentests mittels LCT deklarativ angehen
 
Wie kommt die Milch eigentlich in die Buchhaltung? Reisekostenabrechnung am S...
Wie kommt die Milch eigentlich in die Buchhaltung? Reisekostenabrechnung am S...Wie kommt die Milch eigentlich in die Buchhaltung? Reisekostenabrechnung am S...
Wie kommt die Milch eigentlich in die Buchhaltung? Reisekostenabrechnung am S...
 
Einstieg in Xamarin und Xamarin.Forms, DDC 2018
Einstieg in Xamarin und Xamarin.Forms, DDC 2018Einstieg in Xamarin und Xamarin.Forms, DDC 2018
Einstieg in Xamarin und Xamarin.Forms, DDC 2018
 
Open icf (open identity connector framework) @ forgerock deutsch
Open icf (open identity connector framework) @ forgerock   deutschOpen icf (open identity connector framework) @ forgerock   deutsch
Open icf (open identity connector framework) @ forgerock deutsch
 

Mais de Andreas Schreiber

Provenance-based Security Audits and its Application to COVID-19 Contact Trac...
Provenance-based Security Audits and its Application to COVID-19 Contact Trac...Provenance-based Security Audits and its Application to COVID-19 Contact Trac...
Provenance-based Security Audits and its Application to COVID-19 Contact Trac...Andreas Schreiber
 
Visualization of Software Architectures in Virtual Reality and Augmented Reality
Visualization of Software Architectures in Virtual Reality and Augmented RealityVisualization of Software Architectures in Virtual Reality and Augmented Reality
Visualization of Software Architectures in Virtual Reality and Augmented RealityAndreas Schreiber
 
Provenance as a building block for an open science infrastructure
Provenance as a building block for an open science infrastructureProvenance as a building block for an open science infrastructure
Provenance as a building block for an open science infrastructureAndreas Schreiber
 
Raising Awareness about Open Source Licensing at the German Aerospace Center
Raising Awareness about Open Source Licensing at the German Aerospace CenterRaising Awareness about Open Source Licensing at the German Aerospace Center
Raising Awareness about Open Source Licensing at the German Aerospace CenterAndreas Schreiber
 
Open Source Licensing for Rocket Scientists
Open Source Licensing for Rocket ScientistsOpen Source Licensing for Rocket Scientists
Open Source Licensing for Rocket ScientistsAndreas Schreiber
 
Interactive Visualization of Software Components with Virtual Reality Headsets
Interactive Visualization of Software Components with Virtual Reality HeadsetsInteractive Visualization of Software Components with Virtual Reality Headsets
Interactive Visualization of Software Components with Virtual Reality HeadsetsAndreas Schreiber
 
Provenance for Reproducible Data Science
Provenance for Reproducible Data ScienceProvenance for Reproducible Data Science
Provenance for Reproducible Data ScienceAndreas Schreiber
 
Visualizing Provenance using Comics
Visualizing Provenance using ComicsVisualizing Provenance using Comics
Visualizing Provenance using ComicsAndreas Schreiber
 
Nachvollziehbarkeit mit Hinblick auf Privacy-Verletzungen
Nachvollziehbarkeit mit Hinblick auf Privacy-VerletzungenNachvollziehbarkeit mit Hinblick auf Privacy-Verletzungen
Nachvollziehbarkeit mit Hinblick auf Privacy-VerletzungenAndreas Schreiber
 
Reproducible Science with Python
Reproducible Science with PythonReproducible Science with Python
Reproducible Science with PythonAndreas Schreiber
 
A Provenance Model for Quantified Self Data
A Provenance Model for Quantified Self DataA Provenance Model for Quantified Self Data
A Provenance Model for Quantified Self DataAndreas Schreiber
 
Tracking after Stroke: Doctors, Dogs and All The Rest
Tracking after Stroke: Doctors, Dogs and All The RestTracking after Stroke: Doctors, Dogs and All The Rest
Tracking after Stroke: Doctors, Dogs and All The RestAndreas Schreiber
 
High Throughput Processing of Space Debris Data
High Throughput Processing of Space Debris DataHigh Throughput Processing of Space Debris Data
High Throughput Processing of Space Debris DataAndreas Schreiber
 
Bericht von der QS15 Conference & Exposition
Bericht von der QS15 Conference & ExpositionBericht von der QS15 Conference & Exposition
Bericht von der QS15 Conference & ExpositionAndreas Schreiber
 
Telemedizin: Gesundheit, messbar für jedermann
Telemedizin: Gesundheit, messbar für jedermannTelemedizin: Gesundheit, messbar für jedermann
Telemedizin: Gesundheit, messbar für jedermannAndreas Schreiber
 
Quantified Self mit Wearable Devices und Smartphone-Sensoren
Quantified Self mit Wearable Devices und Smartphone-SensorenQuantified Self mit Wearable Devices und Smartphone-Sensoren
Quantified Self mit Wearable Devices und Smartphone-SensorenAndreas Schreiber
 

Mais de Andreas Schreiber (20)

Provenance-based Security Audits and its Application to COVID-19 Contact Trac...
Provenance-based Security Audits and its Application to COVID-19 Contact Trac...Provenance-based Security Audits and its Application to COVID-19 Contact Trac...
Provenance-based Security Audits and its Application to COVID-19 Contact Trac...
 
Visualization of Software Architectures in Virtual Reality and Augmented Reality
Visualization of Software Architectures in Virtual Reality and Augmented RealityVisualization of Software Architectures in Virtual Reality and Augmented Reality
Visualization of Software Architectures in Virtual Reality and Augmented Reality
 
Provenance as a building block for an open science infrastructure
Provenance as a building block for an open science infrastructureProvenance as a building block for an open science infrastructure
Provenance as a building block for an open science infrastructure
 
Raising Awareness about Open Source Licensing at the German Aerospace Center
Raising Awareness about Open Source Licensing at the German Aerospace CenterRaising Awareness about Open Source Licensing at the German Aerospace Center
Raising Awareness about Open Source Licensing at the German Aerospace Center
 
Open Source Licensing for Rocket Scientists
Open Source Licensing for Rocket ScientistsOpen Source Licensing for Rocket Scientists
Open Source Licensing for Rocket Scientists
 
Interactive Visualization of Software Components with Virtual Reality Headsets
Interactive Visualization of Software Components with Virtual Reality HeadsetsInteractive Visualization of Software Components with Virtual Reality Headsets
Interactive Visualization of Software Components with Virtual Reality Headsets
 
Provenance for Reproducible Data Science
Provenance for Reproducible Data ScienceProvenance for Reproducible Data Science
Provenance for Reproducible Data Science
 
Visualizing Provenance using Comics
Visualizing Provenance using ComicsVisualizing Provenance using Comics
Visualizing Provenance using Comics
 
Quantified Self Comics
Quantified Self ComicsQuantified Self Comics
Quantified Self Comics
 
Nachvollziehbarkeit mit Hinblick auf Privacy-Verletzungen
Nachvollziehbarkeit mit Hinblick auf Privacy-VerletzungenNachvollziehbarkeit mit Hinblick auf Privacy-Verletzungen
Nachvollziehbarkeit mit Hinblick auf Privacy-Verletzungen
 
Reproducible Science with Python
Reproducible Science with PythonReproducible Science with Python
Reproducible Science with Python
 
Python at Warp Speed
Python at Warp SpeedPython at Warp Speed
Python at Warp Speed
 
A Provenance Model for Quantified Self Data
A Provenance Model for Quantified Self DataA Provenance Model for Quantified Self Data
A Provenance Model for Quantified Self Data
 
Open Source im DLR
Open Source im DLROpen Source im DLR
Open Source im DLR
 
Tracking after Stroke: Doctors, Dogs and All The Rest
Tracking after Stroke: Doctors, Dogs and All The RestTracking after Stroke: Doctors, Dogs and All The Rest
Tracking after Stroke: Doctors, Dogs and All The Rest
 
High Throughput Processing of Space Debris Data
High Throughput Processing of Space Debris DataHigh Throughput Processing of Space Debris Data
High Throughput Processing of Space Debris Data
 
Bericht von der QS15 Conference & Exposition
Bericht von der QS15 Conference & ExpositionBericht von der QS15 Conference & Exposition
Bericht von der QS15 Conference & Exposition
 
Telemedizin: Gesundheit, messbar für jedermann
Telemedizin: Gesundheit, messbar für jedermannTelemedizin: Gesundheit, messbar für jedermann
Telemedizin: Gesundheit, messbar für jedermann
 
Big Python
Big PythonBig Python
Big Python
 
Quantified Self mit Wearable Devices und Smartphone-Sensoren
Quantified Self mit Wearable Devices und Smartphone-SensorenQuantified Self mit Wearable Devices und Smartphone-Sensoren
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( &quot;Word.Application&quot; ) word.Visible = 1 doc = word.Documents.Add() doc.Content.Text = &quot;Hello World&quot;
  • 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
  • 14. Browsen der Schnittstellen mit combrowse
  • 15. Browsen der Schnittstellen mit combrowse PowerPoint
  • 16. Browsen der Schnittstellen mit combrowse Slides Add Slide Parameter
  • 17. Alternativer Browser Type Library Browser tlbrowse.py
  • 18. Beispiel from win32com import client ppt = client.Dispatch( „Powerpoint.Application&quot; ) ppt.Visible = 1 ppt.ActivePresentation.Slides.Add( 1 , 1 ) Index Layout
  • 20.
  • 21.
  • 22.
  • 23.
  • 24.
  • 25.
  • 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
  • 28.
  • 29. Add-Ins Klasse Addin class Addin(object): _com_interfaces_ = [ '_IDTExtensibility2' ] _public_methods_ = [] _reg_clsctx_ = pythoncom.CLSCTX_INPROC_SERVER _reg_clsid_ = '{2F1E606F-2A7B-46F9-AF6A-267C0036C348}' _reg_progid_ = 'Python.Test.Addin' _reg_policy_spec_ = 'win32com.server.policy.EventHandlerPolicy' def __init__( self ): import win32traceutil; self .application = None def OnConnection( self , application, connectMode, addin, custom): print 'OnConnection' , application, connectMode, addin, custom def OnDisconnection( self , mode, custom): print 'OnDisconnection ' ‚ mode, custom def OnAddInsUpdate( self , custom): print 'OnAddInsUpdate' , custom def OnStartupComplete( self , custom): print 'OnStartupComplete' , custom def OnBeginShutdown( self , custom): print 'OnBeginShutdown' , custom
  • 30. Demos
  • 31.
  • 32.
  • 33.
  • 35.
  • 36.

Notas do Editor

  1. @pycologne Vortrag Automatisierung von Windows-Anwendungen
  2. Demo: Slide change notification from Microsoft PowerPoint. If you read this message, the demo is successful!
  3. In Python, its very easy to catch the slide change event. Full source code on http://pastebin.ca/1478907
  4. For details see Roy Hans #pycon tutorial Automating Windows Applications with win32com http://tr.im/q43o
  5. Good tutorial for Automating Windows Applications with win32com by Roy Han: http://tr.im/q43o
  6. Book: Python Programming on Win32 http://tr.im/vZlM