Example #1
0
 def paint_body(self, painter, option, widget):
     # Paint the body part.
     painter.setBrush(_qt.QBrush(_qt.QColor(*UI.node.body.brush)))
     painter.drawRect(
         self.x,
         self.y + UI.node.header.height,
         UI.node.width,
         self.height - UI.node.header.height,
     )
Example #2
0
    def drawBackground(self, painter, rect):
        painter.setBrush(_qt.QColor(*UI.graph.brush))
        painter.drawRect(rect)

        for i, lines in enumerate(self.get_grid_lines(rect)):
            color = _qt.QColor(*UI.graph.grid.lines[i]['pen'])
            thickness = UI.graph.grid.lines[i]['thickness']
            painter.setPen(_qt.QPen(color, thickness))
            painter.drawLines(lines)
Example #3
0
 def paint_label(self, painter, option, widget):
     # Paint the label part.
     painter.setBrush(_qt.QBrush(_qt.QColor(*UI.node.header.brush)))
     painter.drawRect(
         self.x,
         self.y,
         UI.node.width,
         UI.node.header.height,
     )
Example #4
0
 def paint_resize_handle(self, painter, option, widget):
     """Paint the footer region of the node.
     """
     painter.setBrush(_qt.QBrush(_qt.QColor(*UI['header']['brush'])))
     painter.drawRect(
         self.x,
         self.y + self.height - self.resize_handle_size,
         UI.node.width,
         self.resize_handle_size,
     )
Example #5
0
 def paint_label_text(self, painter, option, widget):
     # Paint the label text
     font = _qt.QFont(
         UI.node.label.font.family,
         UI.node.label.font.size,
         UI.node.label.font.weight,
     )
     painter.setFont(font)
     painter.setPen(_qt.QColor(*UI.node.label.pen))
     painter.drawText(
         self.x + UI.node.label.offset,
         self.y,
         UI.node.width - UI.node.label.offset,
         UI.node.header.height,
         _qtcore.Qt.AlignVCenter | _qtcore.Qt.AlignLeft,
         self.name,
     )
Example #6
0
    def reset(self):
        self.myWidth = self.node.width - self.attribute.size
        self.myHeight = 50
        self.setStyleSheet("background-color: transparent")
        self.resize(self.myWidth, self.myHeight)
        self.layout = _qt.QHBoxLayout()
        self.setLayout(self.layout)

        self.left_layout = _qt.QHBoxLayout()
        self.right_layout = _qt.QHBoxLayout()
        self.left_layout.setAlignment(_qtcore.Qt.AlignLeft)
        self.right_layout.setAlignment(_qtcore.Qt.AlignRight)
        self.layout.addLayout(self.left_layout)
        self.layout.addLayout(self.right_layout)

        self.label = _qt.QLabel(self.name)
        self.right_layout.addWidget(self.label)
Example #7
0
    def paint_highlight(self, painter, option, widget):
        """Highlight the node.

        Called when the node is selected.
        """
        path = _qt.QPainterPath()
        path.addRoundedRect(
            self.x,
            self.y,
            UI.node.width,
            self.height,
            UI.node.roundness,
            UI.node.roundness,
        )
        self.highlighter.setWidth(UI.node.highlight.padding * 2)
        outline = self.highlighter.createStroke(path)
        color = _qt.QColor(*UI.node.highlight.brush)
        painter.fillPath(outline, _qt.QBrush(color))
Example #8
0
    def compute_path(self):
        """Compute the path of this connection.

        The computed path will be drawn between the source_pos and
        destination_pos of this connection.

        This method requires `BaseConnection.source_pos` and
        `BaseConnection.destination_pos` attributes to be set.
        Both must be `PySide.QtCore.QPointF` attributes or present
        a similar interface (`PySide.QtCore.QPointF.x` and
        `PySide.QtCore.QPointF.y` are used in particular).
        """
        path = _qt.QPainterPath()
        path.moveTo(self.source_pos)

        control_x = self.destination_pos.x() - self.source_pos.x()
        control_y = self.destination_pos.y() - self.source_pos.y()

        control_source = _qtcore.QPointF(
            self.source_pos.x() + control_x * .4,
            self.source_pos.y() + control_y * 0,
        )

        control_destination = _qtcore.QPointF(
            self.source_pos.x() + control_x * .6,
            self.source_pos.y() + control_y * 1,
        )

        path.cubicTo(
            control_source,
            control_destination,
            self.destination_pos,
        )

        stroker = _qt.QPainterPathStroker()
        stroker.setWidth(UI.connection.thickness)
        stroker.setCapStyle(_qtcore.Qt.RoundCap)

        self.setPath(stroker.createStroke(path))
Example #9
0
def main():
    app = _qt.QApplication(sys.argv)

    window = kukulkan.gui.api.window.GraphWindow()
    jong = window.scene.add_node('jong')
    jonhy = window.scene.add_node('johny')
    rouleau = jong.add_attribute('rouleau_de_printemps')
    autre = jonhy.add_attribute('autre_chose')
    rouleau.is_output = True
    rouleau.is_input = False
    window.show()

    sys.exit(app.exec_())
Example #10
0
    def reset(self):
        """Reset the graphic state to its initial value."""
        self.setFlag(_qt.QGraphicsItem.ItemIsMovable)
        self.setFlag(_qt.QGraphicsItem.ItemIsSelectable)
        self.setFlag(_qt.QGraphicsItem.ItemIsFocusable)

        self.resizing = False

        self.x = 0
        self.y = 0

        self.highlighter = _qt.QPainterPathStroker()
        self.highlighter.setCapStyle(_qtcore.Qt.RoundCap)
        self.resize_handle_size = 10
