Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

clean up context menu #76

Merged
merged 1 commit into from
Jun 21, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
47 changes: 10 additions & 37 deletions src/QuiltiX/hotkeys/hotkey_functions.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,48 +42,20 @@ def layout_v_mode(graph):
graph.set_layout_direction(1)


def open_session(graph):
"""
Prompts a file open dialog to load a session.
"""
current = graph.current_session()
file_path = graph.load_dialog(current)
if file_path:
graph.load_session(file_path)
def load_mtlx_file(graph):
graph.get_root_graph().widget.parent().load_mx_file_triggered()


def import_session(graph):
"""
Prompts a file open dialog to load a session.
"""
current = graph.current_session()
file_path = graph.load_dialog(current)
if file_path:
graph.import_session(file_path)
def load_mtlx_data(graph):
graph.get_root_graph().widget.parent().load_mx_data_triggered()


def save_session(graph):
"""
Prompts a file save dialog to serialize a session if required.
"""
current = graph.current_session()
if current:
graph.save_session(current)
msg = 'Session layout saved:\n{}'.format(current)
viewer = graph.viewer()
viewer.message_dialog(msg, title='Session Saved')
else:
save_session_as(graph)
def save_mtlx(graph):
graph.get_root_graph().widget.parent().save_mx_file_triggered()


def save_session_as(graph):
"""
Prompts a file save dialog to serialize a session.
"""
current = graph.current_session()
file_path = graph.save_dialog(current)
if file_path:
graph.save_session(file_path)
def save_mtlx_as(graph):
graph.get_root_graph().widget.parent().save_mx_file_as_triggered()


def new_session(graph):
Expand Down Expand Up @@ -253,7 +225,8 @@ def toggle_node_search(graph):
"""
show/hide the node search widget.
"""
graph.toggle_node_search()
graph._viewer.tab_search_set_nodes(graph._node_factory.names)
graph._viewer.tab_search_toggle()


