Skip to content

Commit

Permalink
fix bug that deletes .py file after a failed model check on a .c file…
Browse files Browse the repository at this point in the history
… by removing os.remove(). allow user to load .c models into editor even if .c file fails model checks
  • Loading branch information
tsole0 committed Jun 27, 2024
1 parent eb3dee0 commit 14d1e0a
Showing 1 changed file with 6 additions and 8 deletions.
14 changes: 6 additions & 8 deletions src/sas/qtgui/Utilities/TabbedModelEditor.py
Original file line number Diff line number Diff line change
Expand Up @@ -193,18 +193,19 @@ def loadFile(self, filename):
# Name the tab with .py filename
self.tabWidget.setTabText(0, display_name)

# In case previous model was incorrect, change the frame colours back
self.editor_widget.txtEditor.setStyleSheet("")
self.editor_widget.txtEditor.setToolTip("")

# Check the validity of loaded model if the model is python
if self.is_python:
error_line = self.checkModel(self.filename)
if error_line > 0:
# select bad line
cursor = QtGui.QTextCursor(self.editor_widget.txtEditor.document().findBlockByLineNumber(error_line-1))
self.editor_widget.txtEditor.setTextCursor(cursor)
return

# In case previous model was incorrect, change the frame colours back
self.editor_widget.txtEditor.setStyleSheet("")
self.editor_widget.txtEditor.setToolTip("")
# Do not return because we still want to load C file if it exists
QtWidgets.QMessageBox.warning(self, "Model check failed", "The loaded model contains errors. Please correct all errors before using model.")

# See if there is filename.c present
c_path = self.filename.parent / self.filename.name.replace(".py", ".c")
Expand Down Expand Up @@ -381,9 +382,6 @@ def checkModel(self, full_path):
# GuiUtils.Communicate.statusBarUpdateSignal.emit("Model check failed")
self.parent.communicate.statusBarUpdateSignal.emit("Model check failed")

# Remove the file so it is not being loaded on refresh
os.remove(full_path)

# Put a thick, red border around the editor.
from sas.qtgui.Utilities.CodeEditor import QCodeEditor

Expand Down

0 comments on commit 14d1e0a

Please sign in to comment.