Skip to content

Commit

Permalink
Merge remote-tracking branch 'remotes/upstream/master' into prepare_0…
Browse files Browse the repository at this point in the history
…_6_6
  • Loading branch information
vasily-v-ryabov committed Feb 1, 2019
2 parents 97e3bd6 + 12c9ce7 commit 98533ee
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 18 deletions.
Binary file modified apps/WinForms_samples/DataGridView_TestApp.exe
Binary file not shown.
Binary file modified apps/WinForms_samples/x64/DataGridView_TestApp.exe
Binary file not shown.
39 changes: 21 additions & 18 deletions pywinauto/controls/uia_controls.py
Original file line number Diff line number Diff line change
Expand Up @@ -644,6 +644,9 @@ def __init__(self, elem):
self.row_header = False
self.col_header = False

def __getitem__(self, key):
return self.get_item(key)

def __raise_not_implemented(self):
raise NotImplementedError("This method not work properly for WinForms DataGrid, use cells()")

Expand Down Expand Up @@ -781,27 +784,27 @@ def get_item(self, row):
if isinstance(row, six.string_types):
# Try to find item using FindItemByProperty
# That way we can get access to virtualized (unloaded) items
com_elem = self.iface_item_container.FindItemByProperty(0, IUIA().UIA_dll.UIA_NamePropertyId, row)
# Try to load element using VirtualizedItem pattern
try:
get_elem_interface(com_elem, "VirtualizedItem").Realize()
itm = uiawrapper.UIAWrapper(uia_element_info.UIAElementInfo(com_elem))
except NoPatternInterfaceError:
# Item doesn't support VirtualizedItem pattern - item is already on screen or com_elem is NULL
com_elem = self.iface_item_container.FindItemByProperty(0, IUIA().UIA_dll.UIA_NamePropertyId, row)
# Try to load element using VirtualizedItem pattern
try:
get_elem_interface(com_elem, "VirtualizedItem").Realize()
itm = uiawrapper.UIAWrapper(uia_element_info.UIAElementInfo(com_elem))
except ValueError:
# com_elem is NULL pointer
# Get DataGrid row
try:
itm = self.descendants(title=row)[0]
# Applications like explorer.exe usually return ListItem
# directly while other apps can return only a cell.
# In this case we need to take its parent - the whole row.
if not isinstance(itm, ListItemWrapper):
itm = itm.parent()
except IndexError:
raise ValueError("Element '{0}' not found".format(row))
except NoPatternInterfaceError:
# Item doesn't support VirtualizedItem pattern - item is already on screen or com_elem is NULL
itm = uiawrapper.UIAWrapper(uia_element_info.UIAElementInfo(com_elem))
except (NoPatternInterfaceError, ValueError):
# com_elem is NULL pointer or item doesn't support ItemContainer pattern
# Get DataGrid row
try:
itm = self.descendants(title=row)[0]
# Applications like explorer.exe usually return ListItem
# directly while other apps can return only a cell.
# In this case we need to take its parent - the whole row.
if not isinstance(itm, ListItemWrapper):
itm = itm.parent()
except IndexError:
raise ValueError("Element '{0}' not found".format(row))
elif isinstance(row, six.integer_types):
# Get the item by a row index
# TODO: Can't get virtualized items that way
Expand Down
17 changes: 17 additions & 0 deletions pywinauto/unittests/test_uiawrapper.py
Original file line number Diff line number Diff line change
Expand Up @@ -1165,6 +1165,23 @@ def setUp(self):
self.add_row_button = dlg.AddRow
self.row_header_button = dlg.RowHeader
self.col_header_button = dlg.ColHeader
self.list_box = dlg.ListBox

def test_list_box_item_selection(self):
"""Test get_item method"""
self.list_box.set_focus()
list_box_item = self.list_box.get_item('item (2)')
self.assertFalse(list_box_item.is_selected())
list_box_item.select()
self.assertTrue(list_box_item.is_selected())

def test_list_box_getitem_overload(self):
"""Test __getitem__ method"""
self.list_box.set_focus()
list_box_item = self.list_box['item (2)']
self.assertFalse(list_box_item.is_selected())
list_box_item.select()
self.assertTrue(list_box_item.is_selected())

def test_empty_grid(self):
"""Test some error cases handling"""
Expand Down

0 comments on commit 98533ee

Please sign in to comment.