Skip to content

Commit

Permalink
Re #4303 Add flexibility to REFL UI
Browse files Browse the repository at this point in the history
  • Loading branch information
mdoucet committed Jan 23, 2012
1 parent 868b42b commit 30c8c3b
Show file tree
Hide file tree
Showing 11 changed files with 2,362 additions and 2,012 deletions.
10 changes: 10 additions & 0 deletions Code/Mantid/scripts/Interface/reduction_application.py
Original file line number Diff line number Diff line change
Expand Up @@ -180,6 +180,12 @@ def setup_layout(self, load_last=False):
self.tabWidget.addTab(tab[1], tab[0])
self._set_window_title()

# Show the "advanced interface" check box if needed
if self._interface.has_advanced_version():
self.interface_chk.show()
else:
self.interface_chk.hide()

if load_last:
self._interface.load_last_reduction()
else:
Expand Down Expand Up @@ -384,6 +390,8 @@ def reduce_clicked(self):
self.export_button.setEnabled(False)
self.save_button.setEnabled(False)
self.interface_chk.setEnabled(False)
self.file_menu.setEnabled(False)
self.tools_menu.setEnabled(False)
if IS_IN_MANTIDPLOT:
_qti.app.mantidUI.setIsRunning(True)
self._interface.reduce()
Expand All @@ -393,6 +401,8 @@ def reduce_clicked(self):
self.export_button.setEnabled(True)
self.save_button.setEnabled(True)
self.interface_chk.setEnabled(True)
self.file_menu.setEnabled(True)
self.tools_menu.setEnabled(True)

def open_file(self, file_path=None):
"""
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,3 +54,9 @@ def __init__(self, name, settings):
# Stitcher
if IS_IN_MANTIDPLOT:
self.attach(StitcherWidget(settings = self._settings))

def has_advanced_version(self):
"""
Returns true if the instrument has simple and advanced views
"""
return True
Original file line number Diff line number Diff line change
Expand Up @@ -190,6 +190,12 @@ def set_running(self, is_running=True):
for widget in self.widgets:
widget.is_running(is_running)

def has_advanced_version(self):
"""
Returns true if the instrument has simple and advanced views
"""
return False

def reset(self):
"""
Reset the interface
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,12 @@ def initialize_content(self):
self.connect(self._summary.plot_tof_btn, QtCore.SIGNAL("clicked()"), self._plot_tof)
self.connect(self._summary.add_dataset_btn, QtCore.SIGNAL("clicked()"), self._add_data)
self.connect(self._summary.angle_list, QtCore.SIGNAL("itemSelectionChanged()"), self._angle_changed)
self.connect(self._summary.remove_btn, QtCore.SIGNAL("clicked()"), self._remove_item)

def _remove_item(self):
row = self._summary.angle_list.currentRow()
if row>=0:
self._summary.angle_list.takeItem(row)

def is_running(self, is_running):
"""
Expand Down Expand Up @@ -111,15 +117,16 @@ def _add_data(self):
run_numbers = self._summary.data_run_number_edit.text()
list_items = self._summary.angle_list.findItems(run_numbers, QtCore.Qt.MatchFixedString)
if len(list_items)>0:
print "Found"
list_items[0].setData(QtCore.Qt.UserRole, state)
else:
item_widget = QtGui.QListWidgetItem(run_numbers, self._summary.angle_list)
item_widget.setData(QtCore.Qt.UserRole, state)

def _angle_changed(self):
state = self._summary.angle_list.currentItem().data(QtCore.Qt.UserRole).toPyObject()
self.set_editing_state(state)
current_item = self._summary.angle_list.currentItem()
if current_item is not None:
state = current_item.data(QtCore.Qt.UserRole).toPyObject()
self.set_editing_state(state)

def _check_for_missing_fields(self):

Expand Down Expand Up @@ -179,6 +186,7 @@ def set_state(self, state):

if len(state.data_sets)>0:
self.set_editing_state(state.data_sets[0])
self._summary.angle_list.setCurrentRow(0)

def set_editing_state(self, state):

Expand All @@ -191,6 +199,7 @@ def set_editing_state(self, state):

#Background flag
self._summary.data_background_switch.setChecked(state.DataBackgroundFlag)
self._data_background_clicked(state.DataBackgroundFlag)

#Background from/to pixels
self._summary.data_background_from_pixel1.setText(str(state.DataBackgroundRoi[0]))
Expand All @@ -208,6 +217,7 @@ def set_editing_state(self, state):
self._summary.norm_peak_to_pixel.setText(str(state.NormPeakPixels[1]))

self._summary.norm_background_switch.setChecked(state.NormBackgroundFlag)
self._norm_background_clicked(state.NormBackgroundFlag)

self._summary.norm_background_from_pixel1.setText(str(state.NormBackgroundRoi[0]))
self._summary.norm_background_to_pixel1.setText(str(state.NormBackgroundRoi[1]))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,10 @@ def __init__(self):

class ReflData(object):
name = ""
is_ref = False
scale = 1.0
def __init__(self, workspace, is_ref=False, scale=1.0, parent_layout=None):
self.is_ref = is_ref
self.name = workspace
self.scale = scale
self._scale = scale
self._data = None
self._call_back = None

Expand All @@ -48,12 +46,16 @@ def __init__(self, workspace, is_ref=False, scale=1.0, parent_layout=None):
self._layout.addWidget(self._label)
self._layout.addItem(self._spacer)
self._layout.addWidget(self._edit_ctrl)
self._edit_ctrl.setText(str(self.scale))
self._edit_ctrl.setText(str(self._scale))

if parent_layout is not None:
parent_layout.addLayout(self._layout)
parent_layout.connect(self._edit_ctrl, QtCore.SIGNAL("returnPressed()"), self._scale_updated)
#parent_layout.connect(self._radio, QtCore.SIGNAL("toggled()"), self._reference_updated)

def is_selected(self):
return self._radio.isChecked()

def _scale_updated(self):
if self._data is not None:
try:
Expand All @@ -77,11 +79,10 @@ def delete(self):
sip.delete(self._layout)

def select(self):
self.is_ref = True
self._radio.setChecked(True)

def get_scale(self):
return self.scale
return self._scale

def set_scale(self, scale):
self._edit_ctrl.setText("%-6.3g" % scale)
Expand Down Expand Up @@ -125,7 +126,6 @@ def __init__(self, parent=None):
self._data_sets = []
self._plotted = False


self._workspace_list = []
self.initialize_content()

Expand All @@ -134,8 +134,8 @@ def initialize_content(self):
Initialize the content of the frame
"""
# Apply and save buttons
#self.connect(self._content.apply_button, QtCore.SIGNAL("clicked()"), self._apply)
#self.connect(self._content.save_result_button, QtCore.SIGNAL("clicked()"), self._save_result)
self.connect(self._content.auto_scale_btn, QtCore.SIGNAL("clicked()"), self._apply)
self.connect(self._content.save_btn, QtCore.SIGNAL("clicked()"), self._save_result)

