Skip to content
This repository was archived by the owner on Sep 20, 2023. It is now read-only.

Commit 3572f6a

Browse files
committed
cleaning up custom node widget base classes
renamed MWB, IWB to NodeMainWidget and NodeInputWidget respectively
1 parent e655886 commit 3572f6a

File tree

4 files changed

+57
-29
lines changed

4 files changed

+57
-29
lines changed

docs/unused/gui.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -40,11 +40,11 @@ import ryvencore_qt as rc
4040
from PySide2.QtWidgets import QPushButton
4141

4242

43-
class MyMainWidget(rc.MWB, QPushButton):
43+
class MyMainWidget(rc.NodeMainWidget, QPushButton):
4444
def __init__(self, params):
45-
rc.MWB.__init__(self, params)
45+
rc.NodeMainWidget.__init__(self, params)
4646
QPushButton.__init__(self)
47-
47+
4848
# then do your stuff like
4949
self.setEnabled(False)
5050
self.clicked.connect(self.node.update)

ryvencore_qt/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414

1515
# customer base classes
1616
from ryvencore import Node
17-
from .src.flows.nodes.WidgetBaseClasses import MWB, IWB
17+
from .src.flows.nodes.WidgetBaseClasses import NodeMainWidget, NodeInputWidget
1818

1919
# gui classes
2020
from .src.widgets import *

ryvencore_qt/src/flows/nodes/PortItemInputWidgets.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
from qtpy.QtGui import QFontMetrics, QFont
22
from qtpy.QtWidgets import QSpinBox, QLineEdit, QCheckBox, QComboBox
33

4-
from .WidgetBaseClasses import IWB
4+
from .WidgetBaseClasses import NodeInputWidget
55

66

7-
class DType_IW_Base(IWB):
7+
class DType_IW_Base(NodeInputWidget):
88

99
def __init__(self, params):
1010
super().__init__(params)

ryvencore_qt/src/flows/nodes/WidgetBaseClasses.py

Lines changed: 51 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -2,69 +2,97 @@
22
from ryvencore import Data
33

44

5-
class MWB:
6-
"""MainWidgetBase"""
5+
class NodeMainWidget:
6+
"""Base class for the main widget of a node."""
77

88
def __init__(self, params):
99
self.node, self.node_item = params
1010

1111
# OVERRIDE
1212
def get_state(self) -> dict:
13+
"""
14+
*VIRTUAL*
15+
16+
Return the state of the widget, in a (pickle) serializable format.
17+
"""
1318
data = {}
1419
return data
1520

16-
# OVERRIDE
1721
def set_state(self, data: dict):
18-
pass
22+
"""
23+
*VIRTUAL*
1924
20-
# OVERRIDE
21-
def remove_event(self):
25+
Set the state of the widget, where data corresponds to the dict
26+
returned by get_state().
27+
"""
2228
pass
2329

30+
# def remove_event(self):
31+
# """
32+
# *VIRTUAL*
33+
#
34+
# Called when the input is removed.
35+
# """
36+
# pass
37+
2438
def update_node(self):
2539
self.node.update()
2640

2741
def update_node_shape(self):
2842
self.node_item.update_shape()
2943

3044

31-
class IWB:
32-
"""InputWidgetBase"""
45+
class NodeInputWidget:
46+
"""Base class for the input widget of a node."""
3347

3448
def __init__(self, params):
3549
self.input, self.input_item, self.node, self.node_gui, self.position = \
3650
params
3751

38-
# OVERRIDE
39-
def get_val(self):
40-
"""
41-
Returns the value that the widget represents for the data input.
42-
It has to be (pickle) serializable!
52+
def get_state(self) -> dict:
4353
"""
54+
*VIRTUAL*
4455
45-
return None
46-
47-
# OVERRIDE
48-
def get_state(self) -> dict:
56+
Return the state of the widget, in a (pickle) serializable format.
57+
"""
4958
data = {}
5059
return data
5160

5261
# OVERRIDE
5362
def set_state(self, data: dict):
54-
pass
63+
"""
64+
*VIRTUAL*
5565
56-
# OVERRIDE
57-
def remove_event(self):
66+
Set the state of the widget, where data corresponds to the dict
67+
returned by get_state().
68+
"""
5869
pass
5970

6071
# OVERRIDE
72+
# def remove_event(self):
73+
# pass
74+
6175
def val_update_event(self, val):
76+
"""
77+
*VIRTUAL*
78+
79+
Called when the input's value is updated through a connection.
80+
This can be used to represent the value in the widget.
81+
The widget is disabled when the port is connected.
82+
"""
6283
pass
6384

85+
"""
86+
87+
API methods
88+
89+
"""
90+
6491
def update_node_input(self, val: Data):
65-
# updates the input's default value which is used when
66-
# the input is not connected
67-
self.input.default = Data(val)
92+
"""
93+
Update the input's value and update the node.
94+
"""
95+
self.input.default = val
6896
self.input.node.update(self.node.inputs.index(self.input))
6997

7098
def update_node(self):

0 commit comments

Comments
 (0)