Skip to content

Commit

Permalink
Re #4048 Keep track of last executed reduction parameters
Browse files Browse the repository at this point in the history
  • Loading branch information
mdoucet committed Nov 8, 2011
1 parent 1aef081 commit 8b8cec7
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 5 deletions.
9 changes: 7 additions & 2 deletions Code/Mantid/scripts/Interface/reduction_application.py
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ def _set_window_title(self):
def _progress_updated(self, value):
self.progress_bar.setValue(value)

def setup_layout(self):
def setup_layout(self, load_last=False):
"""
Sets up the instrument-specific part of the UI layout
"""
Expand All @@ -140,6 +140,9 @@ def setup_layout(self):
self.tabWidget.addTab(tab[1], tab[0])
self._set_window_title()
self.progress_bar.hide()

if load_last:
self._interface.load_last_reduction()
else:
self.close()

Expand Down Expand Up @@ -368,9 +371,11 @@ def open_file(self, file_path=None):

self.reduce_button.setEnabled(False)
self.export_button.setEnabled(False)
self.save_button.setEnabled(False)
self._interface.load_file(file_path)
self.reduce_button.setEnabled(True)
self.export_button.setEnabled(True)
self.save_button.setEnabled(True)

self._filename = file_path
self._update_file_menu()
Expand Down Expand Up @@ -482,7 +487,7 @@ def start(argv=[]):
app.setApplicationName("Mantid Reduction")

reducer = ReductionGUI()
reducer.setup_layout()
reducer.setup_layout(load_last=True)
reducer.show()
app.exec_()

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ class InstrumentInterface(object):
## List of widgets with associated observers
widgets = []
ERROR_REPORT_NAME = "sans_error_report.xml"
LAST_REDUCTION_NAME = ".mantid_last_reduction.xml"
ERROR_REPORT_DIR = ""

def __init__(self, name, settings):
Expand Down Expand Up @@ -62,7 +63,14 @@ def _warning(self, title, message):
if len(self.widgets)>0:
QtGui.QMessageBox.warning(self.widgets[0], title, message)


def load_last_reduction(self):
try:
red_path = os.path.join(self.ERROR_REPORT_DIR, self.LAST_REDUCTION_NAME)
if os.path.isfile(red_path):
self.load_file(red_path)
except:
print "Could not load last reduction\n %s" % str(traceback.format_exc())

def load_file(self, file_name):
"""
Load an XML file containing reduction parameters and
Expand Down Expand Up @@ -117,6 +125,13 @@ def reduce(self):
"""
self.scripter.update()

# Save the last reduction for later
try:
red_path = os.path.join(self.ERROR_REPORT_DIR, self.LAST_REDUCTION_NAME)
self.save_file(red_path)
except:
print "Could not save last reduction\n %s" % str(traceback.format_exc())

try:
self.scripter.apply()
except RuntimeError, e:
Expand All @@ -137,7 +152,7 @@ def reduce(self):
self._error_report(traceback.format_exc())
# Update widgets
self.scripter.push_state()

def _error_report(self, trace=''):
"""
Try to dump the state of the UI to a file, with a traceback
Expand Down
2 changes: 1 addition & 1 deletion Code/Mantid/scripts/ORNL_SANS.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,5 @@
from PyQt4 import QtCore, uic

reducer = ReductionGUI(instrument_list=["BIOSANS", "GPSANS", "EQSANS"])
reducer.setup_layout()
reducer.setup_layout(load_last=True)
reducer.show()

0 comments on commit 8b8cec7

Please sign in to comment.