Skip to content

Commit 1941397

Browse files
committed
Updated NODE constant vars to enums
1 parent f6a088d commit 1941397

File tree

9 files changed

+90
-63
lines changed

9 files changed

+90
-63
lines changed

NodeGraphQt/constants.py

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -111,11 +111,22 @@ class PORT_TYPE(Enum):
111111

112112
# ==================================== NODE ====================================
113113

114-
NODE_WIDTH = 160
115-
NODE_HEIGHT = 60
116-
NODE_ICON_SIZE = 18
117-
NODE_SEL_COLOR = (255, 255, 255, 30)
118-
NODE_SEL_BORDER_COLOR = (254, 207, 42, 255)
114+
115+
class NODE_STYLING(Enum):
116+
"""
117+
Node styling layout:
118+
``NodeGraphQt.constants.NODE_STYLING``
119+
"""
120+
#: default node width.
121+
WIDTH = 160
122+
#: default node height.
123+
HEIGHT = 60
124+
#: default node icon size (WxH).
125+
ICON_SIZE = 18
126+
#: default node overlay color when selected.
127+
SELECTED_COLOR = (255, 255, 255, 30)
128+
#: default node border color when selected.
129+
SELECTED_BORDER_COLOR = (254, 207, 42, 255)
119130

120131
# === NODE PROPERTY ===
121132

NodeGraphQt/qgraphics/node_abstract.py

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,7 @@
11
#!/usr/bin/python
22
from Qt import QtCore, QtWidgets
33

4-
from NodeGraphQt.constants import (Z_VAL_NODE,
5-
NODE_WIDTH,
6-
NODE_HEIGHT,
7-
ITEM_CACHE_MODE)
4+
from NodeGraphQt.constants import Z_VAL_NODE, NODE_STYLING, ITEM_CACHE_MODE
85

96

107
class AbstractNodeItem(QtWidgets.QGraphicsItem):
@@ -28,8 +25,8 @@ def __init__(self, name='node', parent=None):
2825
'disabled': False,
2926
'visible': False,
3027
}
31-
self._width = NODE_WIDTH
32-
self._height = NODE_HEIGHT
28+
self._width = NODE_STYLING.WIDTH.value
29+
self._height = NODE_STYLING.HEIGHT.value
3330

3431
def __repr__(self):
3532
return '{}.{}(\'{}\')'.format(

NodeGraphQt/qgraphics/node_backdrop.py

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,7 @@
11
#!/usr/bin/python
22
from Qt import QtGui, QtCore, QtWidgets
33

4-
from NodeGraphQt.constants import (Z_VAL_PIPE,
5-
NODE_SEL_COLOR,
6-
NODE_SEL_BORDER_COLOR)
4+
from NodeGraphQt.constants import Z_VAL_PIPE, NODE_STYLING
75
from NodeGraphQt.qgraphics.node_abstract import AbstractNodeItem
86
from NodeGraphQt.qgraphics.pipe import PipeItem
97
from NodeGraphQt.qgraphics.port import PortItem
@@ -88,7 +86,7 @@ def paint(self, painter, option, widget):
8886

8987
item = self.parentItem()
9088
if item and item.selected:
91-
color = QtGui.QColor(*NODE_SEL_BORDER_COLOR)
89+
color = QtGui.QColor(*NODE_STYLING.SELECTED_BORDER_COLOR.value)
9290
else:
9391
color = QtGui.QColor(*item.color)
9492
color = color.darker(110)
@@ -221,7 +219,7 @@ def paint(self, painter, option, widget):
221219
self.backdrop_text)
222220

223221
if self.selected:
224-
sel_color = [x for x in NODE_SEL_COLOR]
222+
sel_color = [x for x in NODE_STYLING.SELECTED_COLOR.value]
225223
sel_color[-1] = 15
226224
painter.setBrush(QtGui.QColor(*sel_color))
227225
painter.setPen(QtCore.Qt.NoPen)
@@ -234,9 +232,9 @@ def paint(self, painter, option, widget):
234232

