Checking visibility of a TableItem in a Table (SWT)

Last edited on

The SWT classes Table and TableItem do not provide a direct way to check if a TableItem (a cell of the table) is visible or not.

This check can be performed by accessing the SWT API of the Table and TableItem objects and by comparing their bounds:

def is_swt_tableitem_visible(swt_table_obj, row, column, check_fully_visible):
    row_obj = waitForObjectItem(swt_table_obj, "%s/%s" % (row, column)).item
    cell_bounds = row_obj.getBounds(column)
    table_bounds = swt_table_obj.bounds

    x_ok = table_bounds.width >= cell_bounds.x
    y_ok = table_bounds.height >= cell_bounds.y
    top_left_visible = x_ok and y_ok

    width_ok = table_bounds.width >= cell_bounds.x + cell_bounds.width
    height_ok = table_bounds.height >= cell_bounds.y + cell_bounds.height
    bottom_right_visible = width_ok and height_ok

    if check_fully_visible:
        return top_left_visible and bottom_right_visible
    return top_left_visible or bottom_right_visible

def is_swt_tableitem_fully_visible(swt_table_obj, row, column):
    return is_swt_tableitem_visible(swt_table_obj, row, column, True)

def is_swt_tableitem_partially_visible(swt_table_obj, row, column):
    return is_swt_tableitem_visible(swt_table_obj, row, column, False)
import names
def main():
    # ...

    t = waitForObject(names.Table_Table)
    test.log("Partially visible? 0/0: %s" % is_swt_tableitem_partially_visible(t, 0, 0))
    test.log("Fully visible? 0/0: %s" % is_swt_tableitem_fully_visible(t, 0, 0))