Example #1
0
class PaletteWidget(QtGui.QWidget):
    """ widget containing palette """
    def __init__(self, project):
        QtGui.QWidget.__init__(self)
        self.project = project
        ### palette ###
        self.paletteCanvas = PaletteCanvas(self)
        self.paletteV = Viewer()
        self.paletteV.setHorizontalScrollBarPolicy(
            QtCore.Qt.ScrollBarAlwaysOff)
        self.paletteV.setVerticalScrollBarPolicy(QtCore.Qt.ScrollBarAlwaysOn)
        self.paletteV.setWidget(self.paletteCanvas)
        ### buttons ###
        self.project.updatePaletteSign.connect(self.paletteCanvas.update)
        addColorB = Button("add color", "icons/color_add.png", self.addColor)
        delColorB = Button("delete color", "icons/color_del.png",
                           self.delColor)
        moveLeftColorB = Button("move color left", "icons/color_move_left.png",
                                self.moveColorLeft)
        moveRightColorB = Button("move color right",
                                 "icons/color_move_right.png",
                                 self.moveColorRight)
        ### layout ###
        colorButtons = QtGui.QHBoxLayout()
        colorButtons.setSpacing(0)
        colorButtons.addWidget(addColorB)
        colorButtons.addWidget(delColorB)
        colorButtons.addWidget(moveLeftColorB)
        colorButtons.addWidget(moveRightColorB)
        self.layout = QtGui.QVBoxLayout()
        self.layout.setSpacing(0)
        self.layout.addWidget(self.paletteV)
        self.layout.addLayout(colorButtons)
        self.layout.setContentsMargins(6, 0, 6, 0)
        self.setLayout(self.layout)

    def showEvent(self, event):
        self.paletteV.setFixedWidth(self.paletteCanvas.width() +
                                    self.paletteV.verticalScrollBar().width() +
                                    2)

    def editColor(self, n):
        col = self.project.colorTable[self.project.color]
        ok, color = ColorDialog(False, col).getRgb()
        if not ok:
            return
        self.project.saveToUndo("colorTable")
        self.project.colorTable[n] = color
        for i in self.project.timeline.getAllCanvas():
            i.setColorTable(self.project.colorTable)
        self.project.updateViewSign.emit()
        self.paletteCanvas.update()
        self.project.colorChangedSign.emit()

    def addColor(self):
        """ choose a color and add it to the palette """
        if not len(self.project.colorTable) >= 256:
            col = self.project.colorTable[self.project.color]
            ok, color = ColorDialog(False, col).getRgb()
            if not ok:
                return
            self.project.saveToUndo("colorTable_frames")
            self.project.colorTable.append(color)
            self.project.changeColor(len(self.project.colorTable) - 1)
            for i in self.project.timeline.getAllCanvas():
                i.setColorTable(self.project.colorTable)
            self.project.updateViewSign.emit()

    def delColor(self):
        """ delete a color, replace with color 0 on canvas """
        col, table = self.project.color, self.project.colorTable
        if col != 0:
            self.project.saveToUndo("colorTable_frames")
            table.pop(col)
            for i in self.project.timeline.getAllCanvas():
                i.delColor(col)
                i.setColorTable(table)
            self.project.changeColor(col - 1)
            self.project.updateViewSign.emit()

    def moveColorLeft(self):
        col, table = self.project.color, self.project.colorTable
        if col != 0 and col != 1:
            self.project.saveToUndo("colorTable_frames")
            table[col], table[col - 1] = table[col - 1], table[col]
            for i in self.project.timeline.getAllCanvas():
                i.swapColor(col, col - 1)
                i.setColorTable(table)
            self.project.changeColor(col - 1)

    def moveColorRight(self):
        col, table = self.project.color, self.project.colorTable
        if col != len(table) - 1 and col != 0:
            self.project.saveToUndo("colorTable_frames")
            table[col], table[col + 1] = table[col + 1], table[col]
            for i in self.project.timeline.getAllCanvas():
                i.swapColor(col, col + 1)
                i.setColorTable(table)
            self.project.changeColor(col + 1)
