Exemplo n.º 1
0
    def __getitem__(self, item):
        if isinstance(item, six.string_types):
            if self.assoc_column is None:
                raise TypeError('You cannot use string indices when no assoc_column specified!')
            try:
                row = self.row((self.assoc_column, item))
            except RowNotFound:
                raise KeyError(
                    'Row {!r} not found in table by associative column {!r}'.format(
                        item, self.assoc_column))
            at_index = row.index
        elif isinstance(item, int):
            at_index = item
            if at_index > self.row_count:
                raise IndexError('Integer row index {} is greater than row count {}'
                                 .format(at_index, self.row_count))
        else:
            raise TypeError('Table [] accepts only strings or integers.')
        if at_index < 0:
            # To mimic the list handling
            at_index = self._process_negative_index(at_index)

        if self.table_tree:
            nodes = self.resolver.glob(self.table_tree, '/table/tbody/tr*')
            at_index = at_index + 1 if self._is_header_in_body else at_index
            try:
                return six.next(n.obj for n in nodes if n.position == at_index)
            except StopIteration:
                raise RowNotFound('Row not found by index {} via {}'.format(at_index, item))
        else:
            return self.Row(self, at_index, logger=create_item_logger(self.logger, item))
Exemplo n.º 2
0
    def row_by_cell_or_widget_value(self, column, value):
        """Row queries do not work with embedded widgets. Therefore you can use this method.

        Args:
            column: Position or name fo the column where you are looking the value for.
            value: The value looked for

        Returns:
            :py:class:`TableRow` instance

        Raises:
            :py:class:`RowNotFound`
        """
        try:
            return self.row((column, value))
        except RowNotFound:
            for row in self.rows():
                if row[column].widget is None:
                    continue
                # Column has a widget
                if not row[column].widget.is_displayed:
                    continue
                # Column widget is displayed...
                if row[column].widget.read() == value:
                    return row  # found matching widget value
                # But the value didn't match, keep looping
                else:
                    continue
            else:
                raise RowNotFound('Row not found by {!r}/{!r}'.format(column, value))
Exemplo n.º 3
0
 def row(self, *extra_filters, **filters):
     try:
         return six.next(self.rows(*extra_filters, **filters))
     except StopIteration:
         raise RowNotFound(
             'Row not found when using filters {!r}/{!r}'.format(
                 extra_filters, filters))