Skip to content

Commit

Permalink
Merge pull request #32642 from mantidproject/32638_close_sliceviewer_…
Browse files Browse the repository at this point in the history
…when_ws_deleted

Close sliceviewer when underlying ws deleted
  • Loading branch information
DavidFair authored Sep 28, 2021
2 parents 330e5a3 + 062b065 commit bf806d7
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 9 deletions.
17 changes: 10 additions & 7 deletions qt/python/mantidqt/widgets/sliceviewer/model.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ class SliceViewerModel:
def __init__(self, ws):
# reference to the workspace requested to be viewed
self._ws = ws
self._ws_name = ws.name()
if isinstance(ws, MatrixWorkspace):
if ws.getNumberHistograms() < 2:
raise ValueError("workspace must contain at least 2 spectrum")
Expand All @@ -53,10 +54,9 @@ def __init__(self, ws):
else:
raise ValueError("only works for MatrixWorkspace and MDWorkspace")

wsname = self.get_ws_name()
self._rebinned_name = wsname + '_svrebinned'
self._xcut_name, self._ycut_name = wsname + '_cut_x', wsname + '_cut_y'
self._roi_name = wsname + '_roi'
self._rebinned_name = self._ws_name + '_svrebinned'
self._xcut_name, self._ycut_name = self._ws_name + '_cut_x', self._ws_name + '_cut_y'
self._roi_name = self._ws_name + '_roi'

ws_type = self.get_ws_type()
if ws_type == WS_TYPE.MDE:
Expand Down Expand Up @@ -126,9 +126,12 @@ def can_support_dynamic_rebinning(self) -> bool:
return ws_type == WS_TYPE.MDE or (ws_type == WS_TYPE.MDH and self._get_ws().hasOriginalWorkspace(
0) and self._get_ws().getOriginalWorkspace(0).getNumDims() == self._get_ws().getNumDims())

def set_ws_name(self, new_name):
self._ws_name = new_name

def get_ws_name(self) -> str:
"""Return the name of the workspace being viewed"""
return self._ws.name()
return self._ws_name

def get_frame(self) -> SpecialCoordinateSystem:
"""Return the coordinate system of the workspace"""
Expand All @@ -139,7 +142,7 @@ def get_title(self, ws_name=None) -> str:
of the model's workspace if none supplied.
"""
if not ws_name:
ws_name = self.get_ws_name()
ws_name = self._ws_name
return f'Sliceviewer - {ws_name}'

def get_ws_MDE(self,
Expand Down Expand Up @@ -497,7 +500,7 @@ def export_pixel_cut_to_workspace_matrix(self, slicepoint, bin_params, pos: tupl
return help_msg

def workspace_equals(self, ws_name):
return str(self._get_ws()) == ws_name
return self._ws_name == ws_name

# private api
def _get_ws(self):
Expand Down
5 changes: 3 additions & 2 deletions qt/python/mantidqt/widgets/sliceviewer/presenter.py
Original file line number Diff line number Diff line change
Expand Up @@ -439,11 +439,12 @@ def refresh_view(self):
ws.unlock()

def rename_workspace(self, old_name, new_name):
if str(self.model._get_ws()) == old_name:
if self.model.get_ws_name() == old_name:
self.model.set_ws_name(new_name)
self.view.emit_rename(self.model.get_title(new_name))

def delete_workspace(self, ws_name):
if ws_name == str(self.model._ws):
if ws_name == self.model.get_ws_name():
self.view.emit_close()

def ADS_cleared(self):
Expand Down

0 comments on commit bf806d7

Please sign in to comment.