Skip to content

Commit

Permalink
Merge branch 'atspi' into refactor-dump-tree
Browse files Browse the repository at this point in the history
  • Loading branch information
eltimen committed Mar 13, 2021
2 parents bf8e509 + 69121be commit 91e1248
Show file tree
Hide file tree
Showing 23 changed files with 193 additions and 215 deletions.
Binary file added apps/MFC_samples/NewControls.exe
Binary file not shown.
Binary file added apps/MFC_samples/x64/NewControls.exe
Binary file not shown.
10 changes: 5 additions & 5 deletions examples/forte_agent_sample.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,16 +20,16 @@
time.sleep(.5)

# if the trial nag dialog pops up
if app.window(title = "Forte Agent Trial").Exists():
if app.window(title = "Forte Agent Trial").exists():
#app.ForteAgentTrial.IdLikeToContinueUsingAgentfor7moredays.click()
app.ForteAgentTrial.IdliketouseFreeAgent.check()
app.ForteAgentTrial.OK.click()

if app.window(title = "Free Agent Registration").Exists():
if app.window(title = "Free Agent Registration").exists():
app.FreeAgentRegistration.ImreallybusyRemindmein30.click()
app.FreeAgentRegistration.OK.close_click()

if app.window(title = "What's New Reminder").Exists():
if app.window(title = "What's New Reminder").exists():
app.WhatsNewReminder.ImreallybusyRemindmein90.click()
app.WhatsNewReminder.OK.close_click()

Expand All @@ -39,7 +39,7 @@
app.FreeAgent.wait("ready")

# if we get the Agent Setup wizard pops up close it
if app.AgentSetupWizard.Cancel.Exists(1):
if app.AgentSetupWizard.Cancel.exists(1):
app.AgentSetupWizard.Cancel.click()
app.AgentSetupWizard2.Yes.click()

Expand Down Expand Up @@ -73,7 +73,7 @@

# pick something other then a file menu item
app.FreeAgent.menu_select("Tools->ApplyFiltersToFolder")
if app.ToolsApplyFilters.OK.Exists():
if app.ToolsApplyFilters.OK.exists():
app.ToolsApplyFilters.OK.click()

#app.AgentTip.OK.click()
Expand Down
4 changes: 2 additions & 2 deletions examples/list_windows_updates.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
app.wait_cpu_usage_lower(threshold=0.5, timeout=30, usage_interval=1.0)

# Go to "Installed Updates"
app.window(name_re='Programs').child_window(name='View installed updates', control_type='Hyperlink').invoke()
app.window(name_re='Programs').by(name='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
Expand All @@ -33,7 +33,7 @@
print(all_updates)

# list updates from "Microsoft Windows" group only
windows_group_box = list_box.child_window(name_re='^Microsoft Windows.*', control_type='Group')
windows_group_box = list_box.by(name_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)))
Expand Down
10 changes: 5 additions & 5 deletions examples/mspaint.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,15 +29,15 @@

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