Example #2
0
class PaletteWidget(QtGui.QWidget):
    """ widget containing palette """
    def __init__(self, project):
        QtGui.QWidget.__init__(self)
        self.project = project
        ### palette ###
        self.paletteCanvas = PaletteCanvas(self)
        self.paletteV = Viewer()
        self.paletteV.setHorizontalScrollBarPolicy(QtCore.Qt.ScrollBarAlwaysOff)
        self.paletteV.setVerticalScrollBarPolicy(QtCore.Qt.ScrollBarAlwaysOn)
        self.paletteV.setWidget(self.paletteCanvas)
        ### buttons ###
        self.project.updatePaletteSign.connect(self.paletteCanvas.update)
        addColorB = Button("add color", "icons/color_add.png", self.addColor)
        delColorB = Button("delete color", "icons/color_del.png", self.delColor)
        moveLeftColorB = Button("move color left", "icons/color_move_left.png", self.moveColorLeft)
        moveRightColorB = Button("move color right", "icons/color_move_right.png", self.moveColorRight)
        ### layout ###
        colorButtons = QtGui.QHBoxLayout()
        colorButtons.setSpacing(0)
        colorButtons.addWidget(addColorB)
        colorButtons.addWidget(delColorB)
        colorButtons.addWidget(moveLeftColorB)
        colorButtons.addWidget(moveRightColorB)
        self.layout = QtGui.QVBoxLayout()
        self.layout.setSpacing(0)
        self.layout.addWidget(self.paletteV)
        self.layout.addLayout(colorButtons)
        self.layout.setContentsMargins(6, 0, 6, 0)
        self.setLayout(self.layout)

    def showEvent(self, event):
        self.paletteV.setFixedWidth(self.paletteCanvas.width() + 
                    self.paletteV.verticalScrollBar().width() + 2)

    def editColor(self, n):
        col = self.project.colorTable[self.project.color]
        ok, color = ColorDialog(False, col).getRgb()
        if not ok:
            return
        self.project.saveToUndo("colorTable")
        self.project.colorTable[n] = color
        for i in self.project.timeline.getAllCanvas():
            i.setColorTable(self.project.colorTable)
        self.project.updateViewSign.emit()
        self.paletteCanvas.update()
        self.project.colorChangedSign.emit()

    def addColor(self):
        """ choose a color and add it to the palette """
        if not len(self.project.colorTable) >= 256:
            col = self.project.colorTable[self.project.color]
            ok, color = ColorDialog(False, col).getRgb()
            if not ok:
                return
            self.project.saveToUndo("colorTable_frames")
            self.project.colorTable.append(color)
            self.project.changeColor(len(self.project.colorTable)-1)
            for i in self.project.timeline.getAllCanvas():
                i.setColorTable(self.project.colorTable)
            self.project.updateViewSign.emit()

    def delColor(self):
        """ delete a color, replace with color 0 on canvas """
        col, table = self.project.color, self.project.colorTable
        if col != 0:
            self.project.saveToUndo("colorTable_frames")
            table.pop(col)
            for i in self.project.timeline.getAllCanvas():
                i.delColor(col)
                i.setColorTable(table)
            self.project.changeColor(col-1)
            self.project.updateViewSign.emit()

    def moveColorLeft(self):
        col, table = self.project.color, self.project.colorTable
        if col != 0 and col != 1:
            self.project.saveToUndo("colorTable_frames")
            table[col], table[col-1] = table[col-1], table[col]
            for i in self.project.timeline.getAllCanvas():
                i.swapColor(col, col-1)
                i.setColorTable(table)
            self.project.changeColor(col-1)

    def moveColorRight(self):
        col, table = self.project.color, self.project.colorTable
        if col != len(table)-1 and col != 0:
            self.project.saveToUndo("colorTable_frames")
            table[col], table[col+1] = table[col+1], table[col]
            for i in self.project.timeline.getAllCanvas():
                i.swapColor(col, col+1)
                i.setColorTable(table)
            self.project.changeColor(col+1)
