Ejemplo n.º 1
0
    def position_relative(self,
                          widget: Gtk.Widget,
                          neighbour: Gtk.Widget,
                          orientation: str,
                          x_size: int,
                          y_size: int,
                          spacing: int = 0) -> None:
        """
        Position a widget relatively to another widget in a grid layout
        :param widget: the widget to be positioned
        :param neighbour: the neighbour widget to be used as a reference point
        :param orientation: the orientation of the widget relative to the neighbour
                should be able to accept:
                    NORTH/EAST/SOUTH/WEST
                    N/E/S/W
                    TOP/BOTTOM/RIGHT/LEFT
                For Future: Maybe consider using a python enum equivalent
        :param x_size: the width of the widget in the grid layout
        :param y_size: the height of the widget in the grid layout
        :param spacing: space between the widgets
        :return: void
        """
        x_spacing = 1 if orientation.upper() in [
            "NORTH", "N", "TOP", "SOUTH", "S", "BOTTOM"
        ] else spacing
        y_spacing = 1 if orientation.upper() in [
            "EAST", "E", "RIGHT", "WEST", "W", "LEFT"
        ] else spacing
        root_widget = neighbour if spacing == 0 else \
            self.add_spacing_next_to(neighbour, orientation, x_spacing, y_spacing)

        widget.set_vexpand(True)
        widget.set_hexpand(True)
        widget.set_size_request(0, 0)

        if orientation.upper() in ["NORTH", "N", "TOP"]:
            self.grid.attach_next_to(widget, root_widget, Gtk.PositionType.TOP,
                                     x_size, y_size)
        elif orientation.upper() in ["EAST", "E", "RIGHT"]:
            self.grid.attach_next_to(widget, root_widget,
                                     Gtk.PositionType.RIGHT, x_size, y_size)
        elif orientation.upper() in ["SOUTH", "S", "BOTTOM"]:
            self.grid.attach_next_to(widget, root_widget,
                                     Gtk.PositionType.BOTTOM, x_size, y_size)
        elif orientation.upper() in ["WEST", "W", "LEFT"]:
            self.grid.attach_next_to(widget, root_widget,
                                     Gtk.PositionType.LEFT, x_size, y_size)
        else:
            raise ValueError("Incorrect orientation type " + orientation)
Ejemplo n.º 2
0
 def position_absolute(self, widget: Gtk.Widget, x_position: int,
                       y_position: int, x_size: int, y_size: int) -> None:
     """
     Position a widget absolutely in a grid layout
     :param widget: the widget to be positioned
     :param x_position: the horizontal position of the widget in the grid
     :param y_position: the vertical position of the widget in the grid
     :param x_size: the width of the widget in the grid layout
     :param y_size: the width of the widget in the grid layout
     :return: void
     """
     widget.set_vexpand(True)
     widget.set_hexpand(True)
     widget.set_size_request(0, 0)
     self.grid.attach(widget, x_position, y_position, x_size, y_size)