예제 #1
0
def set_custom_color(color_box: QComboBox, color_text: str):
    color_index = color_box.findText(color_text)
    if color_index > -1:
        color_box.setCurrentIndex(color_index)
    else:
        color_box.addItem(color_icon(color_text), color_text)
        color_box.setCurrentIndex(color_box.count() - 1)
예제 #2
0
    def __init__(self, vpoints: List[VPoint], vlinks: List[VLink],
                 pos: Union[int, bool], parent: QWidget):
        """Input data reference from main window.

        + Needs VPoints and VLinks information.
        + If row is false: Create action.
        """
        super(EditPointDialog, self).__init__(parent)
        self.setupUi(self)
        flags = self.windowFlags()
        self.setWindowFlags(flags & ~Qt.WindowContextHelpButtonHint)
        icon = self.windowIcon()
        self.icon = QIcon(QPixmap(":/icons/link.png"))
        self.vpoints = vpoints
        self.vlinks = vlinks
        vpoints_count = len(vpoints)
        for i, e in enumerate(color_names):
            self.color_box.insertItem(i, color_icon(e), e)
        for vlink in vlinks:
            self.no_selected.addItem(QListWidgetItem(self.icon, vlink.name))
        if pos is False:
            self.name_box.addItem(icon, f'Point{vpoints_count}')
            self.name_box.setEnabled(False)
            self.color_box.setCurrentIndex(self.color_box.findText('green'))
        else:
            for i in range(vpoints_count):
                self.name_box.insertItem(i, icon, f'Point{i}')
            self.name_box.setCurrentIndex(pos)
        self.type_box.currentIndexChanged.connect(self.__check_angle)
        self.__check_angle()
예제 #3
0
 def edit_link(self, row: int, arg: LinkArgs):
     """Edit a link."""
     for i, e in enumerate(astuple(arg)):
         item = QTableWidgetItem(e)
         item.setFlags(Qt.ItemIsSelectable | Qt.ItemIsEnabled)
         if i == 1:
             item.setIcon(color_icon(e))
         self.setItem(row, i, item)
예제 #4
0
 def edit_point(self, row: int, arg: PointArgs) -> None:
     """Edit a point."""
     for i, e in enumerate((f'Point{row}', ) + astuple(arg) +
                           (f"({arg.x}, {arg.y})", )):
         item = QTableWidgetItem(str(e))
         item.setFlags(Qt.ItemIsSelectable | Qt.ItemIsEnabled)
         if i == 3:
             item.setIcon(color_icon(e))
         self.setItem(row, i, item)
예제 #5
0
    def __init__(
        self,
        vpoints: List[VPoint],
        vlinks: List[VLink],
        row: Union[int, bool],
        parent: QWidget
    ):
        """Input data reference from main window.

        + Needs VPoints and VLinks information.
        + If row is false: Create action.
        """
        super(EditLinkDialog, self).__init__(parent)
        self.setupUi(self)
        self.setWindowFlags(
            self.windowFlags()
            & ~Qt.WindowContextHelpButtonHint
        )
        self.vpoints = vpoints
        self.vlinks = vlinks
        icon = self.windowIcon()
        self.icon = QIcon(QPixmap(":/icons/bearing.png"))
        for i, e in enumerate(color_names):
            self.color_box.insertItem(i, color_icon(e), e)
        for i in range(len(self.vpoints)):
            self.no_selected.addItem(QListWidgetItem(self.icon, f'Point{i}'))
        if row is False:
            names = {vlink.name for vlink in self.vlinks}
            n = 1
            name = f"link_{n}"
            while name in names:
                n += 1
                name = f"link_{n}"
            self.name_edit.setText(name)
            self.name_box.setEnabled(False)
            self.name_box.addItem(icon, "New link")
            self.color_box.setCurrentIndex(self.color_box.findText('blue'))
        else:
            for i, vlink in enumerate(self.vlinks):
                self.name_box.insertItem(i, icon, vlink.name)
            self.name_box.setCurrentIndex(row)
        self.name_edit.textChanged.connect(self.__is_ok)
        self.__is_ok()
예제 #6
0
def add_custom_color(color_box: QComboBox, color: QColor):
    rgb_str = f"({color.red()}, {color.green()}, {color.blue()})"
    color_box.addItem(color_icon(rgb_str), rgb_str)
    color_box.setCurrentIndex(color_box.count() - 1)