235233
border = 0.8
236234
border_color = self.color
237-
if self.selected and NODE_SEL_BORDER_COLOR:
235+
if self.selected and NODE_STYLING.SELECTED_BORDER_COLOR.value:
238236
border = 1.0
239-
border_color = NODE_SEL_BORDER_COLOR
237+
border_color = NODE_STYLING.SELECTED_BORDER_COLOR.value
240238
painter.setBrush(QtCore.Qt.NoBrush)
241239
painter.setPen(QtGui.QPen(QtGui.QColor(*border_color), border))
242240
painter.drawRoundedRect(rect, radius, radius)

NodeGraphQt/qgraphics/node_base.py

Lines changed: 32 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,14 @@
33

44
from Qt import QtGui, QtCore, QtWidgets
55

6-
from NodeGraphQt.constants import (PORT_TYPE, PORT_STYLING,
7-
NODE_WIDTH, NODE_HEIGHT,
8-
NODE_ICON_SIZE, ICON_NODE_BASE,
9-
NODE_SEL_COLOR, NODE_SEL_BORDER_COLOR,
10-
Z_VAL_NODE,
11-
ITEM_CACHE_MODE)
6+
from NodeGraphQt.constants import (
7+
ITEM_CACHE_MODE,
8+
ICON_NODE_BASE,
9+
NODE_STYLING,
10+
PORT_STYLING,
11+
PORT_TYPE,
12+
Z_VAL_NODE
13+
)
1214
from NodeGraphQt.errors import NodeWidgetError
1315
from NodeGraphQt.qgraphics.node_abstract import AbstractNodeItem
1416
from NodeGraphQt.qgraphics.node_overlay_disabled import XDisabledItem
@@ -28,9 +30,10 @@ class NodeItem(AbstractNodeItem):
2830
def __init__(self, name='node', parent=None):
2931
super(NodeItem, self).__init__(name, parent)
3032
pixmap = QtGui.QPixmap(ICON_NODE_BASE)
31-
if pixmap.size().height() > NODE_ICON_SIZE:
33+
if pixmap.size().height() > NODE_STYLING.ICON_SIZE.value:
3234
pixmap = pixmap.scaledToHeight(
33-
NODE_ICON_SIZE, QtCore.Qt.SmoothTransformation
35+
NODE_STYLING.ICON_SIZE.value,
36+
QtCore.Qt.SmoothTransformation
3437
)
3538
self._properties['icon'] = ICON_NODE_BASE
3639
self._icon_item = QtWidgets.QGraphicsPixmapItem(pixmap, self)
@@ -73,7 +76,7 @@ def paint(self, painter, option, widget):
7376

7477
# light overlay on background when selected.
7578
if self.selected:
76-
painter.setBrush(QtGui.QColor(*NODE_SEL_COLOR))
79+
painter.setBrush(QtGui.QColor(*NODE_STYLING.SELECTED_COLOR.value))
7780
painter.drawRoundedRect(rect, radius, radius)
7881

7982
# node name background.
@@ -84,15 +87,17 @@ def paint(self, painter, option, widget):
8487
rect.width() - padding[0] - margin,
8588
text_rect.height() - (padding[1] * 2))
8689
if self.selected:
87-
painter.setBrush(QtGui.QColor(*NODE_SEL_COLOR))
90+
painter.setBrush(QtGui.QColor(*NODE_STYLING.SELECTED_COLOR.value))
8891
else:
8992
painter.setBrush(QtGui.QColor(0, 0, 0, 80))
9093
painter.drawRoundedRect(text_rect, 3.0, 3.0)
9194

