Skip to content

Commit

Permalink
relative path fix
Browse files Browse the repository at this point in the history
  • Loading branch information
jchanvfx committed Oct 18, 2022
1 parent 1b488ff commit fab1232
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 3 deletions.
14 changes: 12 additions & 2 deletions NodeGraphQt/base/graph.py
Original file line number Diff line number Diff line change
Expand Up @@ -721,6 +721,8 @@ def _deserialize_context_menu(self, menu, menu_data):
import sys
import importlib.util

nodes_menu = self.get_context_menu('nodes')

def build_menu_command(menu, data):
"""
Create menu command from serialized data.
Expand All @@ -745,7 +747,12 @@ def build_menu_command(menu, data):
cmd_func = getattr(mod, data['function_name'])
cmd_name = data.get('label') or '<command>'
cmd_shortcut = data.get('shortcut')
menu.add_command(cmd_name, cmd_func, cmd_shortcut)
cmd_kwargs = {'func': cmd_func, 'shortcut': cmd_shortcut}

if menu == nodes_menu and data.get('node_type'):
cmd_kwargs['node_type'] = data['node_type']

menu.add_command(name=cmd_name, **cmd_kwargs)

if isinstance(menu_data, dict):
item_type = menu_data.get('type')
Expand Down Expand Up @@ -780,7 +787,8 @@ def set_context_menu(self, menu_name, data):
'label': 'test command',
'file': '../path/to/my/test_module.py',
'function': 'run_test',
'shortcut': 'Ctrl+b'
'shortcut': 'Ctrl+b',
'node_type': 'nodeGraphQt.nodes.MyNodeClass'
},
]
Expand All @@ -806,6 +814,8 @@ def set_context_menu_from_file(self, file_path, menu=None):
menu (str): name of the parent context menu to populate under.
file_path (str): serialized menu commands json file.
"""
file_path = os.path.abspath(file_path)

menu = menu or 'graph'
if not os.path.isfile(file_path):
return
Expand Down
4 changes: 3 additions & 1 deletion examples/basic_example.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,9 @@

# create graph controller.
graph = NodeGraph()
graph.set_context_menu_from_file('/Users/jchan/PycharmProjects/NodeGraphQt/examples/hotkeys/hotkeys.json')

# set up context menu for the node graph.
graph.set_context_menu_from_file('../examples/hotkeys/hotkeys.json')

# registered example nodes.
graph.register_nodes([
Expand Down

0 comments on commit fab1232

Please sign in to comment.