Skip to content

Commit

Permalink
Fix Tool Template options button behaviour when 'No Tool' is selected
Browse files Browse the repository at this point in the history
  • Loading branch information
Manuel Marin committed May 21, 2018
1 parent 638940a commit 9b4c125
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 1 deletion.
8 changes: 7 additions & 1 deletion spinetoolbox/tool.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ def __init__(self, parent, name, description, project, tool_template, x, y):
self._widget.make_header_for_output_files()
self._widget.ui.comboBox_tool.setModel(self._parent.tool_template_model)
self._tool_template = None
self._tool_template_index = None
self.set_tool_template(tool_template)
# Set correct row selected in the comboBox
if not tool_template:
Expand Down Expand Up @@ -134,7 +135,12 @@ def set_tool_template(self, tool_template):
ToolTemplate or None if no Tool Template set for this Tool.
"""
self._tool_template = tool_template
self._tool_template_index = self._parent.tool_template_model.tool_template_index(tool_template.name)
if tool_template:
self._tool_template_index = self._parent.tool_template_model.tool_template_index(tool_template.name)
self._widget.ui.toolButton_tool_template_options.setEnabled(True)
else:
self._tool_template_index = None
self._widget.ui.toolButton_tool_template_options.setEnabled(False)
self.update_tool_ui()

def update_tool_ui(self):
Expand Down
6 changes: 6 additions & 0 deletions spinetoolbox/ui_main.py
Original file line number Diff line number Diff line change
Expand Up @@ -1043,6 +1043,8 @@ def edit_tool_template(self, index):
Args:
index (QModelIndex): Index of the item (from double-click or contex menu signal)
"""
if not index.isValid():
return
if index.row() == 0:
return # Don't do anything if No Tool option is double-clicked
tool_template = self.tool_template_model.tool_template(index.row())
Expand All @@ -1057,6 +1059,8 @@ def open_tool_template_file(self, index):
Args:
index (QModelIndex): Index of the item
"""
if not index.isValid():
return
tool_template = self.tool_template_model.tool_template(index.row())
file_path = tool_template.def_file_path
# Check if file exists first. openUrl may return True if file doesn't exist
Expand Down Expand Up @@ -1086,6 +1090,8 @@ def open_tool_main_program_file(self, index):
Args:
index (QModelIndex): Index of the item
"""
if not index.isValid():
return
tool = self.tool_template_model.tool_template(index.row())
file_path = os.path.join(tool.path, tool.includes[0])
# Check if file exists first. openUrl may return True if file doesn't exist
Expand Down

0 comments on commit 9b4c125

Please sign in to comment.