Exemplo n.º 1
0
def generateNodes(count, offset, depth):
    for i in range(count):
        node1 = Node(graph, 'node' + str(depth) + str(i))
        node1.addPort(
            InputPort(node1, graph, 'InPort', QtGui.QColor(128, 170, 170, 255),
                      'MyDataX'))
        node1.addPort(
            OutputPort(node1, graph, 'OutPort', QtGui.QColor(32, 255, 32, 255),
                       'MyDataX'))
        node1.setGraphPos(QtCore.QPointF(offset, i * 80))

        graph.addNode(node1)

        global totalCount
        totalCount += 1

    if depth < 6:
        generateNodes(count * 2, offset + 160, depth + 1)

        for i in range(count):
            graph.connectPorts('node' + str(depth) + str(i), 'OutPort',
                               'node' + str(depth + 1) + str(i * 2), 'InPort')
            graph.connectPorts('node' + str(depth) + str(i), 'OutPort',
                               'node' + str(depth + 1) + str(i * 2 + 1),
                               'InPort')
    elif depth < 12:
        generateNodes(int(count / 2), offset + 160, depth + 1)

        for i in range(count / 2):
            graph.connectPorts('node' + str(depth) + str(i), 'OutPort',
                               'node' + str(depth + 1) + str(int(i)), 'InPort')
Exemplo n.º 2
0
    def dragObject(self):

        if not self.selectedIndexes():
            return

        item = self.selectedItems()[0]
        role = item.data(0, QtCore.Qt.UserRole)

        if role == 'Folder':
            return

        text = 'KrakenComponent:' + role

        mimeData = QtCore.QMimeData()
        mimeData.setText(text)

        drag = QtGui.QDrag(self)
        drag.setMimeData(mimeData)
        drag.setHotSpot(QtCore.QPoint(90, 23))

        ghostComponent = QtGui.QPixmap(180, 46)
        ghostComponent.fill(QtGui.QColor(67, 143, 153, 80))

        drag.setPixmap(ghostComponent)
        drag.start(QtCore.Qt.IgnoreAction)
Exemplo n.º 3
0
class SelectionRect(QtWidgets.QGraphicsWidget):
    __backgroundColor = QtGui.QColor(100, 100, 100, 50)
    __pen = QtGui.QPen(QtGui.QColor(25, 25, 25), 1.0, QtCore.Qt.DashLine)

    def __init__(self, graph, mouseDownPos):
        super(SelectionRect, self).__init__()
        self.setZValue(-1)

        self.__graph = graph
        self.__graph.scene().addItem(self)
        self.__mouseDownPos = mouseDownPos
        self.setPos(self.__mouseDownPos)
        self.resize(0, 0)

    def setDragPoint(self, dragPoint):
        topLeft = QtCore.QPointF(self.__mouseDownPos)
        bottomRight = QtCore.QPointF(dragPoint)
        if dragPoint.x() < self.__mouseDownPos.x():
            topLeft.setX(dragPoint.x())
            bottomRight.setX(self.__mouseDownPos.x())
        if dragPoint.y() < self.__mouseDownPos.y():
            topLeft.setY(dragPoint.y())
            bottomRight.setY(self.__mouseDownPos.y())
        self.setPos(topLeft)
        self.resize(bottomRight.x() - topLeft.x(),
                    bottomRight.y() - topLeft.y())

    def paint(self, painter, option, widget):
        rect = self.windowFrameRect()
        painter.setBrush(self.__backgroundColor)
        painter.setPen(self.__pen)
        painter.drawRect(rect)

    def destroy(self):
        self.__graph.scene().removeItem(self)
