Skip to content

Commit

Permalink
Merge pull request pywinauto#320 from vasily-v-ryabov/UIA
Browse files Browse the repository at this point in the history
Add MS Paint example (fix pywinauto#310).
  • Loading branch information
vasily-v-ryabov authored Feb 28, 2017
2 parents 86070c6 + 77eb463 commit 24cde23
Show file tree
Hide file tree
Showing 6 changed files with 105 additions and 5 deletions.
16 changes: 16 additions & 0 deletions docs/HISTORY.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,22 @@
Change Log
==========

0.6.2 More bug fixes
--------------------------------------------------------------------
28-February-2017
* Several bugs were fixed:

- Maximized window is always resized (restored) when calling ``set_focus()``.
- AttributeError: type object '_CustomLogger' has no attribute 'disable'.
- ``print_control_identifiers()`` gets bytes string on Python 3.x.
- Importing pywinauto causes debug messages to appear twice.

* Improved click methods behaviour for Win32 ListView and TreeView:
``ensure_visible()`` is called inside before the click.

* Made ``taskbar.SystemTrayIcons`` localization friendly.


0.6.1 Bug fixes and optimizations for UI Automation and beyond
--------------------------------------------------------------------
08-February-2017
Expand Down
40 changes: 40 additions & 0 deletions examples/list_windows_updates.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
"""
Example script for listing installed updates on Windows 10
Requirements:
- Windows 10 (may work on Win7+)
- pywinauto 0.6.1+
This example opens "Control Panel", navigates to "Installed Updates" page
and lists all updates (for all apps) as well as OS Windows updates only.
"""

from __future__ import print_function
from pywinauto import Application

# Open "Control Panel"
Application().start('control.exe')
app = Application(backend='uia').connect(path='explorer.exe', title='Control Panel')

# Go to "Programs"
app.window(title='Control Panel').ProgramsHyperlink.invoke()
app.wait_cpu_usage_lower(threshold=0.5, timeout=30, usage_interval=1.0)

# Go to "Installed Updates"
app.window(title='Programs').child_window(title='View installed updates', control_type='Hyperlink').invoke()
app.wait_cpu_usage_lower(threshold=0.5, timeout=30, usage_interval=1.0)

list_box = app.InstalledUpdates.FolderViewListBox

# list all updates
items = list_box.descendants(control_type='ListItem')
all_updates = [item.window_text() for item in items]
print('\nAll updates ({}):\n'.format(len(all_updates)))
print(all_updates)

# list updates from "Microsoft Windows" group only
windows_group_box = list_box.child_window(title_re='^Microsoft Windows.*', control_type='Group')
windows_items = windows_group_box.descendants(control_type='ListItem')
windows_updates = [item.window_text() for item in windows_items]
print('\nWindows updates only ({}):\n'.format(len(windows_updates)))
print(windows_updates)
45 changes: 45 additions & 0 deletions examples/mspaint.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
"""
Example script for MS Paint
Requirements:
- tested on Windows 10 (should work on Win7+)
- pywinauto 0.6.1+
The example shows how to work with MS Paint application. It opens
JPEG image and resizes it using "Resize and Skew" dialog.
"""

from pywinauto import Application

app = Application(backend='uia').start(r'mspaint.exe')
dlg = app.window(title_re='.* - Paint')

# File->Open menu selection
dlg.File_tab.click()
dlg.child_window(title='Open', control_type='MenuItem').invoke()

# handle Open dialog
file_name_edit = dlg.Open.child_window(title="File name:", control_type="Edit")
file_name_edit.set_text('walter_cat.jpg')
# There are 2 Open buttons:
# dlg.Open.Open.click() will call drop down list of the file name combo box.
# The child_window statement is just copied from print_control_identifiers().
dlg.Open.child_window(title="Open", auto_id="1", control_type="Button").click()

dlg.ResizeButton.click()
dlg.ResizeAndSkew.Pixels.select()
if dlg.ResizeAndSkew.Maintain_aspect_ratio.get_toggle_state() != 1:
dlg.ResizeAndSkew.Maintain_aspect_ratio.toggle()
dlg.ResizeAndSkew.HorizontalEdit1.set_text('100')
dlg.ResizeAndSkew.OK.click()

# Select menu "File->Save as->PNG picture"
dlg.File_tab.click()
dlg.SaveAsGroup.child_window(title="Save as", found_index=1).invoke()
dlg.child_window(title='PNG picture').invoke()
# Type output file name and save
dlg.SaveAs.File_name_ComboBox.Edit.set_text('walter_cat_resized.png')
dlg.SaveAs.Save.click()

# Close application
dlg.close()
Binary file added examples/walter_cat.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 1 addition & 1 deletion pywinauto/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@

"""Python package for automating GUI manipulation on Windows"""

__version__ = "0.6.1"
__version__ = "0.6.2"

import sys

Expand Down
7 changes: 3 additions & 4 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,10 +69,9 @@ def setup_path(path = ""):
packages = ["pywinauto", "pywinauto.linux"]

setup(name='pywinauto',
version = '0.6.1',
description = 'pywinauto is a set of python '
'modules to automate the Microsoft Windows GUI',
keywords = "windows automation gui GuiAuto",
version = '0.6.2',
description = 'A set of Python modules to automate the Microsoft Windows GUI',
keywords = "windows gui automation GuiAuto testing test desktop mouse keyboard",
url = "http://pywinauto.github.io/",
author = 'Mark Mc Mahon and Contributors',
author_email = '[email protected]',
Expand Down

0 comments on commit 24cde23

Please sign in to comment.