Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

initial version of modified Send To button #2613

Merged
merged 7 commits into from
Sep 25, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
63 changes: 50 additions & 13 deletions src/sas/qtgui/MainWindow/DataExplorer.py
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,9 @@ def __init__(self, parent=None, guimanager=None, manager=None):
self.cmdAppend_2.clicked.connect(self.appendPlot)
self.cmdHelp.clicked.connect(self.displayHelp)
self.cmdHelp_2.clicked.connect(self.displayHelp)
self.chkSwap.setVisible(False)

self.cmdFreeze.clicked.connect(self.freezeTheory)
# Fill in the perspectives combo
self.initPerspectives()

Expand Down Expand Up @@ -151,6 +153,13 @@ def __init__(self, parent=None, guimanager=None, manager=None):
# Current view on model
self.current_view = self.treeView

def createSendToMenu(self):
self.actionReplace = QtGui.QAction(self)
self.actionReplace.setObjectName(u"actionReplace")
self.actionReplace.setText(u"... replacing data in the current page")
self.send_menu = QtWidgets.QMenu(self)
self.send_menu.addAction(self.actionReplace)

def closeEvent(self, event):
"""
Overwrite the close event - no close!
Expand Down Expand Up @@ -748,23 +757,28 @@ def deleteTheory(self, event):
# update stored_data
self.manager.update_stored_data(deleted_names)

def sendData(self, event=None):
def selectedItems(self):
"""
Send selected item data to the current perspective and set the relevant notifiers
Returns the selected items from the current view
"""
def isItemReady(index):
item = self.model.item(index)
return item.isCheckable() and item.checkState() == QtCore.Qt.Checked

# Figure out which rows are checked
selected_items = [self.model.item(index)
for index in range(self.model.rowCount())
if isItemReady(index)]
return selected_items

def onDataReplaced(self):
"""
Called when data is to be replaced in the current fitting tab.
"""
selected_items = self.selectedItems()
if len(selected_items) < 1:
return
#Check that you have only one box item checked when swaping data
if len(selected_items) > 1 and (self.chkSwap.isChecked() or not self._perspective().allowBatch()):
if len(selected_items) > 1 and not self._perspective().allowBatch():
if hasattr(self._perspective(), 'name'):
title = self._perspective().name
else:
Expand All @@ -776,13 +790,29 @@ def isItemReady(index):
msgbox.setStandardButtons(QtWidgets.QMessageBox.Ok)
_ = msgbox.exec_()
return
try:
self._perspective().swapData(selected_items[0])
except Exception as ex:
msg = "%s perspective returned the following message: \n%s\n" % (self._perspective().name, str(ex))
logging.error(ex, exc_info=True)
msg = str(ex)
msgbox = QtWidgets.QMessageBox()
msgbox.setIcon(QtWidgets.QMessageBox.Critical)
msgbox.setText(msg)
msgbox.setStandardButtons(QtWidgets.QMessageBox.Ok)
_ = msgbox.exec_()

def sendData(self, event=None):
"""
Send selected item data to the current perspective and set the relevant notifiers
"""
selected_items = self.selectedItems()
if len(selected_items) < 1:
return

# Notify the GuiManager about the send request
try:
if self.chkSwap.isChecked():
self._perspective().swapData(selected_items[0])
else:
self._perspective().setData(data_item=selected_items, is_batch=self.chkBatch.isChecked())
self._perspective().setData(data_item=selected_items, is_batch=self.chkBatch.isChecked())
except Exception as ex:
msg = "%s perspective returned the following message: \n%s\n" % (self._perspective().name, str(ex))
logging.error(ex, exc_info=True)
Expand Down Expand Up @@ -985,6 +1015,16 @@ def updateGraphCombo(self, graph_list):
if ind > 0:
graph.setCurrentIndex(ind)

def sendToMenu(self, hasSubmenu=False):
# add menu to cmdSendTO
if hasSubmenu:
self.createSendToMenu()
self.cmdSendTo.setMenu(self.send_menu)
self.cmdSendTo.setPopupMode(QtWidgets.QToolButton.MenuButtonPopup)
else:
self.cmdSendTo.setMenu(None)
self.cmdSendTo.setPopupMode(QtWidgets.QToolButton.InstantPopup)

def updatePerspectiveCombo(self, index):
"""
Notify the gui manager about the new perspective chosen.
Expand All @@ -1000,11 +1040,7 @@ def updatePerspectiveCombo(self, index):
allow_swap = False if current_perspective is None else current_perspective.allowSwap()

self.chkBatch.setEnabled(allow_batch)
self.chkSwap.setEnabled(allow_swap)

# Using this conditional prevents the checkbox for going into the "neither checked nor unchecked" state
if not allow_swap:
self.chkSwap.setChecked(False)
self.sendToMenu(hasSubmenu=allow_swap)

def itemFromDisplayName(self, name):
"""
Expand Down Expand Up @@ -1523,6 +1559,7 @@ def contextMenu(self):
self.actionEditMask.triggered.connect(self.showEditDataMask)
self.actionDelete.triggered.connect(self.deleteSelectedItem)
self.actionFreezeResults.triggered.connect(self.freezeSelectedItems)
self.actionReplace.triggered.connect(self.onDataReplaced)

def onCustomContextMenu(self, position):
"""
Expand Down
Loading