9295
# node border
9396
if self.selected:
9497
border_width = 1.2
95-
border_color = QtGui.QColor(*NODE_SEL_BORDER_COLOR)
98+
border_color = QtGui.QColor(
99+
*NODE_STYLING.SELECTED_BORDER_COLOR.value
100+
)
96101
else:
97102
border_width = 0.8
98103
border_color = QtGui.QColor(*self.border_color)
@@ -202,10 +207,10 @@ def _set_base_size(self, add_w=0.0, add_h=0.0):
202207
add_h (float): add additional height.
203208
"""
204209
self._width, self._height = self.calc_size(add_w, add_h)
205-
if self._width < NODE_WIDTH:
206-
self._width = NODE_WIDTH
207-
if self._height < NODE_HEIGHT:
208-
self._height = NODE_HEIGHT
210+
if self._width < NODE_STYLING.WIDTH.value:
211+
self._width = NODE_STYLING.WIDTH.value
212+
if self._height < NODE_STYLING.HEIGHT.value:
213+
self._height = NODE_STYLING.HEIGHT.value
209214

210215
def _set_text_color(self, color):
211216
"""
@@ -524,9 +529,11 @@ def icon(self, path=None):
524529
self._properties['icon'] = path
525530
path = path or ICON_NODE_BASE
526531
pixmap = QtGui.QPixmap(path)
527-
if pixmap.size().height() > NODE_ICON_SIZE:
528-
pixmap = pixmap.scaledToHeight(NODE_ICON_SIZE,
529-
QtCore.Qt.SmoothTransformation)
532+
if pixmap.size().height() > NODE_STYLING.ICON_SIZE.value:
533+
pixmap = pixmap.scaledToHeight(
534+
NODE_STYLING.ICON_SIZE.value,
535+
QtCore.Qt.SmoothTransformation
536+
)
530537
self._icon_item.setPixmap(pixmap)
531538
if self.scene():
532539
self.post_init()
@@ -808,14 +815,16 @@ def paint(self, painter, option, widget):
808815

809816
# light overlay on background when selected.
810817
if self.selected:
811-
painter.setBrush(QtGui.QColor(*NODE_SEL_COLOR))
818+
painter.setBrush(
819+
QtGui.QColor(*NODE_STYLING.SELECTED_COLOR.value)
820+
)
812821
painter.drawRoundedRect(rect, radius, radius)
813822

814823
# top & bottom edge background.
815824
padding = 2.0
816825
height = 10
817826
if self.selected:
818-
painter.setBrush(QtGui.QColor(*NODE_SEL_COLOR))
827+
painter.setBrush(QtGui.QColor(*NODE_STYLING.SELECTED_COLOR.value))
819828
else:
820829
painter.setBrush(QtGui.QColor(0, 0, 0, 80))
821830
for y in [rect.y() + padding, rect.height() - height - 1]:
@@ -828,7 +837,9 @@ def paint(self, painter, option, widget):
828837
border_color = QtGui.QColor(*self.border_color)
829838
if self.selected:
830839
border_width = 1.2
831-
border_color = QtGui.QColor(*NODE_SEL_BORDER_COLOR)
840+
border_color = QtGui.QColor(
841+
*NODE_STYLING.SELECTED_BORDER_COLOR.value
842+
)
832843
border_rect = QtCore.QRectF(rect.left(), rect.top(),
833844
rect.width(), rect.height())
834845

NodeGraphQt/qgraphics/node_group.py

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,7 @@
11
#!/usr/bin/python
22
from Qt import QtCore, QtGui, QtWidgets
33

4-
from NodeGraphQt.constants import (NODE_SEL_BORDER_COLOR,
5-
NODE_SEL_COLOR,
6-
PORT_STYLING)
4+
from NodeGraphQt.constants import NODE_STYLING, PORT_STYLING
75
from NodeGraphQt.qgraphics.node_base import NodeItem
86

97

@@ -65,9 +63,11 @@ def paint(self, painter, option, widget):
6563
painter.drawRect(rect_2)
6664

