Skip to content

Commit fab1232

Browse files
committed
relative path fix
1 parent 1b488ff commit fab1232

File tree

2 files changed

+15
-3
lines changed

2 files changed

+15
-3
lines changed

NodeGraphQt/base/graph.py

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -721,6 +721,8 @@ def _deserialize_context_menu(self, menu, menu_data):
721721
import sys
722722
import importlib.util
723723

724+
nodes_menu = self.get_context_menu('nodes')
725+
724726
def build_menu_command(menu, data):
725727
"""
726728
Create menu command from serialized data.
@@ -745,7 +747,12 @@ def build_menu_command(menu, data):
745747
cmd_func = getattr(mod, data['function_name'])
746748
cmd_name = data.get('label') or '<command>'
747749
cmd_shortcut = data.get('shortcut')
748-
menu.add_command(cmd_name, cmd_func, cmd_shortcut)
750+
cmd_kwargs = {'func': cmd_func, 'shortcut': cmd_shortcut}
751+
752+
if menu == nodes_menu and data.get('node_type'):
753+
cmd_kwargs['node_type'] = data['node_type']
754+
755+
menu.add_command(name=cmd_name, **cmd_kwargs)
749756

750757
if isinstance(menu_data, dict):
751758
item_type = menu_data.get('type')
@@ -780,7 +787,8 @@ def set_context_menu(self, menu_name, data):
780787
'label': 'test command',
781788
'file': '../path/to/my/test_module.py',
782789
'function': 'run_test',
783-
'shortcut': 'Ctrl+b'
790+
'shortcut': 'Ctrl+b',
791+
'node_type': 'nodeGraphQt.nodes.MyNodeClass'
784792
},
785793
786794
]
@@ -806,6 +814,8 @@ def set_context_menu_from_file(self, file_path, menu=None):
806814
menu (str): name of the parent context menu to populate under.
807815
file_path (str): serialized menu commands json file.
808816
"""
817+
file_path = os.path.abspath(file_path)
818+
809819
menu = menu or 'graph'
810820
if not os.path.isfile(file_path):
811821
return

examples/basic_example.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,9 @@
2626

2727
# create graph controller.
2828
graph = NodeGraph()
29-
graph.set_context_menu_from_file('/Users/jchan/PycharmProjects/NodeGraphQt/examples/hotkeys/hotkeys.json')
29+
30+
# set up context menu for the node graph.
31+
graph.set_context_menu_from_file('../examples/hotkeys/hotkeys.json')
3032

3133
# registered example nodes.
3234
graph.register_nodes([

0 commit comments

Comments
 (0)