Exemplo n.º 4
0
    def paint(self, painter, option, widget):
        rect = self.windowFrameRect()
        painter.setBrush(self.__color)

        painter.setPen(QtGui.QPen(QtGui.QColor(0, 0, 0, 0), 0))

        roundingY = 10
        roundingX = rect.height() / rect.width() * roundingY

        painter.drawRoundRect(rect, roundingX, roundingY)

        # Title BG
        titleHeight = self.__headerItem.size().height() - 3

        painter.setBrush(self.__color.darker(125))
        roundingY = rect.width() * roundingX / titleHeight
        painter.drawRoundRect(0, 0, rect.width(), titleHeight, roundingX, roundingY)
        painter.drawRect(0, titleHeight * 0.5 + 2, rect.width(), titleHeight * 0.5)

        # painter.setPen(self.__linePen)
        # painter.drawLine(QtCore.QPoint(0, titleHeight), QtCore.QPoint(rect.width(), titleHeight))

        painter.setBrush(QtGui.QColor(0, 0, 0, 0))
        if self.__selected:
            painter.setPen(self.__selectedPen)
        else:
            painter.setPen(self.__unselectedPen)

        roundingY = 10
        roundingX = rect.height() / rect.width() * roundingY

        painter.drawRoundRect(rect, roundingX, roundingY)
Exemplo n.º 5
0
    def __init__(self, port, graph, hOffset, color, connectionPointType):
        super(KNodePortCircle, self).__init__(port, graph, hOffset, color,
                                              connectionPointType)

        if self.getPort().getDataType().endswith('[]'):
            self.setDefaultPen(QtGui.QPen(QtGui.QColor(204, 0, 0), 1.5))
            self.setHoverPen(QtGui.QPen(QtGui.QColor(255, 155, 100), 2.0))
Exemplo n.º 6
0
class NodeTitle(QtWidgets.QGraphicsWidget):

    __color = QtGui.QColor(25, 25, 25)
    __font = QtGui.QFont('Decorative', 14)
    __font.setLetterSpacing(QtGui.QFont.PercentageSpacing, 115)
    __labelBottomSpacing = 12

    def __init__(self, text, parent=None):
        super(NodeTitle, self).__init__(parent)

        self.setSizePolicy(QtWidgets.QSizePolicy(QtWidgets.QSizePolicy.Fixed, QtWidgets.QSizePolicy.Fixed))

        self.__textItem = QtWidgets.QGraphicsTextItem(text, self)
        self.__textItem.setDefaultTextColor(self.__color)
        self.__textItem.setFont(self.__font)
        self.__textItem.setPos(0, -2)
        option = self.__textItem.document().defaultTextOption()
        option.setWrapMode(QtGui.QTextOption.NoWrap)
        self.__textItem.document().setDefaultTextOption(option)
        self.__textItem.adjustSize()

        self.setPreferredSize(self.textSize())

    def setText(self, text):
        self.__textItem.setPlainText(text)
        self.__textItem.adjustSize()
        self.setPreferredSize(self.textSize())

    def textSize(self):
        return QtCore.QSizeF(
            self.__textItem.textWidth(),
            self.__font.pointSizeF() + self.__labelBottomSpacing
            )
Exemplo n.º 7
0
    def __init__(self, graph, srcPortCircle, dstPortCircle):
        super(Connection, self).__init__()

        self.__graph = graph
        self.__srcPortCircle = srcPortCircle
        self.__dstPortCircle = dstPortCircle
        penStyle = QtCore.Qt.DashLine

        self.__connectionColor = QtGui.QColor(0, 0, 0)
        self.__connectionColor.setRgbF(
            *self.__srcPortCircle.getColor().getRgbF())
        self.__connectionColor.setAlpha(125)

        self.__defaultPen = QtGui.QPen(self.__connectionColor, 1.5, s=penStyle)
        self.__defaultPen.setDashPattern([1, 2, 2, 1])

        self.__connectionHoverColor = QtGui.QColor(0, 0, 0)
        self.__connectionHoverColor.setRgbF(
            *self.__srcPortCircle.getColor().getRgbF())
        self.__connectionHoverColor.setAlpha(255)

        self.__hoverPen = QtGui.QPen(self.__connectionHoverColor,
                                     1.5,
                                     s=penStyle)
        self.__hoverPen.setDashPattern([1, 2, 2, 1])

        self.setPen(self.__defaultPen)
        self.setZValue(-1)

        self.setAcceptHoverEvents(True)
        self.connect()
