示例#1
0
    def addexproute(self, exp_order, layer_nr):
        """
        This function initialises the Arrows of the export route order and its numbers.
        """
        for shape_nr in range(len(exp_order)):
            shape = self.shapes[exp_order[shape_nr]]
            st = self.expprv
            en = None
            # if hasattr(shape.geos[0], "type") and shape.geos[0].type is "Circle":
            #     en,self.expprv = shape.geos[0].O,shape
            # else:
            en, self.expprv = shape.get_start_end_points_physical()
            if (hasattr(shape.geos[0], "type")
                    and shape.geos[0].type is "Circle"):
                self.expcol = QtCore.Qt.darkGreen
            self.routearrows.append(
                Arrow(startp=en,
                      endp=st,
                      color=self.expcol,
                      pencolor=self.expcol))

            self.expcol = QtCore.Qt.darkGray

            self.routetext.append(
                RouteText(text=("%s,%s" % (layer_nr, shape_nr + 1)),
                          startp=en))
            # self.routetext[-1].ItemIgnoresTransformations

            self.addItem(self.routearrows[-1])
            self.addItem(self.routetext[-1])
示例#2
0
    def addexprouteen(self):
        st = self.expprv
        en = Point(g.config.vars.Plane_Coordinates['axis1_start_end'],
                   g.config.vars.Plane_Coordinates['axis2_start_end'])
        self.expcol = QtCore.Qt.darkRed

        self.routearrows.append(
            Arrow(startp=en, endp=st, color=self.expcol, pencolor=self.expcol))

        self.addItem(self.routearrows[-1])
 def __init__(
     self,
     pos: Tuple[int, int],
     width: int,
     height: int,
     action: Callable,
     args: List[Any],
     initial_arg: Any,
 ) -> None:
     super().__init__()
     self.pos_x = pos[0]
     self.pos_y = pos[1]
     self.width = width
     self.height = height
     self.action = action
     self.args = args
     self.current = initial_arg
     self.left_arrow = Arrow((pos[0] - 4, pos[1]), height, left=True)
     self.right_arrow = Arrow((pos[0] + width + 4, pos[1]), height)
     self.update_color()
示例#4
0
 def createenarrow(self, shape):
     """
     This function creates the Arrows at the end point of a shape when the
     shape is selected.
     @param shape: The shape for which the Arrow shall be created.
     """
     length = 20
     end, end_ang = shape.get_start_end_points_physical(False, True)
     arrow = Arrow(startp=end,
                   length=length,
                   angle=end_ang,
                   color=QColor(0, 245, 100),
                   pencolor=QColor(0, 180, 50),
                   startarrow=False)
     return arrow
示例#5
0
    def createstarrow(self, shape):
        """
        This function creates the Arrows at the end point of a shape when the
        shape is selected.
        @param shape: The shape for which the Arrow shall be created.
        """

        length = 20
        start, start_ang = shape.get_start_end_points_physical(True, True)
        arrow = Arrow(startp=start,
                      length=length,
                      angle=start_ang,
                      color=QColor(50, 200, 255),
                      pencolor=QColor(50, 100, 255))
        return arrow
class SwitchButton(ButtonABC):
    def __init__(
        self,
        pos: Tuple[int, int],
        width: int,
        height: int,
        action: Callable,
        args: List[Any],
        initial_arg: Any,
    ) -> None:
        super().__init__()
        self.pos_x = pos[0]
        self.pos_y = pos[1]
        self.width = width
        self.height = height
        self.action = action
        self.args = args
        self.current = initial_arg
        self.left_arrow = Arrow((pos[0] - 4, pos[1]), height, left=True)
        self.right_arrow = Arrow((pos[0] + width + 4, pos[1]), height)
        self.update_color()

    def update(self, mouse: Tuple[int, int, int], click: bool) -> None:
        mouse_pressed = pygame.mouse.get_pressed()
        if (self.pos_x < mouse[0] < self.pos_x + self.width
                and self.pos_y < mouse[1] < self.pos_y + self.height):
            if click:
                self.action(self.current)
            if mouse_pressed[0]:
                self.state = States.PRESSED
            else:
                self.state = States.HOVER
        else:
            self.state = States.NORMAL

        if self.left_arrow.update(mouse):
            if click:
                self.current = self.args[self.args.index(self.current) - 1]
        elif self.right_arrow.update(mouse):
            if click:
                index = self.args.index(self.current) + 1
                index %= len(self.args)
                self.current = self.args[index]
        self.update_color()

    def draw(self) -> None:
        pygame.draw.rect(screen, self.color,
                         (self.pos_x, self.pos_y, self.width, self.height))
        large_text = pygame.font.Font('freesansbold.ttf', 15)
        text_surf, text_rect = text_objects(self.current.name, large_text)
        text_rect.center = (self.pos_x + self.width / 2,
                            self.pos_y + self.height / 2)
        screen.blit(text_surf, text_rect)

        self.left_arrow.draw()
        self.right_arrow.draw()