Skip to content

Commit bdc6be7

Browse files
committed
Updated VIEWER constant vars to enums
1 parent 1941397 commit bdc6be7

File tree

9 files changed

+96
-60
lines changed

9 files changed

+96
-60
lines changed

NodeGraphQt/base/graph.py

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
PIPE_LAYOUT,
2222
URI_SCHEME, URN_SCHEME,
2323
PORT_TYPE,
24-
VIEWER_GRID_LINES
24+
VIEWER_STYLING
2525
)
2626
from NodeGraphQt.nodes.backdrop_node import BackdropNode
2727
from NodeGraphQt.nodes.base_node import BaseNode
@@ -553,7 +553,7 @@ def set_grid_color(self, r, g, b):
553553
self.scene().grid_color = (r, g, b)
554554
self._viewer.force_update()
555555

556-
def set_grid_mode(self, mode=VIEWER_GRID_LINES):
556+
def set_grid_mode(self, mode=None):
557557
"""
558558
Set node graph grid mode.
559559
@@ -562,13 +562,20 @@ def set_grid_mode(self, mode=VIEWER_GRID_LINES):
562562
563563
Node graph background types:
564564
565-
* :attr:`NodeGraphQt.constants.VIEWER_GRID_NONE`
566-
* :attr:`NodeGraphQt.constants.VIEWER_GRID_DOTS`
567-
* :attr:`NodeGraphQt.constants.VIEWER_GRID_LINES`
565+
* :attr:`NodeGraphQt.constants.VIEWER_STYLING.GRID_DISPLAY_NONE.value`
566+
* :attr:`NodeGraphQt.constants.VIEWER_STYLING.GRID_DISPLAY_DOTS.value`
567+
* :attr:`NodeGraphQt.constants.VIEWER_STYLING.GRID_DISPLAY_LINES.value`
568568
569569
Args:
570570
mode (int): background style.
571571
"""
572+
display_types = [
573+
VIEWER_STYLING.GRID_DISPLAY_NONE.value,
574+
VIEWER_STYLING.GRID_DISPLAY_DOTS.value,
575+
VIEWER_STYLING.GRID_DISPLAY_LINES.value
576+
]
577+
if mode not in display_types:
578+
mode = VIEWER_STYLING.GRID_DISPLAY_LINES.value
572579
self.scene().grid_mode = mode
573580
self._viewer.force_update()
574581

NodeGraphQt/base/graph_actions.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -280,24 +280,24 @@ def _bg_grid_none(graph):
280280
"""
281281
Turn off the background patterns.
282282
"""
283-
from NodeGraphQt.constants import VIEWER_GRID_NONE
284-
graph.set_grid_mode(VIEWER_GRID_NONE)
283+
from NodeGraphQt.constants import VIEWER_STYLING
284+
graph.set_grid_mode(VIEWER_STYLING.GRID_DISPLAY_NONE.value)
285285

286286

287287
def _bg_grid_dots(graph):
288288
"""
289289
Set background node graph background with grid dots.
290290
"""
291-
from NodeGraphQt.constants import VIEWER_GRID_DOTS
292-
graph.set_grid_mode(VIEWER_GRID_DOTS)
291+
from NodeGraphQt.constants import VIEWER_STYLING
292+
graph.set_grid_mode(VIEWER_STYLING.GRID_DISPLAY_DOTS.value)
293293

294294

295295
def _bg_grid_lines(graph):
296296
"""
297297
Set background node graph background with grid lines.
298298
"""
299-
from NodeGraphQt.constants import VIEWER_GRID_LINES
300-
graph.set_grid_mode(VIEWER_GRID_LINES)
299+
from NodeGraphQt.constants import VIEWER_STYLING
300+
graph.set_grid_mode(VIEWER_STYLING.GRID_DISPLAY_LINES.value)
301301

302302

303303
def _layout_graph_down(graph):

NodeGraphQt/constants.py

Lines changed: 30 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -167,18 +167,36 @@ class NODE_STYLING(Enum):
167167

168168
# === NODE VIEWER ===
169169