Exemplo n.º 8
0
def getPortColor(dataType):

    if dataType.startswith('Xfo'):
        return QtGui.QColor(128, 170, 170, 255)
    elif dataType.startswith('Float'):
        return QtGui.QColor(32, 255, 32, 255)
    elif dataType.startswith('Integer'):
        return QtGui.QColor(0, 128, 0, 255)
    elif dataType.startswith('Boolean'):
        return QtGui.QColor(255, 102, 0, 255)
    else:
        return QtGui.QColor(50, 205, 254, 255)
Exemplo n.º 9
0
class KBackdropTitle(QtWidgets.QGraphicsWidget):

    __color = QtGui.QColor(255, 255, 255)
    __font = QtGui.QFont('Helvetica', 11)
    __font.setLetterSpacing(QtGui.QFont.PercentageSpacing, 120)
    __fontMetrics = QtGui.QFontMetrics(__font)
    __labelBottomSpacing = 4

    def __init__(self, text, parent=None):
        super(KBackdropTitle, self).__init__(parent)

        self.parentWidget = parent

        self.__textItem = QtWidgets.QGraphicsTextItem(text, self)
        self.__textItem.setDefaultTextColor(self.__color)
        self.__textItem.setFont(self.__font)
        self.__textItem.setPos(0, 1)
        option = self.__textItem.document().defaultTextOption()
        self.__textItem.document().setDefaultTextOption(option)
        self.__textItem.adjustSize()
        self.__textItem.setTextWidth(120)

        self.setPreferredSize(self.textSize())

    def setText(self, text):
        self.__textItem.setPlainText(text)
        # self.__textItem.adjustSize()
        self.nodeResized(self.parentWidget.parentWidget.size().width())

    def setTextColor(self, color):
        self.__color = color
        self.update()

    def textSize(self):
        return QtCore.QSizeF(self.__textItem.textWidth(), self.textHeight())

    def textHeight(self):
        return self.__textItem.document().documentLayout().documentSize(
        ).height() + self.__labelBottomSpacing

    def nodeResized(self, width=None):

        fmWidth = self.__fontMetrics.width(self.__textItem.toPlainText())
        newWidth = min(fmWidth, width)
        if width > fmWidth:
            newWidth = width

        self.__textItem.setTextWidth(newWidth)
        self.setPreferredSize(newWidth, self.textHeight())

    def getBackdropWidget(self):
        return self.parent().parent()
Exemplo n.º 10
0
    def __init__(self, parent, color):
        super(KColorWidget, self).__init__(parent)
        self.installEventFilter(self)
        self._color = QtGui.QColor(color)

        self.pixmap = QtGui.QPixmap(12, 12)
        self.pixmap.fill(self._color)

        self.setProperty('colorLabel', True)
        self.setFixedSize(24, 24)
        self.setScaledContents(True)
        self.setPixmap(self.pixmap)

        self.createConnections()
Exemplo n.º 11
0
 def defineLineEditSubEditor():
     widget = LineEdit(self)
     validator = QtGui.QDoubleValidator(self)
     validator.setDecimals(3)
     widget.setValidator(validator)
     self.__editors.append(widget)
     return widget
