示例#1
0
    def __init__(self, text, colors, color_caption):
        TestableWidget.__init__(self)
        self.setWindowFlags(Qt.Popup)

        main_layout = QVBoxLayout()
        main_layout.setContentsMargins(0, 0, 0, 0)
        border = "border: 1px solid #9b9b9b;"
        self.setStyleSheet('QFrame[frameShape="4"]{  color: #9b9b9b;}')

        # -- CAPTION ----------------------------------
        caption = QFrame(self, flags=Qt.WindowFlags())
        caption_layout = QHBoxLayout()
        self._lbl_caption = QLabel(text)
        self._lbl_caption.setStyleSheet("border: 0px solid blue;")
        caption_layout.addWidget(self._lbl_caption, alignment=Qt.Alignment())
        caption.setLayout(caption_layout)
        caption_layout.setContentsMargins(9, 5, 9, 5)
        caption.setStyleSheet(f"background-color: {color_caption}; {border}")

        # -- COLORS GRID ------------------------------
        colorbox = QFrame(self, flags=Qt.WindowFlags())
        color_layout = QGridLayout()
        colorbox.setLayout(color_layout)
        color_layout.setContentsMargins(9, 0, 9, 0)
        nn = 7
        self.clrbtn = []
        for i, color in enumerate(colors):
            self.clrbtn.append(QToolButton())
            css = (f"QToolButton {{{border}background-color:{color};}}"
                   f"QToolButton:hover {{border: 1px solid red; }}")
            self.clrbtn[-1].setStyleSheet(css)
            self.clrbtn[-1].clicked.connect(
                lambda x, c=color: self.select_color_(c))
            # noinspection PyArgumentList
            color_layout.addWidget(self.clrbtn[-1], i // nn, i % nn)

        # -- SPLITTER ---------------------------------
        h_frame = QFrame(None, flags=Qt.WindowFlags())
        h_frame.setFrameShape(QFrame.HLine)
        h_frame.setContentsMargins(0, 0, 0, 0)

        # -- BOTTOM (other color) ---------------------
        btns = QFrame(self, flags=Qt.WindowFlags())
        btn_layout = QHBoxLayout()
        other = QToolButton()
        other.clicked.connect(self.other_color_)
        other.setAutoRaise(True)
        other.setIcon(QIcon(img("editor/colorwheel")))
        btn_layout.addWidget(other, alignment=Qt.Alignment())
        self._lbl_other = QLabel(self.tr("other colors"))
        btn_layout.addWidget(self._lbl_other, alignment=Qt.Alignment())
        btns.setLayout(btn_layout)
        btn_layout.setContentsMargins(9, 0, 9, 9)
        self.clrbtn.append(other)

        # ---------------------------------------------
        main_layout.addWidget(caption, alignment=Qt.Alignment())
        main_layout.addWidget(colorbox, alignment=Qt.Alignment())
        main_layout.addWidget(h_frame, alignment=Qt.Alignment())
        main_layout.addWidget(btns, alignment=Qt.Alignment())

        self.setLayout(main_layout)
示例#2
0
文件: instable.py 项目: ligm74/LiGM
    def __init__(self, color_caption):
        TestableWidget.__init__(self)
        self.setWindowFlags(Qt.Popup)
        self._text = self.tr("Table")

        main_layout = QVBoxLayout()
        main_layout.setContentsMargins(0, 0, 0, 0)

        b = "border: 1px solid #9b9b9b;"
        self._styles = {
            "border": b,
            "border_blue": "border: 0px solid blue;",
            "selection": f"QToolButton {{{b}background-color:#fee5e2;}}",
            "white": f"QToolButton {{{b}background-color:white;}}",
            "frame": 'QFrame[frameShape="4"]{color: #9b9b9b;}'}

        self.setStyleSheet(self._styles["frame"])

        # -- CAPTION ----------------------------------
        caption = QFrame(self, flags=Qt.WindowFlags())
        caption_layout = QHBoxLayout()
        self._lbl_caption = QLabel(self._text)
        self._lbl_caption.setStyleSheet(self._styles["border_blue"])
        caption_layout.addWidget(self._lbl_caption, alignment=Qt.Alignment())
        caption.setLayout(caption_layout)
        caption_layout.setContentsMargins(9, 5, 9, 5)
        caption.setStyleSheet(
            f"background-color: {color_caption}; {self._styles['border']}")

        # -- CELLS GRID -------------------------------
        cellsbox = QFrame(self, flags=Qt.WindowFlags())
        cells = QGridLayout()
        cells.setSpacing(1)
        cellsbox.setLayout(cells)
        cells.setContentsMargins(9, 0, 9, 0)
        self._nn = 10
        self._clrbtn = []
        colors = ["white" for _ in range(self._nn ** 2)]
        cellsbox.leaveEvent = lambda x: self._leave_cell()
        for i, color in enumerate(colors):
            self._clrbtn.append(QToolButton())
            # noinspection PyPep8Naming
            self._clrbtn[-1].enterEvent = lambda x, n=i: self._enter_cell(n)
            self._clrbtn[-1].setStyleSheet(self._styles["white"])
            self._clrbtn[-1].clicked.connect(
                lambda x, n=i: self.select_size_(n))
            # noinspection PyArgumentList
            cells.addWidget(self._clrbtn[-1], i // self._nn, i % self._nn)

        # -- SPLITTER ---------------------------------
        h_frame = QFrame(None, flags=Qt.WindowFlags())
        h_frame.setFrameShape(QFrame.HLine)
        h_frame.setContentsMargins(0, 0, 0, 0)

        # -- BOTTOM (other color) ---------------------
        btns = QFrame(self, flags=Qt.WindowFlags())
        btn_layout = QHBoxLayout()
        other = QToolButton()
        other.clicked.connect(self.other_size_)
        other.setAutoRaise(True)
        other.setIcon(QIcon(img("editor/table_gray")))
        btn_layout.addWidget(other, alignment=Qt.Alignment())
        self._lbl_other = QLabel(self.tr("insert table"))
        btn_layout.addWidget(self._lbl_other, alignment=Qt.Alignment())
        btns.setLayout(btn_layout)
        btn_layout.setContentsMargins(9, 0, 9, 9)
        self._clrbtn.append(other)

        # ---------------------------------------------
        main_layout.addWidget(caption, alignment=Qt.Alignment())
        main_layout.addWidget(cellsbox, alignment=Qt.Alignment())
        main_layout.addWidget(h_frame, alignment=Qt.Alignment())
        main_layout.addWidget(btns, alignment=Qt.Alignment())

        self.setLayout(main_layout)