Example #3
0
class PaletteWidget(QWidget):
    """ side widget containing palette """

    def __init__(self, project):
        QWidget.__init__(self)
        self.project = project

        self.setContextMenuPolicy(Qt.ActionsContextMenu)
        ### context menu ###
        newAction = QAction("New", self)
        self.addAction(newAction)
        mergeAction = QAction("Merge", self)
        self.addAction(mergeAction)
        deleteAction = QAction("Delete", self)
        self.addAction(deleteAction)
        cutAction = QAction("Cut", self)
        self.addAction(cutAction)
        copyAction = QAction("Copy", self)
        self.addAction(copyAction)
        pasteAction = QAction("Paste", self)
        self.addAction(pasteAction)
        lockAction = QAction("Lock", self)
        lockAction.setCheckable(True)
        self.addAction(lockAction)

        ### palette ###
        self.paletteCanvas = PaletteCanvas(self)
        self.paletteV = Viewer()
        self.paletteV.setHorizontalScrollBarPolicy(Qt.ScrollBarAlwaysOff)
        self.paletteV.setVerticalScrollBarPolicy(Qt.ScrollBarAlwaysOn)
        self.paletteV.setWidget(self.paletteCanvas)

        self.project.updatePaletteSign.connect(self.paletteCanvas.update)
        addColorB = Button("add color",
                           "icons/color_add.png", self.addColor)
        delColorB = Button("delete color",
                           "icons/color_del.png", self.delColor)

        ### Layout ###
        colorButtons = QHBoxLayout()
        colorButtons.setSpacing(0)
        colorButtons.addWidget(addColorB)
        colorButtons.addWidget(delColorB)
        paintOption = QHBoxLayout()
        paintOption.setSpacing(0)
        paintOption.addStretch()
        layout = QGridLayout()
        layout.setSpacing(0)
        layout.addLayout(paintOption, 1, 1)
        layout.addWidget(self.paletteV, 2, 1)
        layout.addLayout(colorButtons, 3, 1)
        layout.setContentsMargins(6, 0, 6, 0)
        self.setLayout(layout)

    def showEvent(self, event):
        self.paletteV.setFixedWidth(self.paletteCanvas.width() +
                                    self.paletteV.verticalScrollBar().width() + 2)

    ######## Color #####################################################
    def updateColorTable(self):
        for i in self.project.timeline.getAllCanvas():
            i.setColorTable(self.project.colorTable)
        self.project.updateViewSign.emit()
        self.paletteCanvas.update()
        self.project.colorChanged.emit()

    def colorDialog(self):
        current = self.project.colorTable[self.project.color]
        return QColorDialog.getColor(QColor(current), self)

    def editColor(self, n):
        color = self.colorDialog()
        if not color.isValid():
            return
        self.project.saveToUndo("colorTable")
        self.project.colorTable[n] = color.rgba()
        self.updateColorTable()

    def addColor(self):
        """ select a color and add it to the palette"""
        if not len(self.project.colorTable) >= 256:
            color = self.colorDialog()
            if not color.isValid():
                return
            self.project.saveToUndo("colorTable_frames")
            self.project.colorTable.append(color)
            self.project.setColorIndex(len(self.project.colorTable) - 1)
            for i in self.project.timeline.getAllCanvas():
                i.setColorTable(self.project.colorTable)
            self.project.updateViewSign.emit()

    def delColor(self):
        col, table = self.project.color, self.project.colorTable
        if col != 0:
            self.project.saveToUndo("colorTable_frames")
            table.pop(col)
            for i in self.project.timeline.getAllCanvas():
                i.delColor(col)
                i.setColorTable(table)
            self.project.setColorIndex(col - 1)
            self.project.updateViewSign.emit()