def __init__(self, *args, **kwargs):
        super(PaintScene, self).__init__(*args, **kwargs)

        # scene properties
        self.width = self.sceneRect().width()
        self.height = self.sceneRect().height()

        # stroke info
        self._strokes = {}
        self.next_stroke = 0
        self._current_path = None
        self._path_preview = None
        self._paint_layer = None
        self._is_painting = False

        # undo framework
        self.undo_stack = QtGui.QUndoStack(self)
        self.undo_view = QtGui.QUndoView(self.undo_stack)
        self.undo_view.setEmptyLabel(QtCore.QString('New'))

        # brush properites
        self.pen_size = 30
        self.pen_color = QtGui.QColor(255, 0, 0, 255)
        self.pen_blur = 0

        # scene ui styling
        border = QtGui.QPen()
        border.setWidthF(0.01)
        border.setColor(QtGui.QColor(128, 128, 128, 255))
        self.addRect(
            0, 0, self.width, self.height, border,
            QtGui.QBrush(QtGui.QColor(255, 255, 255, 255),
                         QtCore.Qt.SolidPattern))

        # cursor preview
        pen = QtGui.QPen(QtGui.QColor(0, 0, 0, 255), .5, QtCore.Qt.SolidLine,
                         QtCore.Qt.RoundCap, QtCore.Qt.RoundJoin)
        brush = QtGui.QBrush(QtGui.QColor(0, 0, 0, 0), QtCore.Qt.SolidPattern)
        self._cursor_outline = self.addEllipse(-15, -15, 30, 30, pen, brush)

        pen = QtGui.QPen(QtGui.QColor(255, 255, 255,
                                      0), 1, QtCore.Qt.SolidLine,
                         QtCore.Qt.RoundCap, QtCore.Qt.RoundJoin)
        brush = QtGui.QBrush(QtGui.QColor(255, 0, 0, 255),
                             QtCore.Qt.SolidPattern)
        self._cursor_fill = self.addEllipse(-15, -15, 30, 30, pen, brush)
        self._cursor_fill.setOpacity(.5)

        effect = QtGui.QGraphicsBlurEffect()
        effect.setBlurRadius(self.pen_blur)
        self._cursor_fill.setGraphicsEffect(effect)
        self._cursor_fill.setZValue(1000)
        self._cursor_outline.setZValue(1001)
Example #2
0
    def start_paintstroke(self, position, layer=None):
        """
        creates new QPath with appropriate brush settings

        Args:
            position (QPoint): start position of stroke
            layer (None, optional): index of target layer
        """
        if self.is_painting:
            if self.paintLayer == layer:
                self.update_paintstroke(position)
                return
            else:
                self.complete_paintstroke()

        self._current_path = QtGui.QGraphicsPathItem(QtGui.QPainterPath())
        pen = QtGui.QPen(self.pen_color, self.pen_size, QtCore.Qt.SolidLine,
                         QtCore.Qt.RoundCap, QtCore.Qt.RoundJoin)
        self._current_path.setPen(pen)
        path = QtGui.QPainterPath(position)
        self._current_path.setPath(path)

        # brush hardness
        effect = QtGui.QGraphicsBlurEffect()
        effect.setBlurRadius(self.pen_blur)
        self._current_path.setGraphicsEffect(effect)

        # draw preview
        # preview is temp version of stroke to display while drawing
        # preview is deleted when stroke is finalized
        pen = QtGui.QPen(self.pen_color, self.pen_size,
                         QtCore.Qt.SolidLine, QtCore.Qt.RoundCap,
                         QtCore.Qt.RoundJoin)
        self._path_preview = self.addPath(QtGui.QPainterPath(), pen)
        self._path_preview.setPath(path)
        preview_effect = QtGui.QGraphicsBlurEffect()
        preview_effect.setBlurRadius(self.pen_blur)
        self._path_preview.setGraphicsEffect(preview_effect)
        self._path_preview.setZValue(self.next_stroke + 1)
Example #3
0
 def _indicator(self, x, y, label, parent=None):
     indicator = QtGui.QFrame(parent)
     indicator.setGeometry(QtCore.QRect(x, y, 15, 10))
     indicator.setFrameStyle(QtGui.QFrame.Panel | QtGui.QFrame.Sunken)
     indicator.setLineWidth(1)
     indicator.setObjectName(_fromUtf8("frame"))
     #indicator.setStyleSheet("QFrame { background-color: rgb(100,140,100) }")
     if label:
         indicatorLabel = QLabel(parent)
         indicatorLabel.setText(label)
         indicatorLabel.setGeometry(x + 20, y, 60, 20)
     effect = QtGui.QGraphicsBlurEffect(indicator)
     effect.setBlurRadius(2)
     indicator.setGraphicsEffect(effect)
     return indicator