6765
if self.selected:
68-
border_color = QtGui.QColor(*NODE_SEL_BORDER_COLOR)
66+
border_color = QtGui.QColor(
67+
*NODE_STYLING.SELECTED_BORDER_COLOR.value
68+
)
6969
# light overlay on background when selected.
70-
painter.setBrush(QtGui.QColor(*NODE_SEL_COLOR))
70+
painter.setBrush(QtGui.QColor(*NODE_STYLING.SELECTED_COLOR.value))
7171
painter.drawRect(rect_2)
7272
else:
7373
border_color = QtGui.QColor(*self.border_color)
@@ -80,7 +80,7 @@ def paint(self, painter, option, widget):
8080
rect.right() - (padding[0] * 2) - margin,
8181
text_rect.height() - (padding[1] * 2))
8282
if self.selected:
83-
painter.setBrush(QtGui.QColor(*NODE_SEL_COLOR))
83+
painter.setBrush(QtGui.QColor(*NODE_STYLING.SELECTED_COLOR.value))
8484
else:
8585
painter.setBrush(QtGui.QColor(0, 0, 0, 80))
8686
painter.setPen(QtCore.Qt.NoPen)
@@ -242,9 +242,11 @@ def paint(self, painter, option, widget):
242242
painter.drawRect(rect_2)
243243

244244
if self.selected:
245-
border_color = QtGui.QColor(*NODE_SEL_BORDER_COLOR)
245+
border_color = QtGui.QColor(
246+
*NODE_STYLING.SELECTED_BORDER_COLOR.value
247+
)
246248
# light overlay on background when selected.
247-
painter.setBrush(QtGui.QColor(*NODE_SEL_COLOR))
249+
painter.setBrush(QtGui.QColor(*NODE_STYLING.SELECTED_COLOR.value))
248250
painter.drawRect(rect_2)
249251
else:
250252
border_color = QtGui.QColor(*self.border_color)
@@ -253,7 +255,7 @@ def paint(self, painter, option, widget):
253255
padding = 2.0
254256
height = 10
255257
if self.selected:
256-
painter.setBrush(QtGui.QColor(*NODE_SEL_COLOR))
258+
painter.setBrush(QtGui.QColor(*NODE_STYLING.SELECTED_COLOR.value))
257259
else:
258260
painter.setBrush(QtGui.QColor(0, 0, 0, 80))
259261

NodeGraphQt/qgraphics/node_port_in.py

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
#!/usr/bin/python
22
from Qt import QtCore, QtGui, QtWidgets
33

4-
from NodeGraphQt.constants import (NODE_SEL_BORDER_COLOR, NODE_SEL_COLOR)
4+
from NodeGraphQt.constants import NODE_STYLING
55
from NodeGraphQt.qgraphics.node_base import NodeItem, NodeItemVertical
66

77

@@ -74,8 +74,10 @@ def paint(self, painter, option, widget):
7474
poly = transform.map(triangle)
7575

7676
if self.selected:
77-
pen = QtGui.QPen(QtGui.QColor(*NODE_SEL_BORDER_COLOR), 1.3)
78-
painter.setBrush(QtGui.QColor(*NODE_SEL_COLOR))
77+
pen = QtGui.QPen(
78+
QtGui.QColor(*NODE_STYLING.SELECTED_BORDER_COLOR.value), 1.3
79+
)
80+
painter.setBrush(QtGui.QColor(*NODE_STYLING.SELECTED_COLOR.value))
7981
else:
8082
pen = QtGui.QPen(QtGui.QColor(*self.border_color), 1.2)
8183
painter.setBrush(QtGui.QColor(0, 0, 0, 50))
@@ -220,8 +222,10 @@ def paint(self, painter, option, widget):
220222
poly = transform.map(triangle)
221223

222224
if self.selected:
223-
pen = QtGui.QPen(QtGui.QColor(*NODE_SEL_BORDER_COLOR), 1.3)
224-
painter.setBrush(QtGui.QColor(*NODE_SEL_COLOR))
225+
pen = QtGui.QPen(
226+
QtGui.QColor(*NODE_STYLING.SELECTED_BORDER_COLOR.value), 1.3
227+
)
228+
painter.setBrush(QtGui.QColor(*NODE_STYLING.SELECTED_COLOR.value))
225229
else:
226230
pen = QtGui.QPen(QtGui.QColor(*self.border_color), 1.2)
227231
painter.setBrush(QtGui.QColor(0, 0, 0, 50))

NodeGraphQt/qgraphics/node_port_out.py

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
#!/usr/bin/python
22
from Qt import QtCore, QtGui, QtWidgets
33

