Skip to content

Commit

Permalink
Prevent node deletion when editing a parameter
Browse files Browse the repository at this point in the history
  • Loading branch information
PhilippThoelke committed Oct 9, 2024
1 parent d8a7baf commit a275fa0
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 17 deletions.
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -19,4 +19,4 @@ license = {file = "LICENSE"}
name = "goofi"
readme = {file = "README.md", content-type = "text/markdown"}
requires-python = ">=3.9"
version = "2.1.6"
version = "2.1.7"
5 changes: 4 additions & 1 deletion src/goofi/gui/events.py
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,10 @@ def key_release_callback(_, data, win):

def delete_selected_item(win):
"""Deletes the selected node or link."""
if any([dpg.is_item_active(item) for item in win.param_input_fields if dpg.does_item_exist(item)]):
# an input field is active, do not delete the selected node
return

for node in dpg.get_selected_nodes(win.node_editor):
win._remove_node(node)
for link in dpg.get_selected_links(win.node_editor):
Expand Down Expand Up @@ -311,7 +315,6 @@ def paste_nodes(win):
KEY_HANDLER_MAP = {
dpg.mvKey_Delete: delete_selected_item,
dpg.mvKey_Back: delete_selected_item,
# dpg.mvKey_X: delete_selected_item, # TODO: filter out when editing some text field
dpg.mvKey_Tab: create_node,
dpg.mvKey_Escape: escape,
dpg.mvKey_S: save_manager,
Expand Down
38 changes: 23 additions & 15 deletions src/goofi/gui/window.py
Original file line number Diff line number Diff line change
Expand Up @@ -266,12 +266,14 @@ def add_param(parent: int, group: str, name: str, param: Param, node: NodeRef) -
elif isinstance(param, FloatParam):
with dpg.group(horizontal=True) as input_group:
# parameter is a float
dpg.add_input_text(
width=50,
scientific=True,
default_value=str(param.value),
callback=param_updated,
user_data=(group, name, node, input_group, float),
Window().param_input_fields.append(
dpg.add_input_text(
width=50,
scientific=True,
default_value=str(param.value),
callback=param_updated,
user_data=(group, name, node, input_group, float),
)
)
dpg.add_slider_float(
default_value=param.value,
Expand All @@ -283,11 +285,13 @@ def add_param(parent: int, group: str, name: str, param: Param, node: NodeRef) -
elif isinstance(param, IntParam):
with dpg.group(horizontal=True) as input_group:
# parameter is an integer
dpg.add_input_text(
width=50,
default_value=str(param.value),
callback=param_updated,
user_data=(group, name, node, input_group, int),
Window().param_input_fields.append(
dpg.add_input_text(
width=50,
default_value=str(param.value),
callback=param_updated,
user_data=(group, name, node, input_group, int),
)
)
dpg.add_slider_int(
default_value=param.value,
Expand All @@ -300,10 +304,12 @@ def add_param(parent: int, group: str, name: str, param: Param, node: NodeRef) -
# parameter is a string
if param.options is None:
# `options` is not set, use an unconstrained text input
dpg.add_input_text(
default_value=param.value,
callback=param_updated,
user_data=(group, name, node),
Window().param_input_fields.append(
dpg.add_input_text(
default_value=param.value,
callback=param_updated,
user_data=(group, name, node),
)
)
else:
# `options` is set, use a dropdown menu
Expand Down Expand Up @@ -833,6 +839,7 @@ def _select_node(self, item: Optional[int]) -> None:
dpg.add_separator()

# populate parameters window
self.param_input_fields.clear()
with dpg.tab_bar():
for group in node_ref.params:
with dpg.tab(label=format_name(group)) as tab:
Expand Down Expand Up @@ -1044,6 +1051,7 @@ def _initialize(self, manager, width=1280, height=720):
self.node_clipboard = None
self.node_info_window = None
self.metadata_view = None
self.param_input_fields = []

# create window
self.window = dpg.add_window(
Expand Down

0 comments on commit a275fa0

Please sign in to comment.