Exemplo n.º 1
0
    def initToolLayout(self):
        bx, by = self.buttonScale
        bC = self.buttonCol
        blankSize = self.blankSize
        self.toolWidgets = []

        for line in config.toolTexts:
            tempLine = []
            for tool in line:
                tempTool = []
                if not isinstance(tool, list):
                    tool = [tool]
                n = len(tool)
                for command in tool:
                    if command[0] == '#':
                        continue
                    elif command == '*':
                        tempLine.append(None)
                    elif command[-1] == '-':
                        command = command[:-1]
                        temp = MySlider(self, command, Qt.Horizontal)
                        self.setSlider(temp, command)
                        temp.setTickPosition(QSlider.TicksBothSides)
                        lef, rig, typ = config.sliderConfig[command]
                        temp.setSliderType(lef, rig, type=typ)
                        temp.setFixedSize(
                            QSize(bx * 3 + config.defaultBlank * 2, by))
                        self.setSlider(temp, command)

                        tempTool.append(temp)
                    elif command[-1] == '=':
                        command = command[:-1]
                        buttonGroup = MyButtonGroup(self, command)
                        subCommands = command.split('&')
                        id = 0
                        for subCommand in subCommands:
                            temp = MyRadioButton(self, subCommand)
                            buttonGroup.addRadioButton(temp, id)
                            tempTool.append(temp)
                            id += 1
                        self.setButtonGroup(buttonGroup, command)

                    else:
                        temp = MyPushButton(self, config.getText(command),
                                            command)
                        temp.setFixedSize(
                            QSize(bx,
                                  (by - config.defaultBlank * (n - 1)) // n))
                        tempTool.append(temp)

                if len(tempTool) > 0:
                    tempLine.append(tempTool)
            if len(tempLine) > 0:
                self.toolWidgets.append(tempLine)

        self.toolLayout = QVBoxLayout()
        self.toolLayout.setAlignment(Qt.AlignTop)
        for line in self.toolWidgets:
            bR = (len(line) - 1) // bC + 1

            for row in range(bR):
                lineLayout = QHBoxLayout()
                lineLayout.setAlignment(Qt.AlignLeft)

                for tool in line[row * bC:(row + 1) * bC]:
                    if tool is not None:
                        singleToolLayout = QVBoxLayout()
                        for obj in tool:
                            if obj is not None:
                                singleToolLayout.addWidget(obj)
                        lineLayout.addLayout(singleToolLayout)
                self.toolLayout.addLayout(lineLayout)
                addBlankToLayout(self.toolLayout, blankSize[0])

            addBlankToLayout(self.toolLayout, blankSize[1])
Exemplo n.º 2
0
    def initImageLayout(self):
        imgx, imgy = self.scale
        self.texts = []
        for i in range(2):
            text = ClickLabel(self, i, "None")
            text.setAlignment(Qt.AlignTop)
            text.setFixedSize(QSize(imgx, imgy))
            self.texts.append(text)

        # for i, f in enumerate(self.functions):
        #     text = ClickLabel(self, i + 3, "")
        #     text.setAlignment(Qt.AlignTop)
        #     text.setFixedSize(QSize(imgx, imgy))
        #     self.texts.append(text)

        text = ClickLabel(self, -1, "")
        text.setAlignment(Qt.AlignTop)
        text.setFixedSize(QSize(imgx, imgy))
        self.texts.append(text)

        # self.newSet()

        texts = self.texts[:3] + self.texts[-1:]

        # row = config.imgRow
        row = 1
        col = (len(texts) + row - 1) // row

        self.imageLayout = QHBoxLayout()
        self.imageLayout.addStretch(1)

        self.imageLayoutLeft = QVBoxLayout()
        self.imageLayoutLeft.setAlignment(Qt.AlignCenter)
        # self.imageLayoutLeft.addStretch()

        self.imageLayoutRight = QHBoxLayout()
        self.imageLayoutRight.addStretch()

        for i in range(row):
            rowLayout = QHBoxLayout()
            rowLayout.addStretch(1)
            for j in texts[i * col:(i + 1) * col]:
                rowLayout.addWidget(j)
                rowLayout.setAlignment(Qt.AlignCenter)
                rowLayout.addStretch()
                rowLayout.setContentsMargins(20, 20, 20, 20)
                self.imageLayoutRight.addLayout(rowLayout)

        bx, by = self.buttonScale
        temp = MySlider(self, 'ImageAlphaSlider', Qt.Vertical)
        self.setSlider(temp, 'ImageAlphaSlider')
        temp.setTickPosition(QSlider.TicksBothSides)
        lef, rig, typ = config.sliderConfig['ImageAlphaSlider']
        temp.setSliderType(lef, rig, type=typ)
        temp.setFixedSize(QSize(100, 300))
        # self.setSlider(temp, 'ImageAlphaSlider')

        temp_top = MyPushButton(self, config.getText('Top'), 'Top')
        temp_top.setFixedSize(
            QSize(bx, (by - config.defaultBlank * (1 - 1)) // 1))
        temp_bottom = MyPushButton(self, config.getText('Bottom'), 'Bottom')
        temp_bottom.setFixedSize(
            QSize(bx, (by - config.defaultBlank * (1 - 1)) // 1))

        self.imageLayoutLeft.addWidget(temp_top)
        self.imageLayoutLeft.addWidget(temp)
        self.imageLayoutLeft.addWidget(temp_bottom)

        self.imageLayout.addLayout(self.imageLayoutLeft)
        self.imageLayout.addLayout(self.imageLayoutRight)
Exemplo n.º 3
0
    def initToolLeftGridLayout(self):
        bx, by = self.buttonScale
        bC = self.buttonCol
        blankSize = self.blankSize

        self.toolLeftGridGroupBox = QGroupBox()
        layout = QGridLayout()

        # Foreground Background Unknown
        buttonGroup = MyButtonGroup(self, "Foreground&Background&Unknown")
        self.colorBox = QGroupBox()
        colorLayout = QVBoxLayout()
        foregroundRadio = MyColorButton(self, "Foreground")
        foregroundRadio.setIcon(QIcon("icon/icon_1.png"))
        foregroundRadio.setShortcut("1")
        colorLayout.addWidget(foregroundRadio)
        buttonGroup.addRadioButton(foregroundRadio, 0)

        backgroundRadio = MyColorButton(self, "Background")
        backgroundRadio.setIcon(QIcon("icon/icon_2.png"))
        backgroundRadio.setShortcut("2")
        colorLayout.addWidget(backgroundRadio)
        buttonGroup.addRadioButton(backgroundRadio, 1)

        unknownRadio = MyColorButton(self, "Unknown")
        unknownRadio.setIcon(QIcon("icon/icon_3.png"))
        unknownRadio.setShortcut("3")
        colorLayout.addWidget(unknownRadio)
        buttonGroup.addRadioButton(unknownRadio, 2)
        self.colorBox.setLayout(colorLayout)
        # ~~~~~

        buttonGroup2 = MyButtonGroup(self, "Pen&Filler")
        self.colorBox2 = QGroupBox()
        colorLayout = QVBoxLayout()
        penRadio = MyToolButton(self, "画笔 (Q)")
        penRadio.setIcon(QIcon("icons/brush.png"))
        penRadio.setShortcut("q")
        colorLayout.addWidget(penRadio)
        buttonGroup2.addRadioButton(penRadio, 0)

        fillerRadio = MyToolButton(self, "填充 (W)")
        fillerRadio.setIcon(QIcon("icons/filler.png"))
        fillerRadio.setShortcut("w")
        colorLayout.addWidget(fillerRadio)
        buttonGroup2.addRadioButton(fillerRadio, 1)
        self.colorBox2.setLayout(colorLayout)
        # ~~~~~
        # drawButtonGroup = MyButtonGroup(self, "Pen&Filler")
        # self.toolBox = QGroupBox()
        # colorLayout = QVBoxLayout()
        # penRadio = MyColorButton(self, "Pen")
        # foregroundRadio.setIcon(QIcon("icon/icon_1.png"))
        # colorLayout.addWidget(foregroundRadio)
        # buttonGroup.addRadioButton(foregroundRadio, 0)

        # fillerRadio = MyColorButton(self, "Filler")
        # backgroundRadio.setIcon(QIcon("icon/icon_2.png"))
        # colorLayout.addWidget(backgroundRadio)
        # buttonGroup.addRadioButton(backgroundRadio, 1)

        # pen
        penButton = MyPushButton(self, config.getText("Pen"), "Pen")
        penButton.setFixedSize(QSize(80, 40))
        # pen slider
        penSlider = MySlider(self, "PenSlider", Qt.Horizontal)
        self.setSlider(penSlider, "PenSlider")
        penSlider.setTickPosition(QSlider.TicksBothSides)
        lef, rig, typ = config.sliderConfig["PenSlider"]
        penSlider.setSliderType(lef, rig, type=typ)
        penSlider.setFixedSize(QSize(bx * 3 + config.defaultBlank * 2, by))
        self.setSlider(penSlider, "PenSlider")

        # filler
        fillerButton = MyPushButton(self, config.getText("Filler"), "Filler")
        fillerButton.setFixedSize(QSize(80, 40))
        # filler slider
        fillerSlider = MySlider(self, "FillerSlider", Qt.Horizontal)
        self.setSlider(fillerSlider, "FillerSlider")
        fillerSlider.setTickPosition(QSlider.TicksBothSides)
        lef, rig, typ = config.sliderConfig["FillerSlider"]
        fillerSlider.setSliderType(lef, rig, type=typ)
        fillerSlider.setFixedSize(QSize(bx * 3 + config.defaultBlank * 2, by))
        self.setSlider(fillerSlider, "FillerSlider")

        # clean trimap
        cleantrimapButton = MyPushButton(self,
                                         config.getText("SolveForeground"),
                                         "SolveForeground")
        cleantrimapButton.setIcon(QIcon("icons/clearscreen.png"))
        # cleanShortut = QShortcut(QKeySequence("Ctrl+C"), self)
        # cleanShortcut.activated.connect(self.clear)
        undoButton = MyPushButton(self, config.getText("Undo"), "Undo")
        undoButton.setIcon(QIcon("icons/undo.png"))
        # undoButton.setShortcut("Ctrl+Z")
        undoShortcut = QShortcut(QKeySequence("Ctrl+Z"), self)
        undoShortcut.activated.connect(self.undo)
        redoButton = MyPushButton(self, config.getText("Redo"), "Redo")
        redoButton.setIcon(QIcon("icons/redo.png"))
        # redoButton.setShortcut("Ctrl+Y")
        redoShortcut = QShortcut(QKeySequence("Ctrl+Y"), self)
        redoShortcut.activated.connect(self.redo)

        # cleantrimapButton.setFixedSize(QSize(80,40))

        fileUnknownButton = MyPushButton(self, config.getText("FillUnknown"),
                                         "FillUnknown")
        unknownUpButton = MyPushButton(self, config.getText("UnknownUp"),
                                       "UnknownUp")
        unknownDownButton = MyPushButton(self, config.getText("UnknownDown"),
                                         "UnknownDown")
        # fileUnknownButton.setFixedSize(QSize(self.width(),40))
        #fileUnknownButton.setFixedHeight(60)
        # unknownUpButton.setFixedHeight(40)
        # unknownUpButton.setFixedSize(QSize(self.width(),40))

        runButton = MyPushButton(self, config.getText("Run"), "Run")
        # runShortcut = QShortcut(QKeySequence("Ctrl+R"), self)
        # runShortcut.activated.connect(self.run)
        runButton.setFixedHeight(60)
        runButton.setStyleSheet("QPushButton{color:white;font-size:18px;}"
                                "QPushButton:hover{background-color:#05f}"
                                "QPushButton{background-color:#477be4}"
                                "QPushButton{border:2px}"
                                "QPushButton{border-radius:10px}"
                                "QPushButton{padding:2px 4px}")
        # runButton.setShortcut("Ctrl+R")
        penSlider.setStyleSheet("QSlider{padding:0px 0px}")
        layout.setSpacing(0)
        layout.addWidget(self.colorBox, 0, 0, 2, 1)
        layout.addWidget(self.colorBox2, 0, 1, 2, 1)

        # layout.addWidget(penButton, 0, 1)
        layout.addWidget(penSlider, 0, 2, 1, 4)
        # layout.addWidget(fillerButton, 1, 1)
        layout.addWidget(fillerSlider, 1, 2, 1, 4)
        layout.addWidget(cleantrimapButton, 2, 0)
        layout.addWidget(undoButton, 2, 1)
        layout.addWidget(redoButton, 2, 2)
        layout.addWidget(fileUnknownButton, 3, 0, 2, 1)
        layout.addWidget(unknownUpButton, 3, 1)
        layout.addWidget(unknownDownButton, 3, 2)
        layout.addWidget(runButton, 2, 4, 2, 2)
        self.toolLeftGridGroupBox.setLayout(layout)
Exemplo n.º 4
0
    def initToolRightGridLayout(self):
        bx, by = self.buttonScale
        bC = self.buttonCol
        blankSize = self.blankSize

        self.toolWidgets = []

        self.toolRightGridGroupBox = QGroupBox()
        self.toolRightGridGroupBox.setFixedWidth(400)
        layout = QGridLayout()

        # Foreground Background Unknown
        buttonGroup = MyButtonGroup(self, "Grid&Red&Green&Blue")
        self.colorBox = QGroupBox()
        colorLayout = QHBoxLayout()
        GridRadio = MyColorButton(self, "Grid")
        GridRadio.setIcon(QIcon(QPixmap("iconss/grid.png")))
        colorLayout.addWidget(GridRadio)
        buttonGroup.addRadioButton(GridRadio, 0)

        redRadio = MyColorButton(self, "Red")
        redRadio.setIcon(QIcon(QPixmap("iconss/red.png")))
        colorLayout.addWidget(redRadio)
        buttonGroup.addRadioButton(redRadio, 1)

        greenRadio = MyColorButton(self, "Green")
        greenRadio.setIcon(QIcon(QPixmap("iconss/green.png")))
        colorLayout.addWidget(greenRadio)
        buttonGroup.addRadioButton(greenRadio, 2)

        blueRadio = MyColorButton(self, "Blue")
        blueRadio.setIcon(QIcon(QPixmap("iconss/blue.png")))
        colorLayout.addWidget(blueRadio)
        self.colorBox.setLayout(colorLayout)
        buttonGroup.addRadioButton(blueRadio, 3)

        # Previous
        previousButton = MyPushButton(self, config.getText("Previous"),
                                      "Previous")
        # Next
        nextButton = MyPushButton(self, config.getText("Submit"), "Submit")
        # Abandon
        abandonButton = MyPushButton(self, config.getText("Abandon"),
                                     "Abandon")

        # clean trimap
        # openButton = QPushButton("Open")
        # openButton = MyPushButton(self, config.getText("Open"), "Open")
        openButton = MyPushButton(self, config.getText("Open"), "Open")
        # saveButton = MyPushButton(self, config.getText("SaveAlpha"), "SaveAlpha")
        previousButton.setFixedHeight(40)
        nextButton.setFixedHeight(40)
        abandonButton.setFixedHeight(40)
        openButton.setFixedHeight(40)
        # saveButton.setFixedHeight(60)
        openButton.setStyleSheet("QPushButton{color:white;font-size:18px;}"
                                 "QPushButton:hover{background-color:#008000}"
                                 "QPushButton{background-color:#008000}"
                                 "QPushButton{border:2px}"
                                 "QPushButton{border-radius:4px}"
                                 "QPushButton{padding:2px 4px}")
        previousButton.setStyleSheet(
            "QPushButton{color:#444;font-size:18px;}"
            "QPushButton:hover{background-color:#b7b7b7}"
            "QPushButton{background-color:#e7e7e7;border-color: #b7b7b7;}"
            "QPushButton{border:1px solid transparent;}"
            "QPushButton{border-radius:4px}"
            "QPushButton{padding:2px 4px}")
        nextButton.setStyleSheet(
            "QPushButton{color:#fff;font-size:18px;}"
            "QPushButton:hover{background-color:#337ab7;border-color: #2e6da4;}"
            "QPushButton{background-color:#3c8dbc;border-color: #367fa9;}"
            "QPushButton{border:1px solid transparent;}"
            "QPushButton{border-radius:4px}"
            "QPushButton{padding:2px 4px}")
        abandonButton.setStyleSheet(
            "QPushButton{color:white;font-size:18px;}"
            "QPushButton:hover{background-color:#B22222}"
            "QPushButton{background-color:#B22222;}"
            "QPushButton{border:2px}"
            "QPushButton{border-radius:4px}"
            "QPushButton{padding:2px 4px}")
        # previousButton.setShortcut("Ctrl+D")
        # nextButton.setShortcut("Ctrl+S")
        # abandonButton.setShortcut("Ctrl+A")

        # layout.setSpacing(10)
        layout.addWidget(self.colorBox, 0, 0, 1, 2)
        # layout.addWidget(previousButton, 1, 1)
        # layout.addWidget(nextButton, 1, 2)
        # layout.addWidget(abandonButton, 1, 3)
        layout.addWidget(openButton, 1, 0)
        layout.addWidget(previousButton, 1, 1)
        layout.addWidget(nextButton, 2, 0)
        layout.addWidget(abandonButton, 2, 1)
        self.toolRightGridGroupBox.setLayout(layout)
Exemplo n.º 5
0
    def initToolLayout(self):
        bx, by = self.buttonScale
        bC = self.buttonCol
        blankSize = self.blankSize
        self.toolWidgets = []

        self.toolLayout = QHBoxLayout()
        self.toolLayout.addStretch(1)

        self.toolLayoutLeft = QVBoxLayout()
        self.toolLayoutLeft.setMargin(10)
        # self.toolLayoutLeft.addStretch(1)

        self.toolLayoutRight = QVBoxLayout()
        self.toolLayoutRight.setMargin(10)
        self.toolLayoutRight.addStretch(1)

        for line in config.toolTexts:
            tempLine = []
            for tool in line:
                tempTool = []
                if not isinstance(tool, list):
                    tool = [tool]
                n = len(tool)
                for command in tool:
                    if command[0] == '#':
                        continue
                    elif command == '*':
                        tempLine.append(None)
                    elif command[-1] == '-':
                        command = command[:-1]
                        temp = MySlider(self, command, Qt.Horizontal)
                        self.setSlider(temp, command)
                        temp.setTickPosition(QSlider.TicksBothSides)
                        lef, rig, typ = config.sliderConfig[command]
                        temp.setSliderType(lef, rig, type=typ)
                        temp.setFixedSize(
                            QSize(bx * 3 + config.defaultBlank * 2, by))
                        self.setSlider(temp, command)

                        tempTool.append(temp)
                    elif command[-1] == '=':
                        command = command[:-1]
                        buttonGroup = MyButtonGroup(self, command)
                        subCommands = command.split('&')
                        id = 0
                        for subCommand in subCommands:
                            temp = MyColorButton(self, subCommand)
                            if subCommand == "Foreground":
                                temp.setIcon(QIcon("icon/icon_1.png"))
                            elif subCommand == "Background":
                                temp.setIcon(QIcon("icon/icon_2.png"))
                            elif subCommand == "Unknown":
                                temp.setIcon(QIcon("icon/icon_3.png"))
                            buttonGroup.addRadioButton(temp, id)
                            tempTool.append(temp)
                            id += 1
                        self.setButtonGroup(buttonGroup, command)

                    else:
                        temp = MyPushButton(self, config.getText(command),
                                            command)
                        temp.setFixedSize(
                            QSize(bx,
                                  (by - config.defaultBlank * (n - 1)) // n))
                        tempTool.append(temp)

                if len(tempTool) > 0:
                    tempLine.append(tempTool)
            if len(tempLine) > 0:
                self.toolWidgets.append(tempLine)