Skip to content

Commit bddcb70

Browse files
committed
docs cleanup & func cleanup
1 parent 73261b7 commit bddcb70

File tree

12 files changed

+148
-119
lines changed

12 files changed

+148
-119
lines changed

NodeGraphQt/__init__.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@
4242
__module_name__ = 'NodeGraphQt'
4343
__url__ = 'https://github.com/jchanvfx/NodeGraphQt'
4444

45+
from .base.actions import setup_context_menu
4546
from .base.graph import NodeGraph
4647
from .base.node import NodeObject, Node, Backdrop
4748
from .base.port import Port

NodeGraphQt/base/actions.py

Lines changed: 20 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -6,35 +6,36 @@
66

77
def setup_context_menu(graph):
88
"""
9-
build the default node graph context menu.
9+
convenience function that populates the node graphs context menu
10+
with some default menus and commands.
1011
1112
Args:
12-
graph (NodeGraphQt.NodeGraph): node graph controller.
13+
graph (NodeGraphQt.NodeGraph): node graph controller class.
1314
"""
1415
root_menu = graph.context_menu()
1516

1617
file_menu = root_menu.add_menu('&File')
1718
edit_menu = root_menu.add_menu('&Edit')
1819

19-
# File menu.
20+
# create "File" menu.
2021
file_menu.add_command('Open...',
21-
lambda: open_session(graph),
22+
lambda: _open_session(graph),
2223
QtGui.QKeySequence.Open)
2324
file_menu.add_command('Save...',
24-
lambda: save_session(graph),
25+
lambda: _save_session(graph),
2526
QtGui.QKeySequence.Save)
2627
file_menu.add_command('Save As...',
27-
lambda: save_session_as(graph),
28+
lambda: _save_session_as(graph),
2829
'Ctrl+Shift+s')
29-
file_menu.add_command('Clear', lambda: clear_session(graph))
30+
file_menu.add_command('Clear', lambda: _clear_session(graph))
3031

3132
file_menu.add_separator()
3233

33-
file_menu.add_command('Zoom In', lambda: zoom_in(graph), '=')
34-
file_menu.add_command('Zoom Out', lambda: zoom_out(graph), '-')
34+
file_menu.add_command('Zoom In', lambda: _zoom_in(graph), '=')
35+
file_menu.add_command('Zoom Out', lambda: _zoom_out(graph), '-')
3536
file_menu.add_command('Reset Zoom', graph.reset_zoom, 'h')
3637

37-
# Edit menu.
38+
# create "Edit" menu.
3839
undo_actn = graph.undo_stack().createUndoAction(graph.viewer(), '&Undo')
3940
if LooseVersion(QtCore.qVersion()) >= LooseVersion('5.10'):
4041
undo_actn.setShortcutVisibleInContextMenu(True)
@@ -48,7 +49,7 @@ def setup_context_menu(graph):
4849
edit_menu.qmenu.addAction(redo_actn)
4950

5051
edit_menu.add_separator()
51-
edit_menu.add_command('Clear Undo History', lambda: clear_undo(graph))
52+
edit_menu.add_command('Clear Undo History', lambda: _clear_undo(graph))
5253
edit_menu.add_separator()
5354

5455
edit_menu.add_command('Copy', graph.copy_nodes, QtGui.QKeySequence.Copy)
@@ -78,7 +79,7 @@ def setup_context_menu(graph):
7879
# --- menu command functions. ---
7980

8081

81-
def zoom_in(graph):
82+
def _zoom_in(graph):
8283
"""
8384
Set the node graph to zoom in by 0.1
8485
@@ -89,7 +90,7 @@ def zoom_in(graph):
8990
graph.set_zoom(zoom)
9091

9192

92-
def zoom_out(graph):
93+
def _zoom_out(graph):
9394
"""
9495
Set the node graph to zoom in by 0.1
9596
@@ -100,7 +101,7 @@ def zoom_out(graph):
100101
graph.set_zoom(zoom)
101102

102103

103-
def open_session(graph):
104+
def _open_session(graph):
104105
"""
105106
Prompts a file open dialog to load a session.
106107
@@ -114,7 +115,7 @@ def open_session(graph):
114115
graph.load_session(file_path)
115116

116117

117-
def save_session(graph):
118+
def _save_session(graph):
118119
"""
119120
Prompts a file save dialog to serialize a session if required.
120121
@@ -128,10 +129,10 @@ def save_session(graph):
128129
viewer = graph.viewer()
129130
viewer.message_dialog(msg, title='Session Saved')
130131
else:
131-
save_session_as(graph)
132+
_save_session_as(graph)
132133

133134

134-
def save_session_as(graph):
135+
def _save_session_as(graph):
135136
"""
136137
Prompts a file save dialog to serialize a session.
137138
@@ -145,7 +146,7 @@ def save_session_as(graph):
145146
graph.save_session(file_path)
146147

147148

148-
def clear_session(graph):
149+
def _clear_session(graph):
149150
"""
150151
Prompts a warning dialog to clear the node graph session.
151152
@@ -157,7 +158,7 @@ def clear_session(graph):
157158
graph.clear_session()
158159