Example #4
0
    def updateSlide(self):
        for cell in self.items():
            if cell.isVisible():
                depth = cell.zValue()
                blur, sprite_depth = self.get_blur(depth, self.current_focus)

                #remove effect
                cell.setGraphicsEffect(None)

                if blur > 12:
                    blur = 12.0

                if blur > 1.5:
                    effect = QtGui.QGraphicsBlurEffect()
                    effect.setBlurRadius(blur)
                    cell.setGraphicsEffect(effect)

                cell.update()
Example #5
0
    def setupUi(self, MainWindow):
        MainWindow.setObjectName(_fromUtf8("MainWindow"))
        MainWindow.resize(410, 490)
        self.centralwidget = QtGui.QWidget(MainWindow)
        self.centralwidget.setObjectName(_fromUtf8("centralwidget"))

        self.emulationFrame = self._frame(5, 105, 400, 160, "emulation",
                                          self.centralwidget)
        self.emulationFrame.setEnabled(False)
        self.fileInUse = QtGui.QLineEdit(self.emulationFrame)
        self.fileInUse.setObjectName(_fromUtf8("file in use"))
        self.fileInUse.setGeometry(65, 30, 250, 25)
        self.edit_btn = self._button(230, 60, 45, 25, "edit",
                                     self.emulationFrame)
        self.browse_btn = self._button(275, 60, 45, 25, "...",
                                       self.emulationFrame)
        self.auto_open_checkbox = QtGui.QCheckBox("auto open file",
                                                  self.emulationFrame)
        self.auto_open_checkbox.setGeometry(62, 60, 20, 20)
        self.auto_open_label = QLabel(self.emulationFrame)
        self.auto_open_label.move(85, 62)
        self.auto_open_label.setText("auto open file")
        self.fileInUse.setFrame(1)
        self.fileInUse.setStyleSheet("background-color: rgb(245,255,255)")
        self.fileInUseLabel = QLabel(self.emulationFrame)
        self.fileInUseLabel.setText("File in use")
        self.fileInUseLabel.setGeometry(5, 32, 55, 20)
        self.read_sram_btn = self._button(20, 100, 70, 20, "read sram",
                                          self.emulationFrame)
        self.read_flash_btn = self._button(90, 100, 70, 20, "read flash",
                                           self.emulationFrame)
        self.emulation_btn = self._button(160, 100, 70, 20, "EMULATE",
                                          self.emulationFrame)
        self.write_flash_btn = self._button(230, 100, 110, 20,
                                            "STORE TO FLASH",
                                            self.emulationFrame)
        #self.load_flash_btn = self._button(300, 100, 70, 20, "load flash", self.emulationFrame)
        self.emulation_frame_blur_effect = QtGui.QGraphicsBlurEffect(
            self.emulationFrame)
        self.emulation_frame_blur_effect.setBlurRadius(2)
        self.emulationFrame.setGraphicsEffect(self.emulation_frame_blur_effect)
        self.progressBar = QtGui.QProgressBar(self.emulationFrame)
        self.progressBar.setGeometry(QtCore.QRect(20, 120, 370, 40))
        self.progressBar.setProperty("value", 0)
        self.progressBar.setObjectName(_fromUtf8("progressBar"))
        self.controlFrame = self._frame(5, 5, 200, 100, "control",
                                        self.centralwidget)
        self.connect_btn = self._button(10, 30, 70, 20, "connect",
                                        self.controlFrame)

        self.ping_btn = self._button(10, 50, 70, 20, "ping", self.controlFrame)
        QtCore.QObject.connect(self.ping_btn,
                               QtCore.SIGNAL(_fromUtf8("clicked()")),
                               MainWindow.ping_button_slot)

        self.flashBankFrame = self._frame(205, 5, 200, 100,
                                          "flash bank in use",
                                          self.centralwidget)
        self.flash_bank1_radio_btn = QtGui.QRadioButton(
            "bank1", self.flashBankFrame)
        self.flash_bank1_radio_btn.move(10, 32)
        self.flash_bank2_radio_btn = QtGui.QRadioButton(
            "bank2", self.flashBankFrame)
        self.flash_bank2_radio_btn.move(10, 52)
        self.flash_bank3_radio_btn = QtGui.QRadioButton(
            "bank3", self.flashBankFrame)
        self.flash_bank3_radio_btn.move(10, 72)
        self.lcd_flash_wear1 = QtGui.QLCDNumber(self.flashBankFrame)
        self.lcd_flash_wear1.setGeometry(75, 30, 80, 22)
        #self.lcd_flash_wear1.display("10000")
        self.lcd_flash_wear2 = QtGui.QLCDNumber(self.flashBankFrame)
        self.lcd_flash_wear2.setGeometry(75, 52, 80, 22)
        #self.lcd_flash_wear2.display("10000")
        self.lcd_flash_wear3 = QtGui.QLCDNumber(self.flashBankFrame)
        self.lcd_flash_wear3.setGeometry(75, 74, 80, 22)
        #self.lcd_flash_wear3.display("10000")
        self.connect_ind = Indicator(85, 36, '', self.controlFrame)
        self.connect_ind.active_color = "rgb(75, 252, 72)"
        self.ping_ind = Indicator(85, 56, '', self.controlFrame)
        self.ping_ind.active_color = "rgb(75, 252, 72)"
        self.rw_ind = Indicator(110, 36, '', self.controlFrame)
        self.rw_ind.active_color = "rgb(252, 255, 21)"

        self.widget = QtGui.QWidget(self.centralwidget)
        self.widget.setGeometry(QtCore.QRect(610, 480, 131, 61))
        self.widget.setObjectName(_fromUtf8("widget"))

        self.gridLayout = QtGui.QGridLayout(self.widget)
        self.gridLayout.setObjectName(_fromUtf8("gridLayout"))

        self.output = self._frame(5, 275, 400, 200, "console",
                                  self.centralwidget)

        self.main_output = QtGui.QTextBrowser(self.output)
        self.main_output.setObjectName(_fromUtf8("main_output"))
        self.main_output.setGeometry(5, 25, 390, 130)
        self.main_output.setStyleSheet("background-color: rgb(247,255,255)")
        self.main_output.setFontPointSize(8)

        self.cmdLine = QtGui.QLineEdit(self.output)
        self.cmdLine.setObjectName(_fromUtf8("cmd_line"))
        self.cmdLine.setGeometry(50, 160, 340, 25)
        self.cmdLine.setFrame(1)
        self.cmdLine.setStyleSheet("background-color: rgb(220,255,255)")
        self.cmdLabel = QLabel(self.output)
        self.cmdLabel.setText("CMD")
        self.cmdLabel.setGeometry(10, 163, 30, 20)

        MainWindow.setCentralWidget(self.centralwidget)
        self.menubar = QtGui.QMenuBar(MainWindow)
        self.menubar.setGeometry(QtCore.QRect(0, 0, 556, 29))
        self.menubar.setObjectName(_fromUtf8("menubar"))

        MainWindow.setMenuBar(self.menubar)
        self.statusbar = QtGui.QStatusBar(MainWindow)
        self.statusbar.setObjectName(_fromUtf8("statusbar"))
        MainWindow.setStatusBar(self.statusbar)
        #MainWindow.setStyleSheet("background-color: rgb(229,255,215)")

        self.retranslateUi(MainWindow)
        QtCore.QObject.connect(self.connect_btn,
                               QtCore.SIGNAL(_fromUtf8("clicked()")),
                               MainWindow.connect_button_slot)
        QtCore.QObject.connect(self.read_sram_btn,
                               QtCore.SIGNAL(_fromUtf8("clicked()")),
                               MainWindow.read_sram_btn_slot)
        QtCore.QObject.connect(self.read_flash_btn,
                               QtCore.SIGNAL(_fromUtf8("clicked()")),
                               MainWindow.read_flash_btn_slot)
        QtCore.QObject.connect(self.write_flash_btn,
                               QtCore.SIGNAL(_fromUtf8("clicked()")),
                               MainWindow.write_flash_btn_slot)
        QtCore.QObject.connect(self.emulation_btn,
                               QtCore.SIGNAL(_fromUtf8("clicked()")),
                               MainWindow.emulation_btn_slot)
        QtCore.QObject.connect(self.browse_btn,
                               QtCore.SIGNAL(_fromUtf8("clicked()")),
                               MainWindow.browse_button_slot)
        QtCore.QObject.connect(self.edit_btn,
                               QtCore.SIGNAL(_fromUtf8("clicked()")),
                               MainWindow.edit_button_slot)
        #QtCore.QObject.connect(self.load_flash_btn, QtCore.SIGNAL(_fromUtf8("clicked()")), MainWindow.emulation_btn_slot)
        QtCore.QObject.connect(self.flash_bank1_radio_btn,
                               QtCore.SIGNAL(_fromUtf8("clicked()")),
                               MainWindow.flash_bank_radio_btn_slot1)
        QtCore.QObject.connect(self.flash_bank2_radio_btn,
                               QtCore.SIGNAL(_fromUtf8("clicked()")),
                               MainWindow.flash_bank_radio_btn_slot2)
        QtCore.QObject.connect(self.flash_bank3_radio_btn,
                               QtCore.SIGNAL(_fromUtf8("clicked()")),
                               MainWindow.flash_bank_radio_btn_slot3)
        QtCore.QMetaObject.connectSlotsByName(MainWindow)
        MainWindow.setTabOrder(self.connect_btn, self.main_output)