def _add_entry(self, workspace):
entry = ReflData(workspace, parent_layout=self._content.angle_list_layout)
Expand All @@ -147,8 +147,8 @@ def is_running(self, is_running):
@param is_running: True if a reduction is running
"""
super(StitcherWidget, self).is_running(is_running)
#self._content.save_result_button.setEnabled(not is_running)
#self._content.apply_button.setEnabled(not is_running)
self._content.save_btn.setEnabled(not is_running)
self._content.auto_scale_btn.setEnabled(not is_running)

def _load_workspace(self, workspace):
ws_data = DataSet(workspace)
Expand All @@ -165,14 +165,13 @@ def _apply(self):
"""
s = Stitcher()
refID = 0

for i in range(len(self._workspace_list)):
item = self._workspace_list[i]
data = DataSet(item.name)
data.load(True)
item.set_user_data(data)

if item.is_ref:
if item.is_selected():
data.set_scale(item.get_scale())
refID = i

Expand All @@ -190,8 +189,6 @@ def _apply(self):
scale = data.get_scale()
item.set_scale(scale)

# Update widgets

self._stitcher = s

self.plot_result()
Expand All @@ -212,29 +209,23 @@ def plot_result(self):
if g is None or not self._plotted:
g = _qti.app.mantidUI.pyPlotSpectraList(ws_list,[0],True)
g.setName(self._graph)
l=g.activeLayer()
l.setTitle(" ")
self._plotted = True

def _save_result(self):
"""
Save the scaled output in one combined I(Q) file
"""
if self._stitcher is not None:
if not os.path.isdir(self._output_dir):
if self._output_dir is None or not os.path.isdir(self._output_dir):
self._output_dir = os.path.expanduser("~")
fname_qstr = QtGui.QFileDialog.getSaveFileName(self, "Save combined I(Q)",
self._output_dir,
"Data Files (*.xml)")
"Data Files (*.txt)")
fname = str(QtCore.QFileInfo(fname_qstr).filePath())
if len(fname)>0:
if fname.endswith('.xml'):
self._stitcher.save_combined(fname, as_canSAS=True)
elif fname.endswith('.txt'):
self._stitcher.save_combined(fname, as_canSAS=False)
else:
fname_tmp = fname + ".xml"
self._stitcher.save_combined(fname_tmp, as_canSAS=True)
fname_tmp = fname + ".txt"
self._stitcher.save_combined(fname_tmp, as_canSAS=False)
self._stitcher.save_combined(fname, as_canSAS=False)

def set_state(self, state):
"""
Expand All @@ -248,7 +239,7 @@ def set_state(self, state):

# Refresh combo boxes
for item in mtd.keys():
if item.startswith("reflectivity"):
if item.startswith("reflectivity") and not item.endswith("scaled"):
self._add_entry(item)

if len(self._workspace_list)>0:
Expand Down

0 comments on commit 30c8c3b

Please sign in to comment.