Exemplo n.º 1
0
    def output_to(self, row, column):
        """Redirects output to the corresponding cell of this grid.

    Args:
      row: 0 based row
      column: 0 based column

    Yields:
      nothing
    """
        if row < 0 or column < 0 or row >= self.rows or column >= self.columns:
            raise _widget.WidgetException(
                'Cell (%d, %d) is outside of boundaries of %dx%d grid' %
                (row, column, self.rows, self.columns))
        component_id = self._get_cell_id(row, column)
        with self._active_component(component_id):
            yield
Exemplo n.º 2
0
  def _populate(self, row_data, col_data, render, header_render=None):
    """Populate the grid with a cross product of row and cols."""

    def display_one_cell(render_func, *args):
      result = render_func(*args)
      if result is not None:
        display.display(result)

    header_render = header_render or display.display
    rows = list(row_data)
    cols = list(col_data)
    row_offset = 1 if self.header_row else 0
    col_offset = 1 if self.header_column else 0

    if (row_offset + len(rows) > self.rows or
        col_offset + len(cols) > self.columns):
      raise _widget.WidgetException('Can not fit %dx%d data into %dx%d grid. ' %
                                    (len(rows), len(cols), self.rows,
                                     self.columns))
    for row, col in iter(self):
      row -= row_offset
      col -= col_offset
      if row >= len(rows):
        continue
      if col >= len(cols):
        continue

      if row < 0 and col < 0:
        continue
      if row < 0:
        display_one_cell(header_render, cols[col])
        continue
      if col < 0:
        display_one_cell(header_render, rows[row])
        continue
      display_one_cell(render, rows[row], cols[col])
    return self