Exemplo n.º 12
0
    def __init__(self, valueController, parent=None):
        super(ScalarSliderEditor, self).__init__(valueController,
                                                 parent=parent)

        hbox = QtWidgets.QHBoxLayout()

        validator = QtGui.QDoubleValidator(self)
        validator.setRange(self._range['min'], self._range['max'], 4)

        self._editEditor.setValidator(validator)
        self._editEditor.setSizePolicy(QtWidgets.QSizePolicy.Preferred,
                                       QtWidgets.QSizePolicy.Fixed)

        self._sliderEditor.setMinimum(self._range['min'] * 1000)
        self._sliderEditor.setMaximum(self._range['max'] * 1000)
        self._sliderEditor.setSizePolicy(
            QtWidgets.QSizePolicy.MinimumExpanding,
            QtWidgets.QSizePolicy.Fixed)
        self._sliderEditor.setTickInterval(1000)

        self._editEditor.setMinimumWidth(50)
        self._editEditor.setMaximumWidth(90)

        hbox.addWidget(self._editEditor, 1)
        hbox.addWidget(self._sliderEditor, 1)
        hbox.addStretch()
        self.setLayout(hbox)
        self.layout().setContentsMargins(0, 0, 0, 0)

        self.updateEditorValue()

        def __sliderPressed():
            self.beginInteraction()

        def __sliderReleased():
            self.endInteraction()

        def __sliderMoved(value):
            if self._updatingEditor:
                return
            value = float(value) / 1000
            self._editEditor.setText(str(round(value, 4)))
            self._value = value
            self._setValueToController()

        def __textEdited():
            if self._updatingEditor:
                return
            value = self.getEditorValue()
            # if self._dynamicRange:
            #     self.updateSliderRange(value)
            self._sliderEditor.setValue(value * 1000)
            self._setValueToController()

        self._sliderEditor.sliderPressed.connect(__sliderPressed)
        self._sliderEditor.sliderReleased.connect(__sliderReleased)
        self._sliderEditor.valueChanged.connect(__sliderMoved)
        self._editEditor.editingFinished.connect(__textEdited)

        self.setEditable(valueController.isEditable())
Exemplo n.º 13
0
    def __init__(self, parent=None):

        # constructors of base classes
        super(KrakenUI, self).__init__(parent)
        self.setObjectName('mainUI')
        self.setWindowIcon(QtGui.QIcon(':/images/Kraken_Icon.png'))

        self.setWindowTitle("Kraken Editor")
        self.setAcceptDrops(True)

        self.graphViewWidget = KGraphViewWidget(parent=self)
        self.nodeLibrary = ComponentLibrary(parent=self)

        self.horizontalSplitter = QtWidgets.QSplitter(QtCore.Qt.Horizontal,
                                                      parent=self)
        self.horizontalSplitter.addWidget(self.nodeLibrary)
        self.horizontalSplitter.addWidget(self.graphViewWidget)

        self.horizontalSplitter.setStretchFactor(0, 0)
        self.horizontalSplitter.setStretchFactor(1, 1)
        self.horizontalSplitter.setSizes([0, 100])
        self.horizontalSplitter.splitterMoved.connect(self.splitterMoved)
        self.nodeLibraryExpandedSize = 175

        grid = QtWidgets.QVBoxLayout(self)
        grid.addWidget(self.horizontalSplitter)
Exemplo n.º 14
0
    def setData(self, data):
        """Sets the data on a backdrop after loading.

        Args:
            data (dict): Name, comment, graph pos, size, and color.

        Returns:
            bool: True if successful.

        """

        self.setComment(data.get('comment', ''))

        size = data.get('size', (self.minimumWidth(), self.minimumHeight()))
        self.resize(size[0], size[1])

        position = data.get('graphPos', (0, 0))
        self.setGraphPos(QtCore.QPointF(position[0], position[1]))

        color = data.get('color', self.__defaultColor.toTuple())
        self.setColor(
            color=QtGui.QColor(color[0], color[1], color[2], color[3]))
        self.setUnselectedColor(self.getColor().darker(125))
        self.setSelectedColor(self.getColor().lighter(175))
        self.setHoveredColor(self.getColor().lighter(110))

        return True
Exemplo n.º 15
0
    def __init__(self, parent=None):
        super(KrakenWindow, self).__init__(parent)
        self.setObjectName('KrakenMainWindow')
        self.setWindowTitle('Kraken Editor')
        self.setWindowIcon(QtGui.QIcon(':/images/Kraken_Icon.png'))
        self.setAttribute(QtCore.Qt.WA_DeleteOnClose)
        self.installEventFilter(self)
        # self.setFocusPolicy(QtCore.Qt.StrongFocus)
        # self.setFocus()

        QtCore.QCoreApplication.setOrganizationName("Kraken")
        QtCore.QCoreApplication.setApplicationName("Kraken Editor")
        self.settings = QtCore.QSettings("Kraken", "Kraken Editor")
        self.preferences = Preferences()

        self._focusInCallbacks = []
        self._focusOutCallbacks = []

        cssPath = os.path.join(os.path.dirname(os.path.realpath(__file__)),
                               'kraken_ui.css')

        styleData = ''
        with open(cssPath) as cssFile:
            styleData = cssFile.read()

        self.setStyleSheet(styleData)

        self.createLayout()
        self.createConnections()
