ryvencore 的 Qt 前端;用于构建可视节点编辑器的库
项目描述
rvencore-qt是ryvencore的包装器,并为它提供了一个 Qt 前端。它来自Ryven项目,将成为未来 Ryven 版本的基础。所以,ryvencore-qt 可以用来构建基于 Python 的跨平台独立可视化节点编辑器。使用 ryvencore-qt 制作的项目可以直接部署在后端 ryvencore 上。ryvencore-qt 的开发目前与 Ryven 紧密相关。
安装
pip install ryvencore-qt
或从源代码构建
git clone https://github.com/leon-thomm/ryvencore-qt
cd ryvencore-qt
pip install .
依赖项
ryvencore-qt 在 PySide2(Qt 的 Python 绑定)上运行,使用QtPy作为包装器(最终,一旦支持)实现 PySide2 和 PySide6 之间的无缝切换。请注意ryvencore-qt,由于 PyQt 中的关键继承限制,这不适用于 PyQt。
快速开始
下面的代码演示了如何使用自定义节点设置编辑器。您还可以在示例文件夹中找到代码。
main.py
# Qt
import sys
import os
os.environ['QT_API'] = 'pyside2' # tells QtPy to use PySide2
from qtpy.QtWidgets import QMainWindow, QApplication
# ryvencore-qt
import ryvencore_qt as rc
from nodes import export_nodes
if __name__ == "__main__":
# first, we create the Qt application and a window
app = QApplication()
mw = QMainWindow()
# now we initialize a new ryvencore-qt session
session = rc.Session()
session.design.set_flow_theme(name='pure light') # setting the design theme
# and register our nodes
session.register_nodes(export_nodes)
# to get a flow where we can place nodes, we need to crate a new script
script = session.create_script('hello world', flow_view_size=[800, 500])
# getting the flow widget of the newly created script
flow_view = session.flow_views[script]
mw.setCentralWidget(flow_view) # and show it in the main window
# finally, show the window and run the application
mw.show()
sys.exit(app.exec_())
nodes.py
import ryvencore_qt as rc
from random import random
# let's define some nodes
# to easily see something in action, we create one node generating random numbers, and one that prints them
class PrintNode(rc.Node):
"""Prints your data"""
title = 'Print'
init_inputs = [
rc.NodeInputBP(),
]
init_outputs = []
color = '#A9D5EF'
# we could also skip the constructor here
def __init__(self, params):
super().__init__(params)
def update_event(self, inp=-1):
print(
self.input(0) # get data from the first input
)
class RandNode(rc.Node):
"""Generates scaled random float values"""
title = 'Rand'
init_inputs = [
rc.NodeInputBP(dtype=rc.dtypes.Data(default=1)),
]
init_outputs = [
rc.NodeOutputBP(),
]
color = '#fcba03'
def update_event(self, inp=-1):
# random float between 0 and value at input
val = random() * self.input(0)
# setting the value of the first output
self.set_output_val(0, val)
export_nodes = [
PrintNode,
RandNode,
]
有关更详细的概述,包括流的精确定义,请参阅功能页面和ryvencore。
发展
代码不是 100% 符合 PEP 8 的,一些正在开发的部分可能看起来很乱。我正在尽我所能:) 随时改进。各个子包都有自己的自述文件,提供快速概述,这对于理解实现非常有帮助。
干杯。
项目详情
关
ryvencore_qt -0.3.1.3-py3-none-any.whl 的哈希值
| 算法 | 哈希摘要 | |
|---|---|---|
| SHA256 | 125d2e783660fdb3cfec614b6c1f0414fdc20de98c15167b7d4cb5c6ef8c05d4 |
|
| MD5 | b2dccc4e66b20678470821884447b28c |
|
| 布莱克2-256 | 1c6cf077704f0a6119ac5cf387975099b516b96a09c37fc1ce076fbfcaf606ab |