Skip to content

Commit

Permalink
Re #6151 move UI components to API2
Browse files Browse the repository at this point in the history
  • Loading branch information
mdoucet committed Dec 20, 2012
1 parent b48c1c4 commit cebb87e
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 33 deletions.
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
import sys
# Check whether Mantid is available
try:
from MantidFramework import *
mtd.initialise()
from mantidsimple import *
import mantid.simpleapi as api
HAS_MANTID = True
except:
HAS_MANTID = False
Expand All @@ -25,10 +24,10 @@ def __init__(self, data_file, workspace_name=None):
else:
self.data_ws = str(workspace_name)
try:
LoadEventNexus(Filename=data_file, OutputWorkspace=workspace_name)
api.LoadEventNexus(Filename=data_file, OutputWorkspace=workspace_name)
except:
self.errors.append("Error loading data file as Nexus event file:\n%s" % sys.exc_value)
LoadNexus(Filename=data_file, OutputWorkspace=workspace_name)
api.Load(Filename=data_file, OutputWorkspace=workspace_name)
self.errors = []
except:
self.data_ws = None
Expand Down
27 changes: 12 additions & 15 deletions Code/Mantid/scripts/Interface/reduction_gui/widgets/base_widget.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,9 @@
IS_IN_MANTIDPLOT = False
try:
import mantidplot
from MantidFramework import *
mtd.initialise(False)
from mantidsimple import *
from mantid.api import AnalysisDataService
import mantid.simpleapi as api
IS_IN_MANTIDPLOT = True
from reduction import find_data
except:
pass

Expand Down Expand Up @@ -154,7 +152,7 @@ def show_instrument(self, file_name=None, workspace=None, tab=-1, reload=False,
file_name = str(file_name)

def _show_ws_instrument(ws):
if not mtd.workspaceExists(ws):
if not AnalysisDataService.doesExist(ws):
return

# Do nothing if the instrument view is already displayed
Expand Down Expand Up @@ -188,24 +186,23 @@ def _show_ws_instrument(ws):
# See if the file is already loaded
if not reload and _show_ws_instrument(workspace):
return

# Check that the file exists.
try:
filepath = find_data(file_name, instrument=self._settings.instrument_name)
except:
QtGui.QMessageBox.warning(self, "File Not Found", "The supplied file can't be found on the file system")
return


if data_proxy is None:
data_proxy = self._data_proxy

if data_proxy is not None:
proxy = data_proxy(filepath, workspace)
proxy = data_proxy(file_name, workspace)
if proxy.data_ws is not None:
if mask is not None:
MaskDetectors(proxy.data_ws, DetectorList=mask)
api.MaskDetectors(Workspace=proxy.data_ws, DetectorList=mask)
_show_ws_instrument(proxy.data_ws)
else:
if hasattr(proxy, 'errors'):
if type(proxy.errors)==list:
for e in proxy.errors:
print e
else:
print proxy.errors
QtGui.QMessageBox.warning(self, "Data Error", "Mantid doesn't know how to load this file")
else:
QtGui.QMessageBox.warning(self, "Data Error", "Mantid doesn't know how to load this file")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,8 @@
IS_IN_MANTIDPLOT = False
try:
import mantidplot
from MantidFramework import *
mtd.initialise(False)
from mantidsimple import *
from mantid.api import AnalysisDataService
IS_IN_MANTIDPLOT = True
from reduction import extract_workspace_name
except:
pass

Expand Down Expand Up @@ -147,12 +144,12 @@ def _create_sensitivity(self):
if IS_IN_MANTIDPLOT and self.options_callback is not None:
# Get patch information
patch_ws = ""
if mtd.workspaceExists(self.patch_ws):
if AnalysisDataService.doesExist(self.patch_ws):
patch_ws = self.patch_ws

try:
reduction_table_ws = self.options_callback()
patch_output = mtd.workspaceExists(patch_ws)
patch_output = AnalysisDataService.doesExist(patch_ws)

filename = self._content.sensitivity_file_edit.text()
script = "_, msg = ComputeSensitivity(Filename='%s',\n" % filename
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,7 @@
import ui.ui_stitcher

import mantidplot
from MantidFramework import *
mtd.initialise(False)
from mantidsimple import *
from mantid.api import AnalysisDataService

from LargeScaleStructures.data_stitching import DataSet, Stitcher, RangeSelector

Expand Down Expand Up @@ -152,10 +150,12 @@ def eventFilter(obj_self, filteredObj, event):
self._content.high_q_combo.installEventFilter(eventFilter)

def populate_combobox(self, combo):
ws_list = mtd.getWorkspaceNames()
ws_list = AnalysisDataService.getObjectNames()
for ws in ws_list:
ws_object = AnalysisDataService.retrieve(ws)
if not ws.startswith("__") and combo.findText(ws)<0\
and hasattr(mtd[ws], "getNumberHistograms") and mtd[ws].getNumberHistograms()==1:
and hasattr(ws_object, "getNumberHistograms")\
and ws_object.getNumberHistograms()==1:
combo.addItem(ws)

def _update_low_scale(self):
Expand Down Expand Up @@ -245,7 +245,7 @@ def update_data(self, dataset_control, min_control, max_control,
file = str(dataset_control.lineEdit().text())
if len(file.strip())==0:
data_object = None
elif os.path.isfile(file) or mtd.workspaceExists(file):
elif os.path.isfile(file) or AnalysisDataService.doesExist(file):
data_object = DataSet(file)
try:
data_object.load(True)
Expand Down Expand Up @@ -309,7 +309,7 @@ def _update_high_q(self, ws=None):
file = str(self._content.high_q_combo.lineEdit().text())
if len(file.strip())==0:
self._high_q_data = None
elif os.path.isfile(file) or mtd.workspaceExists(file):
elif os.path.isfile(file) or AnalysisDataService.doesExist(file):
self._high_q_data = DataSet(file)
try:
self._high_q_data.load(True)
Expand Down

0 comments on commit cebb87e

Please sign in to comment.