Пример #1
0
def _args2vlink(args: LinkArgs) -> VLink:
    """Make arguments as a VLink object."""
    if args.name == '':
        return VLink.HOLDER
    return VLink(args.name, args.color, [
        int(p.replace('Point', '')) for p in _no_empty(args.points.split(','))
    ], color_rgb)
Пример #2
0
    def __init__(self):
        super(MainWindowBase, self).__init__()
        # Environment path
        self.env = ""
        # Alignment mode
        self.alignment_mode = 0
        # Entities list
        self.vpoint_list = []
        self.vlink_list = [VLink(VLink.FRAME, 'White', (), color_rgb)]
        # Condition list of context menus
        self.context = _Context()
        # Preference
        self.prefer = Preferences()
        # Set path from command line
        home_dir = QDir.home()
        self.settings = QSettings(home_dir.absoluteFilePath(".pyslvs.ini"),
                                  QSettings.IniFormat, self)
        if ARGUMENTS.c:
            self.set_locate(QDir(ARGUMENTS.c).absolutePath())
        else:
            home_dir.cd("Desktop")
            env = self.settings.value("ENV", home_dir.absolutePath())
            self.set_locate(str(env))

        # Initialize custom UI
        self.__undo_redo()
        self.__appearance()
        self.__alignment()
        self.__free_move()
        self.__options()
        self.__context_menu()
 def __draw_link(self, vlink: VLink) -> None:
     """Draw a link."""
     if vlink.name == VLink.FRAME or not vlink.points:
         return
     pen = QPen()
     # Rearrange: Put the nearest point to the next position.
     qpoints = convex_hull(
         [(c.x * self.zoom, c.y * -self.zoom)
          for c in vlink.points_pos(self.vpoints)], as_qpoint=True)
     if (
         self.select_mode == SelectMode.LINK
         and self.vlinks.index(vlink) in self.selections
     ):
         pen.setWidth(self.link_width + 6)
         pen.setColor(Qt.black if self.monochrome else QColor(161, 16, 239))
         self.painter.setPen(pen)
         self.painter.drawPolygon(*qpoints)
     pen.setWidth(self.link_width)
     pen.setColor(Qt.black if self.monochrome else color_qt(vlink.color))
     self.painter.setPen(pen)
     self.painter.drawPolygon(*qpoints)
     if not self.show_point_mark:
         return
     pen.setColor(Qt.darkGray)
     self.painter.setPen(pen)
     p_count = len(qpoints)
     cen_x = sum(p.x() for p in qpoints) / p_count
     cen_y = sum(p.y() for p in qpoints) / p_count
     self.painter.drawText(
         QRectF(cen_x - 50, cen_y - 50, 100, 100),
         Qt.AlignCenter,
         f'[{vlink.name}]'
     )
            def catch_l(vlink: VLink) -> bool:
                """Detection function for links.

                + Is polygon: Using Qt polygon geometry.
                + If just a line: Create a range for mouse detection.
                """
                points = [(c.x * self.zoom, c.y * -self.zoom)
                          for c in vlink.points_pos(self.vpoints)]
                if len(points) > 2:
                    polygon = QPolygonF(convex_hull(points, as_qpoint=True))
                else:
                    polygon = QPolygonF(convex_hull(
                        [(x + self.sr, y + self.sr) for x, y in points]
                        + [(x - self.sr, y - self.sr) for x, y in points],
                        as_qpoint=True
                    ))
                if rect:
                    return polygon.intersects(
                        QPolygonF(self.selector.to_rect(self.zoom)))
                else:
                    return polygon.containsPoint(
                        QPointF(self.selector.x, -self.selector.y) * self.zoom,
                        Qt.WindingFill
                    )
Пример #5
0
def _args2vlink(args: Sequence[str]) -> Optional[VLink]:
    """Make arguments as a VLink object."""
    if args[0] == '':
        return None
    points = [int(p.replace('Point', '')) for p in _no_empty(args[2].split(','))]
    return VLink(args[0], args[1], points, color_rgb)