Exemplo n.º 16
0
 def unhighlight(self):
     self._ellipseItem.setBrush(QtGui.QBrush(self._color))
     self._ellipseItem.setRect(
         -self.__radius,
         -self.__radius,
         self.__diameter,
         self.__diameter,
     )
Exemplo n.º 17
0
    def _updateThumbnail(self):
        if self.__value.width > 0 and self.__value.height > 0:
                self._qimage = QtGui.QImage(self._thumbnailSize, self._thumbnailSize, QtGui.QImage.Format_RGB32)
                for i in range(self._thumbnailSize):
                    for j in range(self._thumbnailSize):
                        if self.__value.pixelFormat == "RGB":
                                pixelColor = self.__value.sampleRGB("""RGB""", float(i)/(self._thumbnailSize - 1.0), float(j)/(self._thumbnailSize - 1.0))
                        elif self.__value.pixelFormat == "RGBA":
                                pixelColor = self.__value.sampleRGBA("""RGBA""", float(i)/(self._thumbnailSize - 1.0), float(j)/(self._thumbnailSize - 1.0))
                        pixelValue = QtGui.qRgb(pixelColor.r, pixelColor.g, pixelColor.b)
                        self._qimage.setPixel(i, j, pixelValue)

                self.tumbnailEditor.setPixmap(QtGui.QPixmap.fromImage(self._qimage))


        self._grid.addWidget(self.tumbnailEditor, 3, 0, 2, 2)
        self._grid.setRowStretch(4, 2)
Exemplo n.º 18
0
    def write(self, msg, level):

        if level == 'DEBUG':
            messageColor = QtGui.QColor("#EEE97B")
        elif level == 'INFO':
            messageColor = QtGui.QColor(QtCore.Qt.white)
        elif level == 'INFORM':
            messageColor = QtGui.QColor("#009900")
        elif level == 'WARNING':
            messageColor = QtGui.QColor("#D89614")
        elif level == 'ERROR':
            messageColor = QtGui.QColor("#CC0000")
        elif level == 'CRITICAL':
            messageColor = QtGui.QColor("#CC0000")
        else:
            messageColor = QtGui.QColor(QtCore.Qt.white)

        self.textWidget.setTextColor(messageColor)
        charFormat = self.textWidget.currentCharFormat()
        textCursor = self.textWidget.textCursor()
        textCursor.movePosition(QtGui.QTextCursor.End)
        textCursor.insertText('[ ' + level + ' ] ' + msg, charFormat)

        self.textWidget.setTextCursor(textCursor)
        self.textWidget.ensureCursorVisible()
Exemplo n.º 19
0
    def __init__(self, parent=None):

        # constructors of base classes
        super(KGraphViewWidget, self).__init__(parent)

        self._builder = None
        self._guideBuilder = None
        self.guideRig = None

        graphView = KGraphView(parent=self)
        graphView.nodeAdded.connect(self.__onNodeAdded)
        graphView.nodeRemoved.connect(self.__onNodeRemoved)
        graphView.beginConnectionManipulation.connect(
            self.__onBeginConnectionManipulation)
        graphView.endConnectionManipulation.connect(
            self.__onEndConnectionManipulationSignal)
        graphView.connectionAdded.connect(self.__onConnectionAdded)
        graphView.connectionRemoved.connect(self.__onConnectionRemoved)

        graphView.selectionChanged.connect(self.__onSelectionChanged)
        graphView.endSelectionMoved.connect(self.__onSelectionMoved)

        graphView.beginDeleteSelection.connect(self.__onBeginDeleteSelection)
        graphView.endDeleteSelection.connect(self.__onEndDeleteSelection)

        self.setGraphView(graphView)

        # =========================================
        # Setup hotkeys for the following actions.
        # =========================================

        undoShortcut = QtWidgets.QShortcut(
            QtGui.QKeySequence(QtCore.Qt.CTRL + QtCore.Qt.Key_Z), self)
        undoShortcut.activated.connect(self.undo)

        redoShortcut = QtWidgets.QShortcut(
            QtGui.QKeySequence(QtCore.Qt.CTRL + QtCore.Qt.Key_Y), self)
        redoShortcut.activated.connect(self.redo)

        openContextualNodeListShortcut = QtWidgets.QShortcut(
            QtGui.QKeySequence(QtCore.Qt.Key_Tab), self)
        openContextualNodeListShortcut.activated.connect(
            self.openContextualNodeList)

        self.newRigPreset()