159160

160-
def clear_undo(graph):
161+
def _clear_undo(graph):
161162
"""
162163
Prompts a warning dialog to clear undo.
163164

NodeGraphQt/base/graph.py

Lines changed: 10 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ class NodeGraph(QtCore.QObject):
2424
base node graph controller.
2525
2626
Args:
27-
default_actions(bool): true to initialize with default context menu actions.
27+
tab_search_key(str): hotkey for the tab search widget (default: "tab").
2828
"""
2929

3030
#: signal for when a node has been created in the node graph.
@@ -36,14 +36,19 @@ class NodeGraph(QtCore.QObject):
3636
#: signal for when drop data has been added to the graph.
3737
data_dropped = QtCore.Signal(QtCore.QMimeData, QtCore.QPoint)
3838

39-
def __init__(self, parent=None, default_actions=True):
39+
def __init__(self, parent=None, tab_search_key='tab'):
4040
super(NodeGraph, self).__init__(parent)
4141
self.setObjectName('NodeGraphQt')
4242
self._model = NodeGraphModel()
4343
self._viewer = NodeViewer()
4444
self._vendor = NodeVendor()
4545
self._undo_stack = QUndoStack(self)
46-
self._init_actions(default_actions)
46+
47+
tab = QAction('Search Nodes', self)
48+
tab.setShortcut(tab_search_key)
49+
tab.triggered.connect(self._toggle_tab_search)
50+
self._viewer.addAction(tab)
51+
4752
self._wire_signals()
4853

4954
def _wire_signals(self):
@@ -56,17 +61,6 @@ def _wire_signals(self):
5661
self._viewer.node_selected.connect(self._on_node_selected)
5762
self._viewer.data_dropped.connect(self._on_node_data_dropped)
5863

59-
def _init_actions(self, default_actions=False):
60-
# setup tab search shortcut.
61-
tab = QAction('Search Nodes', self)
62-
tab.setShortcut('tab')
63-
tab.triggered.connect(self._toggle_tab_search)
64-
self._viewer.addAction(tab)
65-
66-
# setup default context menu.
67-
if default_actions:
68-
setup_context_menu(self)
69-
7064
def _toggle_tab_search(self):
7165
"""
7266
toggle the tab search widget.
@@ -88,11 +82,10 @@ def _on_node_selected(self, node_id):
8882
def _on_node_data_dropped(self, data, pos):
8983
"""
9084
called when data has been dropped on the viewer.
91-
(emits the node type and the x,y position where the data was dropped)
9285
9386
Args:
9487
data (QtCore.QMimeData): mime data.
95-
pos (QtCore.QPoint): x, y scene position relative to the cursor.
88+
pos (QtCore.QPoint): scene position relative to the drop.
9689
"""
9790
self.data_dropped.emit(data, pos)
9891

@@ -204,7 +197,7 @@ def undo_stack(self):
204197
def clear_undo_stack(self):
205198
"""
206199
Clears the undo stack.
207-
(convenience function to :meth:`NodeGraph.undo_stact().clear`)
200+
(convenience function to :meth:`NodeGraph.undo_stack().clear`)
208201
"""
209202
self._undo_stack.clear()
210203

NodeGraphQt/base/menu.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,7 @@ def add_command(self, name, func=None, shortcut=None):
104104
shortcut (str): shotcut key.
105105
106106
Returns:
107-
107+
NodeGraphQt.ContextMenuCommand: the appended command.
108108
"""
109109
action = QtWidgets.QAction(name, self.__viewer)
110110
if LooseVersion(QtCore.qVersion()) >= LooseVersion('5.10'):

NodeGraphQt/constants.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@
4444
#: The draw border color for selected nodes.
4545
NODE_SEL_BORDER_COLOR = (254, 207, 42, 255)
4646

47-
# === NODE PROPERTY WIDGET TYPES ===
47+
# === NODE PROPERTY TYPES ===
4848

4949
#: Property type will hidden in the properties bin (default).
5050
NODE_PROP = 0
@@ -63,15 +63,15 @@
6363
#: Property type represented with a Slider widget in the properties bin.
6464
NODE_PROP_SLIDER = 7
6565

66-
# === NODE GRAPH VIEWER DEFAULTS ===
66+
# === NODE VIEWER DEFAULTS ===
6767

6868
#: Node graph background color.
6969
VIEWER_BG_COLOR = (35, 35, 35)
70-
#: Node graph grid color.
7170
VIEWER_GRID_COLOR = (45, 45, 45)
72-
#: Node graph grid enabled.
7371
VIEWER_GRID_OVERLAY = True
7472

73+
SCENE_AREA = 8000.0
74+
7575
# === GRAPH PATHS ===
7676

7777
BASE_PATH = os.path.dirname(os.path.abspath(__file__))

0 commit comments

Comments
 (0)