Skip to content

Commit

Permalink
Add show data to group peak workspace
Browse files Browse the repository at this point in the history
  • Loading branch information
MohamedAlmaki committed Apr 15, 2024
1 parent b34215c commit d8ec136
Show file tree
Hide file tree
Showing 3 changed files with 48 additions and 6 deletions.
13 changes: 13 additions & 0 deletions qt/applications/workbench/workbench/plugins/workspacewidget.py
Expand Up @@ -288,6 +288,19 @@ def _do_show_data(self, names):
import matplotlib.pyplot

parent, flags = get_window_config()
# Process group peak workspaces first and remove them from the list
for ws in self._ads.retrieveGroupPeaksWorkspaces(names):
try:
TableWorkspaceDisplay.supports(ws)
presenter = TableWorkspaceDisplay(ws, plot=matplotlib.pyplot, parent=parent, window_flags=flags, group=True)
presenter.show_view()
names.remove(ws.name())
except ValueError as e:
logger.error(str(e))
logger.error(
"Could not open workspace: {0} with neither " "MatrixWorkspaceDisplay nor TableWorkspaceDisplay." "".format(ws.name())
)

for ws in self._ads.retrieveWorkspaces(names, unrollGroups=True):
try:
MatrixWorkspaceDisplay.supports(ws)
Expand Down
Expand Up @@ -16,6 +16,7 @@
from mantidqt.widgets.workspacedisplay.status_bar_view import StatusBarView
from mantidqt.widgets.workspacedisplay.table.error_column import ErrorColumn
from mantidqt.widgets.workspacedisplay.table.model import TableWorkspaceDisplayModel
from mantidqt.widgets.workspacedisplay.table.group_model import GroupTableWorkspaceDisplayModel
from mantidqt.widgets.workspacedisplay.table.plot_type import PlotType
from mantidqt.widgets.workspacedisplay.table.presenter_batch import TableWorkspaceDataPresenterBatch
from mantidqt.widgets.workspacedisplay.table.presenter_standard import TableWorkspaceDataPresenterStandard
Expand Down Expand Up @@ -58,6 +59,7 @@ def __init__(
window_width=600,
window_height=400,
batch=False,
group=False,
):
"""
Creates a display for the provided workspace.
Expand All @@ -73,7 +75,7 @@ def __init__(
:param ads_observer: ADS observer to be used by the presenter. If not provided the default
one is used. Mainly intended for testing.
"""
view, model = self.create_table(ws, parent, window_flags, model, view, batch)
view, model = self.create_table(ws, parent, window_flags, model, view, batch, group)
self.view = view
self.model = model
self.name = name if name else model.get_name()
Expand All @@ -95,6 +97,7 @@ def __init__(

self.parent = parent
self.plot = plot
self.group = group

self.ads_observer = ads_observer if ads_observer else WorkspaceDisplayADSObserver(self)

Expand All @@ -103,8 +106,10 @@ def __init__(
def show_view(self):
self.container.show()

def create_table(self, ws, parent, window_flags, model, view, batch):
if batch:
def create_table(self, ws, parent, window_flags, model, view, batch, group):
if group:
view, model = self._create_table_group(ws, parent, window_flags, view, model)
elif batch:
view, model = self._create_table_batch(ws, parent, window_flags, view, model)
else:
view, model = self._create_table_standard(ws, parent, window_flags, view, model)
Expand All @@ -126,14 +131,26 @@ def _create_table_batch(self, ws, parent, window_flags, view, model):
self.presenter = TableWorkspaceDataPresenterBatch(model, view)
return view, model

def _create_table_group(self, ws, parent, window_flags, view, model):
model = model if model is not None else GroupTableWorkspaceDisplayModel(ws)
view = view if view else TableWorkspaceDisplayView(presenter=self, parent=parent, window_flags=window_flags)
self.presenter = TableWorkspaceDataPresenterStandard(model, view)
return view, model

@classmethod
def supports(cls, ws):
"""
Checks that the provided workspace is supported by this display.
:param ws: Workspace to be checked for support
:raises ValueError: if the workspace is not supported
"""
return TableWorkspaceDisplayModel.supports(ws)
try:
TableWorkspaceDisplayModel.supports(ws)
except ValueError:
try:
GroupTableWorkspaceDisplayModel.supports(ws)
except ValueError:
raise ValueError("The workspace type is not supported: {0}".format(ws))

def replace_workspace(self, workspace_name, workspace):
if self.presenter.model.workspace_equals(workspace_name) and not self.presenter.model.block_model_replace:
Expand All @@ -142,6 +159,12 @@ def replace_workspace(self, workspace_name, workspace):
self.presenter.load_data(self.presenter.view)
self.presenter.view.blockSignals(False)

if self.group and workspace_name in self.model.ws.getNames() and not self.presenter.model.block_model_replace:
self.presenter.view.blockSignals(True)
self.presenter.model = GroupTableWorkspaceDisplayModel(self.model.ws)
self.presenter.load_data(self.presenter.view)
self.presenter.view.blockSignals(False)

def action_copy_cells(self):
self.copy_cells(self.presenter.view)

Expand Down Expand Up @@ -196,7 +219,8 @@ def action_statistics_on_columns(self):
return

stats = self.presenter.model.get_statistics(selected_columns)
TableWorkspaceDisplay(stats, parent=self.parent, name="Column Statistics of {}".format(self.name))
if not self.group:
TableWorkspaceDisplay(stats, parent=self.parent, name="Column Statistics of {}".format(self.name))

def action_hide_selected(self):
try:
Expand Down
Expand Up @@ -336,7 +336,12 @@ void WorkspaceTreeWidgetSimple::addWorkspaceGroupActions(QMenu *menu, const Mant
menu->addSeparator();
}

if (containsMatrixWorkspace || containsPeaksWorkspace) {
if (containsMatrixWorkspace) {
menu->addAction(m_showDetectors);
}

if (containsPeaksWorkspace) {
menu->addAction(m_showData);
menu->addAction(m_showDetectors);
}
}
Expand Down

0 comments on commit d8ec136

Please sign in to comment.