Exemplo n.º 20
0
 def highlight(self):
     self._ellipseItem.setBrush(QtGui.QBrush(self._color.lighter()))
     # make the port bigger to highlight it can accept the connection.
     self._ellipseItem.setRect(
         -self.__radius * 1.3,
         -self.__radius * 1.3,
         self.__diameter * 1.3,
         self.__diameter * 1.3,
     )
Exemplo n.º 21
0
        def defineLineEditSubEditor(name):
            label = QtWidgets.QLabel(name, self)
            hbox.addWidget(label)

            widget = LineEdit(self)
            validator = QtGui.QDoubleValidator(self)
            validator.setDecimals(2)
            widget.setValidator(validator)
            hbox.addWidget(widget, 1)
            self.__editors.append(widget)
            return widget
Exemplo n.º 22
0
    def paint(self, painter, option, widget):
        rect = self.windowFrameRect()
        painter.setBrush(self.__color)

        painter.setPen(QtGui.QPen(QtGui.QColor(0, 0, 0, 0), 0))

        roundingY = 20.0 / (rect.height() / 80.0)
        roundingX = rect.height() / rect.width() * roundingY

        painter.drawRoundRect(rect,
                              roundingX,
                              roundingY,
                              mode=QtCore.Qt.AbsoluteSize)

        # Title BG
        titleHeight = self.__headerItem.size().height() - 3

        darkerColor = self.__color.darker(125)
        darkerColor.setAlpha(255)
        painter.setBrush(darkerColor)
        roundingYHeader = rect.width() * roundingX / titleHeight
        painter.drawRoundRect(0, 0, rect.width(), titleHeight, roundingX,
                              roundingYHeader)
        painter.drawRect(0, titleHeight * 0.5 + 2, rect.width(),
                         titleHeight * 0.5)

        painter.setBrush(QtGui.QColor(0, 0, 0, 0))
        if self.__selected:
            painter.setPen(self.__selectedPen)
        elif self.__hoveredOver:
            painter.setPen(self.__hoveredPen)
        else:
            painter.setPen(self.__unselectedPen)

        painter.drawRoundRect(rect,
                              roundingX,
                              roundingY,
                              mode=QtCore.Qt.AbsoluteSize)

        super(KBackdrop, self).paint(painter, option, widget)
Exemplo n.º 23
0
    def setGraphView(self, graphView):

        self.graphView = graphView

        # Setup Layout
        layout = QtWidgets.QVBoxLayout(self)
        layout.addWidget(self.graphView)
        self.setLayout(layout)

        #########################
        ## Setup hotkeys for the following actions.
        deleteShortcut = QtWidgets.QShortcut(
            QtGui.QKeySequence(QtCore.Qt.Key_Delete), self)
        deleteShortcut.activated.connect(self.graphView.deleteSelectedNodes)

        frameShortcut = QtWidgets.QShortcut(
            QtGui.QKeySequence(QtCore.Qt.Key_F), self)
        frameShortcut.activated.connect(self.graphView.frameSelectedNodes)

        frameShortcut = QtWidgets.QShortcut(
            QtGui.QKeySequence(QtCore.Qt.Key_A), self)
        frameShortcut.activated.connect(self.graphView.frameAllNodes)