# handle Open dialog
file_name_edit = dlg.Open.child_window(name="File name:", control_type="Edit")
file_name_edit = dlg.Open.by(name="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(name="Open", auto_id="1", control_type="Button").click()
dlg.Open.by(name="Open", auto_id="1", control_type="Button").click()

dlg.ResizeButton.click()
dlg.ResizeAndSkew.Pixels.select()
Expand All @@ -48,8 +48,8 @@

# Select menu "File->Save as->PNG picture"
dlg.File_tab.click()
dlg.SaveAsGroup.child_window(name="Save as", found_index=1).invoke()
dlg.child_window(name='PNG picture', found_index=0).invoke()
dlg.SaveAsGroup.by(name="Save as", found_index=1).invoke()
dlg.by(name='PNG picture', found_index=0).invoke()
# Type output file name and save
dlg.SaveAs.File_name_ComboBox.Edit.set_text('walter_cat_resized.png')
dlg.SaveAs.Save.click()
Expand Down
2 changes: 1 addition & 1 deletion examples/notepad_fast.py
Original file line number Diff line number Diff line change
Expand Up @@ -200,7 +200,7 @@ def run_notepad():

# for some reason my current printer driver
# window does not close cleanly :(
if doc_props.Cancel.Exists():
if doc_props.Cancel.exists():
doc_props.OK.close_click()

# ----- 2nd Page Setup Dialog again ----
Expand Down
2 changes: 1 addition & 1 deletion examples/notepad_slow.py
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,7 @@ def run_notepad():

# for some reason my current printer driver
# window does not close cleanly :(
if doc_props.Cancel.Exists():
if doc_props.Cancel.exists():
doc_props.OK.close_click()

# ----- 2nd Page Setup Dialog again ----
Expand Down
2 changes: 1 addition & 1 deletion examples/save_from_firefox.py
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@

try:
# if asked to overwrite say yes
if app.SaveAs.Yes.Exists():
if app.SaveAs.Yes.exists():
app.SaveAs.Yes.close_click()
except WindowAmbiguousError as e:
for w in e.windows:
Expand Down
2 changes: 1 addition & 1 deletion examples/save_from_internet_explorer.py
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@
app.SaveWebPage.Save.close_click()

# if asked to overwrite say yes
if app.SaveWebPage.Yes.Exists():
if app.SaveWebPage.Yes.exists():
app.SaveWebPage.Yes.close_click()

print("saved:", outputfilename)
Expand Down
2 changes: 1 addition & 1 deletion examples/test_drag_n_drop.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
app = pywinauto.Application().start(os.path.join(mfc_samples_folder,
u"CmnCtrl1.exe"))

tree = app.Common_Controls_Sample.TreeView.WrapperObject()
tree = app.Common_Controls_Sample.TreeView.by()

birds = tree.get_item(r'\Birds')
dogs = tree.get_item(r'\Dogs')
Expand Down
6 changes: 3 additions & 3 deletions examples/uninstall_7zip.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,16 +30,16 @@
explorer.PopupMenu.menu_item('Uninstall').click()

Confirmation = explorer.window(name='Programs and Features', class_name='#32770', active_only=True)
if Confirmation.Exists():
if Confirmation.exists():
Confirmation.Yes.click_input()
Confirmation.wait_not('visible')

WindowsInstaller = explorer.window(name='Windows Installer', class_name='#32770', active_only=True)
if WindowsInstaller.Exists():
if WindowsInstaller.exists():
WindowsInstaller.wait_not('visible', timeout=20)

SevenZipInstaller = explorer.window(name='7-Zip 9.20 (x64 edition)', class_name='#32770', active_only=True)
if SevenZipInstaller.Exists():
if SevenZipInstaller.exists():
SevenZipInstaller.wait_not('visible', timeout=20)

if '7-Zip 9.20 (x64 edition)' not in ProgramsAndFeatures.FolderView.texts():
Expand Down
42 changes: 10 additions & 32 deletions pywinauto/base_application.py
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,6 @@
import sys
import os.path
import time
import warnings
import locale
import codecs
import collections
Expand Down Expand Up @@ -162,18 +161,10 @@ def __init__(self, search_criteria, allow_magic_lookup=True):
self.backend = registry.backends[search_criteria['backend']]
self.allow_magic_lookup = allow_magic_lookup

if self.backend.name == 'win32':
# Non PEP-8 aliases for partial backward compatibility
self.WrapperObject = deprecated(self.wrapper_object)
self.ChildWindow = deprecated(self.child_window)
self.Exists = deprecated(self.exists)
self.Wait = deprecated(self.wait)
self.WaitNot = deprecated(self.wait_not)
self.PrintControlIdentifiers = deprecated(self.print_control_identifiers)

self.Window = deprecated(self.child_window, deprecated_name='Window')
self.Window_ = deprecated(self.child_window, deprecated_name='Window_')
self.window_ = deprecated(self.child_window, deprecated_name='window_')
# Non PEP-8 aliases for partial backward compatibility
self.wrapper_object = deprecated(self.find, deprecated_name='wrapper_object')
self.child_window = deprecated(self.by, deprecated_name="child_window")
self.window = deprecated(self.by, deprecated_name='window')

def __call__(self, *args, **kwargs):
"""No __call__ so return a useful error"""
Expand Down Expand Up @@ -215,7 +206,7 @@ def __get_ctrl(self, criteria_):
ctrl_criteria["parent"] = previous_parent

if isinstance(ctrl_criteria["parent"], WindowSpecification):
ctrl_criteria["parent"] = ctrl_criteria["parent"].wrapper_object()
ctrl_criteria["parent"] = ctrl_criteria["parent"].find()

# resolve the control and return it
if 'backend' not in ctrl_criteria:
Expand Down Expand Up @@ -263,12 +254,12 @@ def __resolve_control(self, criteria, timeout=None, retry_interval=None):

return ctrl

def wrapper_object(self):
def find(self):
"""Allow the calling code to get the HwndWrapper object"""
ctrls = self.__resolve_control(self.criteria)
return ctrls[-1]

def child_window(self, **criteria):
def by(self, **criteria):
"""
Add criteria for a control
Expand All @@ -286,15 +277,6 @@ def child_window(self, **criteria):

return new_item

def window(self, **criteria):
"""Deprecated alias of child_window()"""
warnings.warn(
"WindowSpecification.Window() WindowSpecification.Window_(), "
"WindowSpecification.window() and WindowSpecification.window_() "
"are deprecated, please switch to WindowSpecification.child_window()",
DeprecationWarning)
return self.child_window(**criteria)

def __getitem__(self, key):
"""
Allow access to dialogs/controls through item access
Expand Down Expand Up @@ -353,7 +335,7 @@ def __getattribute__(self, attr_name):
try:
return object.__getattribute__(self, attr_name)
except AttributeError:
wrapper_object = self.wrapper_object()
wrapper_object = self.find()
try:
return getattr(wrapper_object, attr_name)
except AttributeError:
Expand Down Expand Up @@ -382,7 +364,7 @@ def __getattribute__(self, attr_name):
try:
return getattr(ctrls[-1], attr_name)
except AttributeError:
return self.child_window(best_match=attr_name)
return self.by(best_match=attr_name)
else:
# FIXME - I don't get this part at all, why is it win32-specific and why not keep the same logic as above?
# if we have been asked for an attribute of the dialog
Expand Down Expand Up @@ -531,7 +513,7 @@ def wait(self, wait_for, timeout=None, retry_interval=None):
lambda: self.__check_all_conditions(check_method_names, retry_interval))

# Return the wrapped control
return self.wrapper_object()
return self.find()

def wait_not(self, wait_for_not, timeout=None, retry_interval=None):
"""
Expand Down Expand Up @@ -714,10 +696,6 @@ def print_identifiers(element_node, current_depth=0, log_func=print):
auto_id = ctrl.element_info.automation_id
if hasattr(ctrl.element_info, 'control_type'):
control_type = ctrl.element_info.control_type
if control_type:
class_name = None # no need for class_name if control_type exists
else:
control_type = None # if control_type is empty, still use class_name instead
criteria_texts = []
if ctrl_text:
criteria_texts.append(u'name="{}"'.format(ctrl_text))
Expand Down
2 changes: 1 addition & 1 deletion pywinauto/taskbar.py
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ def RightClickHiddenSystemTrayIcon(button, exact=False, by_tooltip=False):

# these are the icons - what people normally think of
# as the system tray
SystemTrayIcons = TaskBar.child_window(class_name="ToolbarWindow32", found_index=0)
SystemTrayIcons = TaskBar.by(class_name="ToolbarWindow32", found_index=0)

# the toolbar with the running applications
RunningApplications = TaskBar.MSTaskListWClass
Expand Down
Loading

0 comments on commit 91e1248

Please sign in to comment.