# custom functions
Expand Down
88 changes: 26 additions & 62 deletions src/QuiltiX/hotkeys/hotkeys.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,30 +5,30 @@
"items":[
{
"type":"command",
"label":"Open...",
"label":"Load MaterialX File...",
"file":"../examples/hotkeys/hotkey_functions.py",
"function_name":"open_session",
"function_name":"load_mtlx_file",
"shortcut":"QtGui.QKeySequence.Open"
},
{
"type":"command",
"label":"Import...",
"label":"Load MaterialX Data...",
"file":"../examples/hotkeys/hotkey_functions.py",
"function_name":"import_session",
"function_name":"load_mtlx_data",
"shortcut":""
},
{
"type":"command",
"label":"Save...",
"label":"Save MaterialX",
"file":"../examples/hotkeys/hotkey_functions.py",
"function_name":"save_session",
"function_name":"save_mtlx",
"shortcut":"QtGui.QKeySequence.Save"
},
{
"type":"command",
"label":"Save As...",
"label":"Save MaterialX As...",
"file":"../examples/hotkeys/hotkey_functions.py",
"function_name":"save_session_as",
"function_name":"save_mtlx_as",
"shortcut":"Ctrl+Shift+S"
}
]
Expand Down Expand Up @@ -151,54 +151,28 @@
},
{
"type":"menu",
"label":"&Graph",
"label":"&Background",
"items":[
{
"type":"menu",
"label":"&Background",
"items":[
{
"type":"command",
"label":"None",
"file":"../examples/hotkeys/hotkey_functions.py",
"function_name":"bg_grid_none",
"shortcut":"Alt+1"
},
{
"type":"command",
"label":"Lines",
"file":"../examples/hotkeys/hotkey_functions.py",
"function_name":"bg_grid_lines",
"shortcut":"Alt+2"
},
{
"type":"command",
"label":"Dots",
"file":"../examples/hotkeys/hotkey_functions.py",
"function_name":"bg_grid_dots",
"shortcut":"Alt+3"
}
]
"type":"command",
"label":"None",
"file":"../examples/hotkeys/hotkey_functions.py",
"function_name":"bg_grid_none",
"shortcut":"Alt+1"
},
{
"type":"command",
"label":"Lines",
"file":"../examples/hotkeys/hotkey_functions.py",
"function_name":"bg_grid_lines",
"shortcut":"Alt+2"
},
{
"type":"menu",
"label":"&Layout",
"items":[
{
"type":"command",
"label":"Horizontal",
"file":"../examples/hotkeys/hotkey_functions.py",
"function_name":"layout_h_mode",
"shortcut":"Shift+1"
},
{
"type":"command",
"label":"Vertical",
"file":"../examples/hotkeys/hotkey_functions.py",
"function_name":"layout_v_mode",
"shortcut":"Shift+2"
}
]
"type":"command",
"label":"Dots",
"file":"../examples/hotkeys/hotkey_functions.py",
"function_name":"bg_grid_dots",
"shortcut":"Alt+3"
}
]
},
Expand Down Expand Up @@ -229,16 +203,6 @@
"file":"../examples/hotkeys/hotkey_functions.py",
"function_name":"layout_graph_down",
"shortcut":"Ctrl+L"
},
{
"type":"separator"
},
{
"type":"command",
"label":"Expand Group Node",
"file":"../examples/hotkeys/hotkey_functions.py",
"function_name":"expand_group_node",
"shortcut":"Return"
}
]
},
Expand Down
24 changes: 22 additions & 2 deletions src/QuiltiX/quiltix.py
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,11 @@ def init_ui(self):
lambda: self.apply_material("volume", selection=True),
node_type="Material.Volumematerial",
)
self.expand_cmd = node_menu.add_command(
"Expand Nodegraph",
self.expand_selected_nodegraph,
node_type="Other.QxGroupNode",
)
self.save_def_cmd = node_menu.add_command(
"Save as new definition...",
self.save_as_definition,
Expand Down Expand Up @@ -273,6 +278,11 @@ def apply_material(self, mat_type, selection=False):

self.stage_ctrl.apply_material_to_prims(material_name, prims)

def expand_selected_nodegraph(self):
action = self.expand_cmd.qaction
node = self.qx_node_graph.get_node_by_id(action.node_id)
node.expand()

def save_as_definition(self):
action = self.save_def_cmd.qaction
node = self.qx_node_graph.get_node_by_id(action.node_id)
Expand All @@ -296,18 +306,22 @@ def init_menu_bar(self):
# endregion Tabs

# region File
load_mx_file = QAction("Load MaterialX file...", self)
load_mx_file = QAction("Load MaterialX File...", self)
load_mx_file.triggered.connect(self.load_mx_file_triggered)
self.file_menu.addAction(load_mx_file)

load_mx_file = QAction("Load MaterialX data...", self)
load_mx_file = QAction("Load MaterialX Data...", self)
load_mx_file.triggered.connect(self.load_mx_data_triggered)
self.file_menu.addAction(load_mx_file)

save_mx_file = QAction("Save MaterialX...", self)
save_mx_file.triggered.connect(self.save_mx_file_triggered)
self.file_menu.addAction(save_mx_file)

save_mx_file_as = QAction("Save MaterialX As...", self)
save_mx_file_as.triggered.connect(self.save_mx_file_as_triggered)
self.file_menu.addAction(save_mx_file_as)

self.file_menu.addSeparator()

load_geo = QAction("Load Geometry...", self)
Expand Down Expand Up @@ -541,6 +555,12 @@ def load_mx_data_triggered(self):
self.qx_node_graph.load_graph_from_mx_data(xml_str)

def save_mx_file_triggered(self):
if os.path.exists(self.current_filepath):
self.qx_node_graph.save_graph_as_mx_file(self.current_filepath)
else:
self.save_mx_file_as_triggered()

def save_mx_file_as_triggered(self):
start_path = self.mx_selection_path
if not start_path:
start_path = self.geometry_selection_path
Expand Down