Exemplo n.º 24
0
    def __init__(self, graph, name):
        super(Node, self).__init__()

        self.__name = name
        self.__graph = graph
        self.__color = self.__defaultColor
        self.__unselectedColor = self.__defaultUnselectedColor
        self.__selectedColor = self.__defaultSelectedColor

        self.__unselectedPen = QtGui.QPen(self.__defaultUnselectedPen)
        self.__selectedPen = QtGui.QPen(self.__defaultSelectedPen)
        self.__linePen = QtGui.QPen(self.__defaultLinePen)

        self.setMinimumWidth(60)
        self.setMinimumHeight(20)
        self.setSizePolicy(QtWidgets.QSizePolicy(QtWidgets.QSizePolicy.Expanding, QtWidgets.QSizePolicy.Expanding))

        layout = QtWidgets.QGraphicsLinearLayout()
        layout.setContentsMargins(0, 0, 0, 0)
        layout.setSpacing(0)
        layout.setOrientation(QtCore.Qt.Vertical)
        self.setLayout(layout)

        self.__headerItem = NodeHeader(self.__name, self)
        layout.addItem(self.__headerItem)
        layout.setAlignment(self.__headerItem, QtCore.Qt.AlignCenter | QtCore.Qt.AlignTop)

        self.__ports = []
        self.__inputPortsHolder = PortList(self)
        self.__ioPortsHolder = PortList(self)
        self.__outputPortsHolder = PortList(self)

        layout.addItem(self.__inputPortsHolder)
        layout.addItem(self.__ioPortsHolder)
        layout.addItem(self.__outputPortsHolder)

        self.__selected = False
        self.__dragging = False
Exemplo n.º 25
0
    def __init__(self, app, *arg, **kwargs):

        splashPixmap = QtGui.QPixmap(':/images/KrakenUI_Splash.png')
        super(KrakenSplash, self).__init__(splashPixmap)

        for handler in logger.handlers:
            if type(handler).__name__ == 'WidgetHandler':
                handler.addWidget(self)

        self._msg = []
        self._app = app
        self.setMask(splashPixmap.mask())
        self.showMessage('Releasing the Kraken!', self.messageFlag, QtCore.Qt.white)
        self._app.processEvents()
Exemplo n.º 26
0
    def __init__(self, graph, name):
        super(KBackdrop, self).__init__()
        self.setAcceptHoverEvents(True)

        self.__name = name
        self.__comment = None

        self.__graph = graph
        self.__color = self.__defaultColor
        self.__color.setAlpha(25)
        self.__unselectedColor = self.__defaultUnselectedColor
        self.__selectedColor = self.__defaultSelectedColor
        self.__hoverColor = self.__defaultHoverColor

        self.__unselectedPen = QtGui.QPen(self.__defaultUnselectedPen)
        self.__selectedPen = QtGui.QPen(self.__defaultSelectedPen)
        self.__hoveredPen = QtGui.QPen(self.__defaultHoveredPen)
        self.__linePen = QtGui.QPen(self.__defaultLinePen)

        self.__inspectorWidget = None

        self.setMinimumWidth(120)
        self.setMinimumHeight(80)
        self.setZValue(-100)

        # Set defaults for interactions
        self.__selected = False
        self.__dragging = False
        self.__resizing = False
        self.__resizeCorner = -1
        self.__resizeEdge = -1

        self.createLayout()
        self.createConnections()

        # Initialize the comment with the name
        self.setComment(name)
Exemplo n.º 27
0
    def paint(self, painter, option, widget):
        srcPoint = self.mapFromScene(
            self.__srcPortCircle.centerInSceneCoords())
        dstPoint = self.mapFromScene(
            self.__dstPortCircle.centerInSceneCoords())

        dist_between = dstPoint - srcPoint

        self.__path = QtGui.QPainterPath()
        self.__path.moveTo(srcPoint)
        self.__path.cubicTo(
            srcPoint + QtCore.QPointF(dist_between.x() * 0.4, 0),
            dstPoint - QtCore.QPointF(dist_between.x() * 0.4, 0), dstPoint)
        self.setPath(self.__path)
        super(Connection, self).paint(painter, option, widget)
