Ejemplo n.º 1
0
    def create_grid(self):
        """
        Setup the grid. After this function has has been called no modifications
        to the grid are possible.

        @todo: make it possible to change the layout during runtime
        """
        # do some calculations
        padding_x, padding_y = self.item_padding
        if padding_x is None:
            # no padding is given. Get the number fitting items
            # and devide the remaining space as paddingand border
            self.num_items_x = int(self.width / self.cell_size[0])
            padding_x = self.width / self.num_items_x - self.cell_size[0]
            self.item_width = self.cell_size[0] + padding_x
        else:
            self.item_width = self.cell_size[0] + padding_x
            # now that we know the sizes check how much items fit
            self.num_items_x = int(self.width / self.item_width)
        if padding_y is None:
            # no padding is given. Get the number fitting items
            # and devide the remaining space as padding and border
            self.num_items_y = int(self.height / self.cell_size[1])
            padding_y = self.height / self.num_items_y - self.cell_size[1]
            self.item_height = self.cell_size[1] + padding_y
        else:
            self.item_height = self.cell_size[1] + padding_y
            # now that we know the sizes check how much items fit
            self.num_items_y = int(self.height / self.item_height)
        self.item_padding = padding_x, padding_y
        # we now center the grid by default
        x0 = (self.width - self.num_items_x * self.item_width + padding_x) / 2
        y0 = (self.height - self.num_items_y * self.item_height +
              padding_y) / 2
        self.clip = (x0 - padding_x, y0 - padding_y), \
            (self.num_items_x * self.item_width + padding_x, self.num_items_y * self.item_height + padding_y)
        self.location = (0, 0)
        # list of rendered items
        self.item_widgets = {}
        # group of items
        self.item_group = AbstractGroup((x0, y0))
        self.add(self.item_group)
        self.create_grid = None