170-
#: Style to render the node graph background with nothing.
171-
VIEWER_GRID_NONE = 0
172-
#: Style to render the node graph background with dots.
173-
VIEWER_GRID_DOTS = 1
174-
#: Style to render the node graph background with grid lines.
175-
VIEWER_GRID_LINES = 2
176-
177-
VIEWER_NAV_BG_COLOR = (25, 25, 25)
178-
VIEWER_NAV_ITEM_COLOR = (35, 35, 35)
179-
VIEWER_BG_COLOR = (35, 35, 35)
180-
VIEWER_GRID_COLOR = (45, 45, 45)
181-
VIEWER_GRID_SIZE = 50
170+
171+
class VIEWER_STYLING(Enum):
172+
"""
173+
Node graph viewer styling layout:
174+
``NodeGraphQt.constants.VIEWER_STYLING``
175+
"""
176+
#: default background color for the node graph.
177+
BACKGROUND_COLOR = (35, 35, 35)
178+
#: style node graph background with no grid or dots.
179+
GRID_DISPLAY_NONE = 0
180+
#: style node graph background with dots.
181+
GRID_DISPLAY_DOTS = 1
182+
#: style node graph background with grid lines.
183+
GRID_DISPLAY_LINES = 2
184+
#: grid size when styled with grid lines.
185+
GRID_SIZE = 50
186+
#: grid line color.
187+
GRID_COLOR = (45, 45, 45)
188+
189+
190+
class VIEWER_NAV_STYLING(Enum):
191+
"""
192+
Node graph viewer navigation styling layout:
193+
``NodeGraphQt.constants.VIEWER_NAV_STYLING``
194+
"""
195+
#: default background color.
196+
BACKGROUND_COLOR = (25, 25, 25)
197+
#: default item color.
198+
ITEM_COLOR = (35, 35, 35)
199+
182200

183201
# ================================== PRIVATE ===================================
184202

NodeGraphQt/widgets/actions.py

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

4-
from NodeGraphQt.constants import VIEWER_BG_COLOR
4+
from NodeGraphQt.constants import VIEWER_STYLING
55

66