Exemplo n.º 28
0
    def __init__(self, port, graph, hOffset, color, connectionPointType):
        super(PortCircle, self).__init__(port)

        self.__port = port
        self._graph = graph
        self._connectionPointType = connectionPointType
        self.__connections = set()
        self._supportsOnlySingleConnections = connectionPointType == 'In'

        self.setSizePolicy(
            QtWidgets.QSizePolicy(QtWidgets.QSizePolicy.Fixed,
                                  QtWidgets.QSizePolicy.Fixed))
        size = QtCore.QSizeF(self.__diameter, self.__diameter)
        self.setPreferredSize(size)
        self.setWindowFrameMargins(0, 0, 0, 0)

        self.transform().translate(self.__radius * hOffset, 0)

        self.__defaultPen = QtGui.QPen(QtGui.QColor(25, 25, 25), 1.0)
        self.__hoverPen = QtGui.QPen(QtGui.QColor(255, 255, 100), 1.5)

        self._ellipseItem = QtWidgets.QGraphicsEllipseItem(self)
        self._ellipseItem.setPen(self.__defaultPen)
        self._ellipseItem.setPos(size.width() / 2, size.height() / 2)
        self._ellipseItem.setRect(
            -self.__radius,
            -self.__radius,
            self.__diameter,
            self.__diameter,
        )
        if connectionPointType == 'In':
            self._ellipseItem.setStartAngle(270 * 16)
            self._ellipseItem.setSpanAngle(180 * 16)

        self.setColor(color)
        self.setAcceptHoverEvents(True)
Exemplo n.º 29
0
    def frameNodes(self, nodes):
        if len(nodes) == 0:
            return

        def computeWindowFrame():
            windowRect = self.rect()
            windowRect.setLeft(windowRect.left() + 16)
            windowRect.setRight(windowRect.right() - 16)
            windowRect.setTop(windowRect.top() + 16)
            windowRect.setBottom(windowRect.bottom() - 16)
            return windowRect

        nodesRect = None
        for node in nodes:
            nodeRectF = node.transform().mapRect(node.rect())
            nodeRect = QtCore.QRect(nodeRectF.x(), nodeRectF.y(),
                                    nodeRectF.width(), nodeRectF.height())
            if nodesRect is None:
                nodesRect = nodeRect
            else:
                nodesRect = nodesRect.united(nodeRect)

        windowRect = computeWindowFrame()

        scaleX = float(windowRect.width()) / float(nodesRect.width())
        scaleY = float(windowRect.height()) / float(nodesRect.height())
        if scaleY > scaleX:
            scale = scaleX
        else:
            scale = scaleY

        if scale < 1.0:
            self.setTransform(QtGui.QTransform.fromScale(scale, scale))
        else:
            self.setTransform(QtGui.QTransform())

        sceneRect = self.sceneRect()
        pan = sceneRect.center() - nodesRect.center()
        sceneRect.translate(-pan.x(), -pan.y())
        self.setSceneRect(sceneRect)

        # Update the main panel when reframing.
        self.update()
Exemplo n.º 30
0
    def __init__(self, graph, component):
        super(KNode, self).__init__(graph, component.getDecoratedName())

        self.__component = component
        self.__inspectorWidget = None

        for i in range(self.__component.getNumInputs()):
            componentInput = component.getInputByIndex(i)
            self.addPort(KNodeInputPort(self, graph, componentInput))

        for i in range(self.__component.getNumOutputs()):
            componentOutput = component.getOutputByIndex(i)
            self.addPort(KNodeOutputPort(self, graph, componentOutput))

        self.setGraphPos(
            QtCore.QPointF(self.__component.getGraphPos().x,
                           self.__component.getGraphPos().y))

        nodeColor = component.getComponentColor()
        self.setColor(
            QtGui.QColor(nodeColor[0], nodeColor[1], nodeColor[2],
                         nodeColor[3]))
        self.setUnselectedColor(self.getColor().darker(125))
        self.setSelectedColor(self.getColor().lighter(175))