Example #11
0
def main():
    app = _qt.QApplication(sys.argv)

    window = kukulkan.gui.api.window.GraphWindow()
    jong = window.scene.add_node('jong')
    johnny = window.scene.add_node('johnny')

    attr = kukulkan.gui.api.attribute.Attribute

    rouleau = jong.add_attribute('rouleau_de_printemps', attr)
    autre = johnny.add_attribute('autre_chose', attr)
    window.show()

    sys.exit(app.exec_())
Example #12
0
    def paint_clip(self, painter, option, widget):
        # Clip the node to make it round.
        clip = _qt.QPainterPath()
        clip.addRoundedRect(
            self.x,
            self.y,
            UI.node.width,
            self.height,
            UI.node.roundness,
            UI.node.roundness,
        )
        painter.setClipping(True)
        painter.setClipPath(clip)

        painter.setPen(_qtcore.Qt.NoPen)
Example #13
0
 def paint(self, painter, option, widget):
     if self.attribute.type == 'integer':
         painter.setBrush(_qt.QColor(*UI.plug.integer.brush))
     elif self.attribute.type == 'float':
         painter.setBrush(_qt.QColor(*UI.plug.float.brush))
     elif self.attribute.type == 'boolean':
         painter.setBrush(_qt.QColor(*UI.plug.boolean.brush))
     elif self.attribute.type == 'string':
         painter.setBrush(_qt.QColor(*UI.plug.string.brush))
     elif self.attribute.type == 'enum':
         painter.setBrush(_qt.QColor(*UI.plug.enum.brush))
     else:
         painter.setBrush(_qt.QColor(*UI.plug.brush))
     pen = _qt.QPen(_qt.QBrush(_qt.QColor(*UI.plug.pen.brush)),
                    UI.plug.pen.width)
     painter.setPen(_qtcore.Qt.NoPen)
     painter.drawEllipse(
         self.x,
         self.y,
         UI.plug.size,
         UI.plug.size,
     )
Example #14
0
def main():
    app = _qt.QApplication(sys.argv)

    window = kukulkan.gui.api.window.GraphWindow()

    node1 = window.scene.add_node('Node1')
    node1.add_attribute(name='Integer',
                        attribute_type='integer',
                        plug_type='output')
    node1.add_attribute(name='Float',
                        attribute_type='float',
                        plug_type='output')
    node1.add_attribute(name='Boolean',
                        attribute_type='boolean',
                        plug_type='output')
    node1.add_attribute(name='String',
                        attribute_type='string',
                        plug_type='output')
    node1.add_attribute(name='Enum', attribute_type='enum', plug_type='output')

    node2 = window.scene.add_node('Node2')
    node2.add_attribute(name='Integer',
                        attribute_type='integer',
                        plug_type='input')
    node2.add_attribute(name='Float',
                        attribute_type='float',
                        plug_type='input')
    node2.add_attribute(name='Boolean',
                        attribute_type='boolean',
                        plug_type='input')
    node2.add_attribute(name='String',
                        attribute_type='string',
                        plug_type='input')
    node2.add_attribute(name='Enum', attribute_type='enum', plug_type='input')

    window.show()

    sys.exit(app.exec_())
Example #15
0
 def paint(self, painter, option, widget):
     """Draw a path between the source and destination `Attribute`."""
     self.compute_path()
     super(BaseConnection, self).paint(painter, option, widget)
     brush = _qt.QBrush(_qt.QColor(*UI.connection.brush))
     painter.fillPath(self.path(), brush)
Example #16
0
def main():
    app = _qt.QApplication(sys.argv)

    window = kukulkan.gui.api.window.GraphWindow()

    if_node = window.scene.add_node('If')
    if_node.add_attribute(
        name='Condition',
        attribute_type='boolean',
        plug_type='input',
    )
    if_node.add_attribute(
        name='If True',
        attribute_type='message',
        plug_type='output',
    )
    if_node.add_attribute(
        name='If False',
        attribute_type='message',
        plug_type='output',
    )

    condition_node = window.scene.add_node('Condition')
    condition_node.add_attribute(
        name='Input1',
        attribute_type='integer',
        plug_type='input',
    )
    condition_node.add_attribute(
        name='Input2',
        attribute_type='integer',
        plug_type='input',
    )
    comparator = condition_node.add_attribute(
        name='Comparator',
        attribute_type='enum',
        plug_type='input',
    )
    comparator.base_widget.widget().widget.addItem('=')
    comparator.base_widget.widget().widget.addItem('<')
    comparator.base_widget.widget().widget.addItem('>')
    comparator.base_widget.widget().widget.addItem('<=')
    comparator.base_widget.widget().widget.addItem('>=')

    condition_node.add_attribute(
        name='output',
        attribute_type='boolean',
        plug_type='output',
    )

    for_node = window.scene.add_node('For Loop')
    for_node.add_attribute(
        name='N',
        attribute_type='integer',
        plug_type='input',
    )
    for_node.add_attribute(
        name='Do',
        attribute_type='message',
        plug_type='output',
    )
    for_node.add_attribute(
        name='Then',
        attribute_type='message',
        plug_type='output',
    )

    window.show()

    sys.exit(app.exec_())
Example #17
0
 def create_widget(self):
     """Create a QCheckBox."""
     super(Boolean, self).create_widget()
     self.widget = _qt.QCheckBox()
     self.widget.setTristate(False)
     self.widget.stateChanged.connect(self.update_value_from_widget)