Ejemplo n.º 1
0
    def __init__(self,
                 width,
                 height,
                 width_in_cells,
                 height_in_cells,
                 visible=False,
                 focusable=False,
                 theme=None):
        Div.__init__(self, width, height, focusable, theme)
        self.visible = visible
        self.width_in_cells = width_in_cells
        self.height_in_cells = height_in_cells
        self.cell_width = self.width / self.width_in_cells
        self.cell_height = self.height / self.height_in_cells

        self.cells = Matrix(width_in_cells, height_in_cells)
        for y in xrange(height_in_cells):
            for x in xrange(width_in_cells):
                div = Div(self.cell_width,
                          self.cell_height,
                          focusable=False,
                          theme=self.theme)
                pos = (x * self.cell_width, y * self.cell_height)
                self.cells[x, y] = div
                self.add_widget(div, pos)
Ejemplo n.º 2
0
    def add_columns(self, number_of_columns=1):
        """
        Add one or more cell columns to the Grid.

        The Grid's dimensions will be expanded, while the size of each
        cell will remain unchanged.

        *number_of_columns* specifies how many columns will be added. This
        defaults to 1.
        """
        old_width = self.width_in_cells
        self.width_in_cells += number_of_columns
        self.cells.resize(self.width_in_cells, self.height_in_cells)

        for y in xrange(self.height_in_cells):
            for x in xrange(old_width, self.width_in_cells):
                div = Div(self.cell_width,
                          self.cell_height,
                          focusable=False,
                          theme=self.theme)
                pos = (x * self.cell_width, y * self.cell_height)
                self.cells[x, y] = div
                self.add_widget(div, pos)