77
class BaseMenu(QtWidgets.QMenu):
@@ -13,7 +13,9 @@ def __init__(self, *args, **kwargs):
1313
style_dict = {
1414
'QMenu': {
1515
'color': 'rgb({0},{1},{2})'.format(*text_color),
16-
'background-color': 'rgb({0},{1},{2})'.format(*VIEWER_BG_COLOR),
16+
'background-color': 'rgb({0},{1},{2})'.format(
17+
*VIEWER_STYLING.BACKGROUND_COLOR.value
18+
),
1719
'border': '1px solid rgba({0},{1},{2},30)'.format(*text_color),
1820
'border-radius': '3px',
1921
},

NodeGraphQt/widgets/node_graph.py

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

33
from NodeGraphQt.constants import (
4-
NODE_STYLING,
5-
VIEWER_BG_COLOR,
6-
VIEWER_NAV_BG_COLOR
4+
NODE_STYLING, VIEWER_STYLING, VIEWER_NAV_STYLING
75
)
6+
87
from NodeGraphQt.widgets.viewer_nav import NodeNavigationWidget
98

109

@@ -15,13 +14,18 @@ def __init__(self, parent=None):
1514
self.setTabsClosable(True)
1615
self.setTabBarAutoHide(True)
1716
text_color = self.palette().text().color().toTuple()
18-
bg_color = QtGui.QColor(*VIEWER_BG_COLOR).darker(120).toTuple()
17+
bg_color = QtGui.QColor(
18+
*VIEWER_STYLING.BACKGROUND_COLOR.value).darker(120).toTuple()
1919
style_dict = {
2020
'QWidget': {
21-
'background-color': 'rgb({0},{1},{2})'.format(*VIEWER_BG_COLOR),
21+
'background-color': 'rgb({0},{1},{2})'.format(
22+
*VIEWER_STYLING.BACKGROUND_COLOR.value
23+
),
2224
},
2325
'QTabWidget::pane': {
24-
'background': 'rgb({0},{1},{2})'.format(*VIEWER_BG_COLOR),
26+
'background': 'rgb({0},{1},{2})'.format(
27+
*VIEWER_STYLING.BACKGROUND_COLOR.value
28+
),
2529
'border': '0px',
2630
'border-top': '0px solid rgb({0},{1},{2})'.format(*bg_color),
2731
},
@@ -34,7 +38,9 @@ def __init__(self, parent=None):
3438
},
3539
'QTabBar::tab:selected': {
3640
'color': 'rgb({0},{1},{2})'.format(*text_color),
37-
'background': 'rgb({0},{1},{2})'.format(*VIEWER_NAV_BG_COLOR),
41+
'background': 'rgb({0},{1},{2})'.format(
42+
*VIEWER_NAV_STYLING.BACKGROUND_COLOR.value
43+
),
3844
'border-top': '1px solid rgb({0},{1},{2})'
3945
.format(*NODE_STYLING.SELECTED_BORDER_COLOR.value),
4046
},

NodeGraphQt/widgets/node_widgets.py

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

4-
from NodeGraphQt.constants import VIEWER_GRID_COLOR, Z_VAL_NODE_WIDGET
4+
from NodeGraphQt.constants import VIEWER_STYLING, Z_VAL_NODE_WIDGET
55
from NodeGraphQt.errors import NodeWidgetError
66

77

@@ -329,7 +329,7 @@ def __init__(self, parent=None, name='', label='', text=''):
329329
'QLineEdit': {
330330
'background': 'rgba({0},{1},{2},20)'.format(*bg_color),
331331
'border': '1px solid rgb({0},{1},{2})'
332-
.format(*VIEWER_GRID_COLOR),
332+
.format(*VIEWER_STYLING.GRID_COLOR.value),
333333
'border-radius': '3px',
334334
'color': 'rgba({0},{1},{2},150)'.format(*text_color),
335335
'selection-background-color': 'rgba({0},{1},{2},100)'

NodeGraphQt/widgets/scene.py

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

4-
from NodeGraphQt.constants import (VIEWER_BG_COLOR,
5-
VIEWER_GRID_SIZE,
6-
VIEWER_GRID_COLOR,
7-
VIEWER_GRID_DOTS,
8-
VIEWER_GRID_LINES)
4+
from NodeGraphQt.constants import VIEWER_STYLING
95

106

117
class NodeScene(QtWidgets.QGraphicsScene):
128

139
def __init__(self, parent=None):
1410
super(NodeScene, self).__init__(parent)
15-
self._grid_mode = VIEWER_GRID_LINES
16-
self._grid_color = VIEWER_GRID_COLOR
17-
self._bg_color = VIEWER_BG_COLOR
11+
self._grid_mode = VIEWER_STYLING.GRID_DISPLAY_LINES.value
12+
self._grid_color = VIEWER_STYLING.GRID_COLOR.value
13+
self._bg_color = VIEWER_STYLING.BACKGROUND_COLOR.value
1814
self.setBackgroundBrush(QtGui.QColor(*self._bg_color))
1915

2016
def __repr__(self):
@@ -98,21 +94,25 @@ def drawBackground(self, painter, rect):
9894
painter.setRenderHint(QtGui.QPainter.Antialiasing, False)
9995
painter.setBrush(self.backgroundBrush())
10096

101-
if self._grid_mode is VIEWER_GRID_DOTS:
97+
if self._grid_mode is VIEWER_STYLING.GRID_DISPLAY_DOTS.value:
10298
pen = QtGui.QPen(QtGui.QColor(*self.grid_color), 0.65)
103-
self._draw_dots(painter, rect, pen, VIEWER_GRID_SIZE)
99+
self._draw_dots(painter, rect, pen, VIEWER_STYLING.GRID_SIZE.value)
104100

105-
elif self._grid_mode is VIEWER_GRID_LINES:
101+
elif self._grid_mode is VIEWER_STYLING.GRID_DISPLAY_LINES.value:
106102
zoom = self.viewer().get_zoom()
107103
if zoom > -0.5:
108104
pen = QtGui.QPen(QtGui.QColor(*self.grid_color), 0.65)
109-
self._draw_grid(painter, rect, pen, VIEWER_GRID_SIZE)
105+
self._draw_grid(
106+
painter, rect, pen, VIEWER_STYLING.GRID_SIZE.value
107+
)
110108

111109
color = QtGui.QColor(*self._bg_color).darker(150)
112110
if zoom < -0.0:
113111
color = color.darker(100 - int(zoom * 110))
114112
pen = QtGui.QPen(color, 0.65)
115-
self._draw_grid(painter, rect, pen, VIEWER_GRID_SIZE * 8)
113+
self._draw_grid(
114+
painter, rect, pen, VIEWER_STYLING.GRID_SIZE.value * 8
115+
)
116116

117117
painter.restore()
118118

@@ -148,7 +148,9 @@ def grid_mode(self):
148148
return self._grid_mode
149149

150150
@grid_mode.setter
151-
def grid_mode(self, mode=VIEWER_GRID_LINES):
151+
def grid_mode(self, mode=None):
152+
if mode is None:
153+
mode = VIEWER_STYLING.GRID_DISPLAY_LINES.value
152154
self._grid_mode = mode
153155

154156
@property

NodeGraphQt/widgets/tab_search.py

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
from Qt import QtCore, QtWidgets, QtGui
66

7-
from NodeGraphQt.constants import VIEWER_BG_COLOR, VIEWER_NAV_BG_COLOR
7+
from NodeGraphQt.constants import VIEWER_STYLING, VIEWER_NAV_STYLING
88

99

1010
class TabSearchCompleter(QtWidgets.QCompleter):
@@ -62,12 +62,15 @@ def __init__(self, parent=None):
6262
style_dict = {
6363
'QLineEdit': {
6464
'color': 'rgb({0},{1},{2})'.format(*text_color),
65-
'border': '1px solid rgb({0},{1},{2})'
66-
.format(*selected_color),
65+
'border': '1px solid rgb({0},{1},{2})'.format(
66+
*selected_color
67+
),
6768
'border-radius': '3px',
6869
'padding': '2px 4px',
6970
'margin': '2px 4px 8px 4px',
70-
'background': 'rgb({0},{1},{2})'.format(*VIEWER_NAV_BG_COLOR),
71+
'background': 'rgb({0},{1},{2})'.format(
72+
*VIEWER_NAV_STYLING.BACKGROUND_COLOR.value
73+
),
7174
'selection-background-color': 'rgba({0},{1},{2},200)'
7275
.format(*selected_color),
7376
}
@@ -110,7 +113,9 @@ def __init__(self, node_dict=None):
110113
style_dict = {
111114
'QMenu': {
112115
'color': 'rgb({0},{1},{2})'.format(*text_color),
113-
'background-color': 'rgb({0},{1},{2})'.format(*VIEWER_BG_COLOR),
116+
'background-color': 'rgb({0},{1},{2})'.format(
117+
*VIEWER_STYLING.BACKGROUND_COLOR.value
118+
),
114119
'border': '1px solid rgba({0},{1},{2},30)'.format(*text_color),
115120
'border-radius': '3px',
116121
},

NodeGraphQt/widgets/viewer_nav.py

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

3-
from NodeGraphQt.constants import (
4-
NODE_STYLING,
5-
VIEWER_NAV_BG_COLOR,
6-
VIEWER_NAV_ITEM_COLOR
7-
)
3+
from NodeGraphQt.constants import NODE_STYLING, VIEWER_NAV_STYLING
84

95

106
class NodeNavigationDelagate(QtWidgets.QStyledItemDelegate):
@@ -36,7 +32,7 @@ def paint(self, painter, option, index):
3632
painter.setRenderHint(QtGui.QPainter.Antialiasing, True)
3733

3834
# background.
39-
bg_color = QtGui.QColor(*VIEWER_NAV_ITEM_COLOR)
35+
bg_color = QtGui.QColor(*VIEWER_NAV_STYLING.ITEM_COLOR.value)
4036
itm_color = QtGui.QColor(80, 128, 123)
4137
if option.state & QtWidgets.QStyle.State_Selected:
4238
bg_color = bg_color.lighter(120)
@@ -109,7 +105,7 @@ def __init__(self, parent=None):
109105
# self.viewport().setAutoFillBackground(False)
110106
self.setStyleSheet(
111107
'QListView {{border: 0px;background-color: rgb({0},{1},{2});}}'
112-
.format(*VIEWER_NAV_BG_COLOR)
108+
.format(*VIEWER_NAV_STYLING.BACKGROUND_COLOR.value)
113109
)
114110

115111
self.setItemDelegate(NodeNavigationDelagate(self))

0 commit comments

Comments
 (0)