Skip to content

Commit

Permalink
Merge pull request #393 from neutrons/multi_gr_out
Browse files Browse the repository at this point in the history
Multi gr out
  • Loading branch information
Kvieta1990 authored Dec 15, 2022
2 parents e1d412b + ffab9f3 commit 0787121
Show file tree
Hide file tree
Showing 3 changed files with 90 additions and 37 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ ImportError: First import of "._api" failed with "libGL.so.1: cannot open shared
The test suite can be run using [pytest](https://docs.pytest.org/en/latest/)
with the [pytest-qt](https://pytest-qt.readthedocs.io/en/latest/) plugin.
```bash
$ pytest tests
$ python -m pytest
```

### Developing using a local Mantid install
Expand Down
116 changes: 82 additions & 34 deletions addie/calculate_gr/event_handler.py
Original file line number Diff line number Diff line change
Expand Up @@ -150,20 +150,26 @@ def generate_gr_step1(main_window):
:return:
"""
# get S(Q) workspace
comboBox_SofQ = main_window.calculategr_ui.comboBox_SofQ
selected_sq = str(comboBox_SofQ.currentText())
if selected_sq == 'All':
sq_ws_name_list = list()
for index in range(comboBox_SofQ.count()):
item = str(comboBox_SofQ.itemText(index))
if item != 'All':
# add S(Q) name unless it is 'All'
sq_ws_name_list.append(item)
# END-IF
# END-FOR
gr_list = main_window.calculategr_ui.treeWidget_grWsList
sq_name_list = gr_list.get_selected_items_of_level(
2, excluded_parent='GofR', return_item_text=True)
if len(sq_name_list) == 0:
comboBox_SofQ = main_window.calculategr_ui.comboBox_SofQ
selected_sq = str(comboBox_SofQ.currentText())
if selected_sq == 'All':
sq_ws_name_list = list()
for index in range(comboBox_SofQ.count()):
item = str(comboBox_SofQ.itemText(index))
if item != 'All':
# add S(Q) name unless it is 'All'
sq_ws_name_list.append(item)
# END-IF
# END-FOR
else:
# selected S(Q) is a single S(Q) name
sq_ws_name_list = [selected_sq]
else:
# selected S(Q) is a single S(Q) name
sq_ws_name_list = [selected_sq]
sq_ws_name_list = sq_name_list

# generate G(r)
generate_gr_step2(main_window,
Expand Down Expand Up @@ -480,37 +486,79 @@ def do_save_gr(main_window):
gr_list = main_window.calculategr_ui.treeWidget_grWsList
gr_name_list = gr_list.get_selected_items_of_level(
2, excluded_parent='SofQ', return_item_text=True)
single_out = True
if len(gr_name_list) != 1:
err_msg = 'ERROR: Only 1 workspace of G(r) can be selected.'
err_msg += '{0} are selected.\n Selection: {1}'
err_msg = err_msg.format(len(gr_name_list), str(gr_name_list))
QMessageBox.warning(main_window, 'Error', err_msg)
return
if len(gr_name_list) == 0:
err_msg = 'ERROR: Only 1 workspace of G(r) can be selected.'
err_msg += '{0} are selected.\n Selection: {1}'
err_msg = err_msg.format(len(gr_name_list), str(gr_name_list))
QMessageBox.warning(main_window, 'Error', err_msg)
return
else:
single_out = False
else:
gr_ws_name = gr_name_list[0]

# pop-up a dialog for the file to save
default_dir = os.getcwd()
caption = 'Save G(r)'

FILE_FILTERS = {'PDFgui (*.gr)': 'gr',
'XYE (*.xye)': 'xye',
'CSV XYE (*.csv)': 'csv',
'RMCProfile (*.dat)': 'dat'}

filename, filetype = get_save_file(
parent=main_window,
directory=default_dir,
caption=caption,
filter=FILE_FILTERS)
if not filename: # user pressed cancel
return
if single_out:
FILE_FILTERS = {'PDFgui (*.gr)': 'gr',
'XYE (*.xye)': 'xye',
'CSV XYE (*.csv)': 'csv',
'RMCProfile (*.dat)': 'dat'}

if filetype == 'dat':
filetype = 'rmcprofile'
filename, filetype = get_save_file(
parent=main_window,
directory=default_dir,
caption=caption,
filter=FILE_FILTERS)
if not filename: # user pressed cancel
return

if filetype == 'dat':
filetype = 'rmcprofile'

# save!
main_window._myController.save_ascii(gr_ws_name, filename, filetype)
# save!
main_window._myController.save_ascii(gr_ws_name, filename, filetype)
main_window.ui.statusbar.setStyleSheet("color: blue")
main_window.ui.statusbar.showMessage("File successfully saved.",
main_window.statusbar_display_time)
else:
options = QFileDialog.Options()
options |= QFileDialog.ShowDirsOnly
out_dir = QFileDialog.getExistingDirectory(main_window, caption,
default_dir, options=options)

ext_dict = {
"xye": "xye",
"gr": "gr",
"csv": "csv",
"rmcprofile": "dat",
"dat": "dat"
}
if "xye" in out_dir.lower():
filetype = "xye"
elif "gr" in out_dir.lower():
filetype = "gr"
elif "csv" in out_dir.lower():
filetype = "csv"
elif "rmc" in out_dir.lower():
filetype = "rmcprofile"
elif "dat" in out_dir.lower():
filetype = "dat"
else:
filetype = "gr"

for item in gr_name_list:
gr_ws_name = item
filename = gr_ws_name + "." + ext_dict[filetype]
filename = os.path.join(out_dir, filename)
main_window._myController.save_ascii(gr_ws_name, filename, filetype)
main_window.ui.statusbar.setStyleSheet("color: blue")
main_window.ui.statusbar.showMessage("Files successfully saved.",
main_window.statusbar_display_time)


def do_save_sq(main_window):
Expand Down
9 changes: 7 additions & 2 deletions addie/calculate_gr/gofrtree.py
Original file line number Diff line number Diff line change
Expand Up @@ -235,8 +235,11 @@ def do_delete_selected_items(self):
if curr_level == -1:
curr_level = temp_level
elif curr_level != temp_level:
raise RuntimeError(
'Nodes of different levels are selected. It is not supported for deletion.')
err_msg = "Nodes of different levels are selected."
self.parent.ui.statusbar.setStyleSheet("color: red")
self.parent.ui.statusbar.showMessage(err_msg,
self.parent.statusbar_display_time)
return

# get item and delete
if curr_level == 0:
Expand Down Expand Up @@ -316,6 +319,8 @@ def _delete_ws_node(self, ws_item, is_gr, check_gr_sq):
print('Unable to remove %s from canvas due to %s.' %
(leaf_node_name, str(ass_err)))
# delete node
item_tmp = self.parent.calculategr_ui.comboBox_SofQ.findText(ws_item.text())
self.parent.calculategr_ui.comboBox_SofQ.removeItem(item_tmp)
self.delete_node(ws_item)

def do_plot(self):
Expand Down

2 comments on commit 0787121

@github-actions
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

GitLab pipeline for addie-dev has been submitted for this commit: "https://code.ornl.gov/sns-hfir-scse/deployments/addie-deploy/-/pipelines/313917"

@github-actions
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

GitLab pipeline for addie-qa has been submitted for this commit: "https://code.ornl.gov/sns-hfir-scse/deployments/addie-deploy/-/pipelines/314218"

Please sign in to comment.