4-
from NodeGraphQt.constants import (NODE_SEL_BORDER_COLOR, NODE_SEL_COLOR)
4+
from NodeGraphQt.constants import NODE_STYLING
55
from NodeGraphQt.qgraphics.node_base import NodeItem, NodeItemVertical
66

77

@@ -74,8 +74,10 @@ def paint(self, painter, option, widget):
7474
poly = transform.map(triangle)
7575

7676
if self.selected:
77-
pen = QtGui.QPen(QtGui.QColor(*NODE_SEL_BORDER_COLOR), 1.3)
78-
painter.setBrush(QtGui.QColor(*NODE_SEL_COLOR))
77+
pen = QtGui.QPen(
78+
QtGui.QColor(*NODE_STYLING.SELECTED_BORDER_COLOR.value), 1.3
79+
)
80+
painter.setBrush(QtGui.QColor(*NODE_STYLING.SELECTED_COLOR.value))
7981
else:
8082
pen = QtGui.QPen(QtGui.QColor(*self.border_color), 1.2)
8183
painter.setBrush(QtGui.QColor(0, 0, 0, 50))
@@ -229,8 +231,10 @@ def paint(self, painter, option, widget):
229231
poly = transform.map(triangle)
230232

231233
if self.selected:
232-
pen = QtGui.QPen(QtGui.QColor(*NODE_SEL_BORDER_COLOR), 1.3)
233-
painter.setBrush(QtGui.QColor(*NODE_SEL_COLOR))
234+
pen = QtGui.QPen(
235+
QtGui.QColor(*NODE_STYLING.SELECTED_BORDER_COLOR.value), 1.3
236+
)
237+
painter.setBrush(QtGui.QColor(*NODE_STYLING.SELECTED_COLOR.value))
234238
else:
235239
pen = QtGui.QPen(QtGui.QColor(*self.border_color), 1.2)
236240
painter.setBrush(QtGui.QColor(0, 0, 0, 50))

NodeGraphQt/widgets/node_graph.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
from Qt import QtWidgets, QtGui
22

33
from NodeGraphQt.constants import (
4-
NODE_SEL_BORDER_COLOR,
4+
NODE_STYLING,
55
VIEWER_BG_COLOR,
66
VIEWER_NAV_BG_COLOR
77
)
@@ -36,12 +36,12 @@ def __init__(self, parent=None):
3636
'color': 'rgb({0},{1},{2})'.format(*text_color),
3737
'background': 'rgb({0},{1},{2})'.format(*VIEWER_NAV_BG_COLOR),
3838
'border-top': '1px solid rgb({0},{1},{2})'
39-
.format(*NODE_SEL_BORDER_COLOR),
39+
.format(*NODE_STYLING.SELECTED_BORDER_COLOR.value),
4040
},
4141
'QTabBar::tab:hover': {
4242
'color': 'rgb({0},{1},{2})'.format(*text_color),
4343
'border-top': '1px solid rgb({0},{1},{2})'
44-
.format(*NODE_SEL_BORDER_COLOR),
44+
.format(*NODE_STYLING.SELECTED_BORDER_COLOR.value),
4545
}
4646
}
4747
stylesheet = ''

NodeGraphQt/widgets/viewer_nav.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
from Qt import QtWidgets, QtCore, QtGui
22

33
from NodeGraphQt.constants import (
4-
NODE_SEL_BORDER_COLOR,
4+
NODE_STYLING,
55
VIEWER_NAV_BG_COLOR,
66
VIEWER_NAV_ITEM_COLOR
77
)
@@ -40,7 +40,7 @@ def paint(self, painter, option, index):
4040
itm_color = QtGui.QColor(80, 128, 123)
4141
if option.state & QtWidgets.QStyle.State_Selected:
4242
bg_color = bg_color.lighter(120)
43-
itm_color = QtGui.QColor(*NODE_SEL_BORDER_COLOR)
43+
itm_color = QtGui.QColor(*NODE_STYLING.SELECTED_BORDER_COLOR.value)
4444

4545
roundness = 2.0
4646
painter.setBrush(bg_color)

0 commit comments

Comments
 (0)