DonationCoder.com forum
 
Read-only archive. This is a static copy of the DonationCoder.com forum. Reading and searching work as before; logging in, posting and private messages do not.
Archive of 2026-10-21 · About this archive · Main site

Author Topic: pywinauto  (Read 5,272 times)

tinjaw

  • I'm so glad breakbeat techno isn't an illegal drug
  • Supporting Member
  • Joined in 2006
  • **
  • Posts: 1,927
    • Participated in NANY Challenge Twice
    • Coding Snacks
    • Military Service Badge - US Army
    • Linux User
pywinauto
« on: April 03, 2007, 06:58 PM »
I have just stumbled upon something so cool, that I have to post it here before I have even downloaded it! :Thmbsup: And of course it's Python related!!  :P

What is it
pywinauto is a set of python modules to automate the Microsoft Windows GUI. At it's simplest it allows you to send mouse and keyboard actions to windows dialogs and controls.

[attachthumb=#1]

It has a syntax that is very pythonic.

How does it work
A lot is done through attribute access (__getattr__) for each class. For example when you get the attribute of an Application or Dialog object it looks for a dialog or control (respectively).

Code
myapp.Notepad # looks for a Window/Dialog of your app that has a title 'similar'
             # to "Notepad"

myapp.PageSetup.OK # looks first for a dialog with a title like "PageSetup"
                  # then it looks for a control on that dialog with a title
                  # like "OK"
This attribute resolution is delayed (currently a hard coded amount of time) until it succeeds. So for example if you Select a menu option and then look for the resulting dialog e.g.

Code
app.Notepad.MenuSelect("File->SaveAs")
app.SaveAs.ComboBox5.Select("UTF-8")
app.SaveAs.edit1.SetText("Example-utf8.txt")
app.SaveAs.Save.Click()

At the 2nd line the SaveAs dialog might not be open by the time this line is executed. So what happens is that we wait until we have a control to resolve before resolving the dialog. At that point if we can't find a SaveAs dialog with a ComboBox5 control then we wait a very short period of time and try again, this is repeated up to a maximum time (currently 1 second!)

This avoid the user having to use time.sleep or a "WaitForDialog" function.

Sit back and have a look at a little movie
Jeff Winkler has created a nice screencast of using pywinauto at ShowMeDo.



Edvard

  • Coding Snacks Author
  • Charter Honorary Member
  • Joined in 2005
  • ***
  • Posts: 3,027
    • Participated in NANY Challenge Once
    • Coding Snacks
    • Linux User
Re: pywinauto
« Reply #1 on: April 19, 2007, 04:35 PM »
Wow, that and Easygui and Python will almost replace Autohotkey! w00t!
All children left unattended will be given a mocha and a puppy.

Original address: https://www.donationcoder.com/forum/index.php?topic=7971.0