Skip to content

Commit

Permalink
Merge pull request #37524 from mantidproject/37040-dragging-text-onto…
Browse files Browse the repository at this point in the history
…-plot-not-handled-well

Fix Issue 37040: Dragging text onto plot not handled well
  • Loading branch information
SilkeSchomann committed Jun 25, 2024
2 parents 570111c + 9a1eaba commit 271f9b2
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 3 deletions.
1 change: 1 addition & 0 deletions docs/source/release/v6.11.0/Workbench/Bugfixes/37040.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
- Fixed issue with dragging text onto the plot: Previously, dragging invalid text onto the plot resulted in unexpected behavior Now, when invalid text is dragged onto the plot, a warning is displayed to the user indicating that the workspace is invalid.
11 changes: 9 additions & 2 deletions qt/applications/workbench/workbench/plotting/figurewindow.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,16 +33,23 @@ def _validate_workspaces(names: List[str]) -> List[bool]:
ads = AnalysisDataServiceImpl.Instance()
has_multiple_bins = []
for name in names:
ws = None
result = None
ws = ads.retrieve(name)

try:
ws = ads.retrieve(name)
except KeyError:
# Handle the case where the workspace name does not exist
mantid.kernel.logger.warning(f"Workspace '{name}' does not exist.")
result = False
if isinstance(ws, WorkspaceGroup):
result = all(_validate_workspaces(ws.getNames()))
elif isinstance(ws, MatrixWorkspace):
try:
result = ws.blocksize() > 1
except RuntimeError:
# blocksize() implementation in Workspace2D and EventWorkspace can throw an error if histograms are not equal
for i in ws.getNumberHistograms():
for i in range(ws.getNumberHistograms()):
if ws.y(i).size() > 1:
result = True
break
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
from unittest.mock import Mock, patch
from mantid.simpleapi import CreateWorkspace
from mantidqt.utils.qt.testing import start_qapplication
from workbench.plotting.figurewindow import FigureWindow
from workbench.plotting.figurewindow import FigureWindow, _validate_workspaces

matplotlib.use("Qt5Agg")
import matplotlib.pyplot as plt
Expand Down Expand Up @@ -51,6 +51,13 @@ def test_drag_and_drop_wont_plot_a_single_binned_workspace(self):
ax = self._drop_workspace("single_bin_ws")
self.assertEqual(1, len(ax.lines))

def test_validate_workspaces_does_not_raise_keyerror_for_non_existent_workspace(self):
try:
result = _validate_workspaces(["non_existent_workspace", "second_non_existent_workspace"])
self.assertEqual(result, [False, False])
except KeyError:
self.fail("KeyError was raised for non-existent workspaces.")

def _drop_workspace(self, ws_name: str):
ax = self.fig.get_axes()[1]
dpi_ratio = self.fig.canvas.device_pixel_ratio
Expand Down

0 comments on commit 271f9b2

Please sign in to comment.