patternpythonMinor
Node Graph-based User Interface with python
Viewed 0 times
graphwithnodeuserinterfacepythonbased
Problem
I'd like to create a pyqt widget similar to the one Blender uses for representing its nodes After wasting some bounties without getting any answers on Stack Overflow, I thought maybe posting a little piece of code here in Code Review would be a better idea.
My goal is designing a powerful node graph widget using python+pyqt where I can group/ungroup nodes. Below you'll find a possible initial design, I'm aware which is badly designed. Could you please point me out the main design flaws of this initial draft and some possible solutions?
model.py
```
from abc import ABCMeta, abstractmethod, abstractproperty
import six
import itertools
from functools import reduce as _reduce
@six.add_metaclass(ABCMeta)
class Port():
def __init__(self, name, datatype):
self.name = name
self.datatype = datatype
@abstractmethod
def can_connect_to(self, p):
raise NotImplementedError
class OutputPort(Port):
def __init__(self, parent, name, datatype):
super(OutputPort, self).__init__(name, datatype)
self.parent = parent
self.subscribers = []
def add_subscriber(self, input_port):
if input_port not in self.subscribers:
self.subscribers.append(input_port)
def remove_subscriber(self, input_port):
if input_port in self.subscribers:
self.subscribers.remove(input_port)
input_port.disconnect()
def update_all_subscribers(self):
for input_port in self.subscribers:
input_port.parent.process()
def remove_all_subscribers(self):
while len(self.subscribers) > 0:
self.remove_subscriber(self.subscribers[-1])
def position(self):
return self.parent.outputs.index(self)
def can_connect_to(self, input_port):
return (
isinstance(input_port, InputPort) and
self.datatype == input_port.datatype
)
class InputPort(Port):
def __init__(self, parent, name, datatype):
sup
My goal is designing a powerful node graph widget using python+pyqt where I can group/ungroup nodes. Below you'll find a possible initial design, I'm aware which is badly designed. Could you please point me out the main design flaws of this initial draft and some possible solutions?
model.py
```
from abc import ABCMeta, abstractmethod, abstractproperty
import six
import itertools
from functools import reduce as _reduce
@six.add_metaclass(ABCMeta)
class Port():
def __init__(self, name, datatype):
self.name = name
self.datatype = datatype
@abstractmethod
def can_connect_to(self, p):
raise NotImplementedError
class OutputPort(Port):
def __init__(self, parent, name, datatype):
super(OutputPort, self).__init__(name, datatype)
self.parent = parent
self.subscribers = []
def add_subscriber(self, input_port):
if input_port not in self.subscribers:
self.subscribers.append(input_port)
def remove_subscriber(self, input_port):
if input_port in self.subscribers:
self.subscribers.remove(input_port)
input_port.disconnect()
def update_all_subscribers(self):
for input_port in self.subscribers:
input_port.parent.process()
def remove_all_subscribers(self):
while len(self.subscribers) > 0:
self.remove_subscriber(self.subscribers[-1])
def position(self):
return self.parent.outputs.index(self)
def can_connect_to(self, input_port):
return (
isinstance(input_port, InputPort) and
self.datatype == input_port.datatype
)
class InputPort(Port):
def __init__(self, parent, name, datatype):
sup
Solution
I made this account to add a comment to your question, but that requires reputation points. This isn't really suitable for an answer but I think it can probably help you out.
There is a fairly featureless open source version of The Foundry's Nuke called Natron that has the implementation of a node graph you are looking for. Though you may have some trouble translating it if you don't know C++ very well.
Here's an example of one of a node tree made in Natron and a link to the github
There is a fairly featureless open source version of The Foundry's Nuke called Natron that has the implementation of a node graph you are looking for. Though you may have some trouble translating it if you don't know C++ very well.
Here's an example of one of a node tree made in Natron and a link to the github
Context
StackExchange Code Review Q#139851, answer score: 2
Revisions (0)
No revisions yet.