Source code for schrodinger.trajectory.trajectory_gui_dir.trajectory_messages

import textwrap
from enum import Enum

from schrodinger import get_maestro
from schrodinger.Qt import QtCore
from schrodinger.Qt import QtWidgets
from schrodinger.ui.qt import messagebox
from schrodinger.ui.qt.filedialog import FileDialog
from schrodinger.ui.qt.swidgets import SComboBox

maestro = get_maestro()


[docs]class MessageButton(Enum): """ Enums for message buttons """ REMOVE = 1, RESET = 2, CANCEL = 3
[docs]def show_snapshot_atom_limit_warning(num_frames: int, num_atoms: int, parent=None) -> bool: """ Shows a snapshot atom limit warning message :param num_frames: number of frames :type num_frames: integer :param num_atoms: number of atoms :type num_atoms: integer :param parent: Parent widget of the dialog :type parent: QtWidgets.QWidget :return: Whether the Ok button was pressed :rtype: bool """ return messagebox.show_question( parent, text=f'You have requested {num_frames} frames, ' f'for an estimated total of {num_atoms} ' 'atoms. These snapshots may take a long ' 'time to display, and Maestro may seem ' 'unresponsive while they are loading.' '\n\nContinue anyway?', title='Snapshots May Be Slow to Display', yes_text='OK', no_text='Cancel', add_cancel_btn=False)
[docs]def show_invalid_structure_dlg(parent=None): """ Shows message for 'Invalid Structure Found' :param parent: Parent widget of the dialog :type parent: QtWidgets.QWidget :return: Button pressed by user :rtype: MessageButton.RESET or MessageButton.CANCEL """ text = textwrap.dedent(""" The current structure does not appear to match the structure found in the associated trajectory. If you use the Trajectory Player, the structure will be reset. Reset it now? Cancel will preserve the current structure, disabling the player if it is open. To re-enable the player, load the trajectory from the entry's "T" button. You will again be prompted to reset. """) title = 'Trajectory Player - Invalid Structure Found' msg = messagebox.MessageBox(parent, title, text, None, QtWidgets.QMessageBox.Question) cancel_button = msg.addButton('Cancel', QtWidgets.QMessageBox.RejectRole) reset_button = msg.addButton('Reset', QtWidgets.QMessageBox.AcceptRole) msg.setEscapeButton(cancel_button) button_to_ret = { reset_button: MessageButton.RESET, cancel_button: MessageButton.CANCEL } msg.exec() return button_to_ret[msg.clickedButton()]
[docs]def show_invalid_trajectory_file_dlg(trj_path, parent=None): """ Shows message for 'Invalid Trajectory File' :param trj_path: Trajectory path that has issue. :type trj_path: str :param parent: Parent widget of the dialog :type parent: QtWidgets.QWidget :return: Button pressed by user :rtype: MessageButton.REMOVE or MessageButton.CANCEL """ text = textwrap.dedent(f""" The entry's associated trajectory: {trj_path} cannot be opened or read in as a valid trajectory. Do you want to remove the trajectory information from this entry? """) title = 'Trajectory Player - Invalid Trajectory' msg = messagebox.MessageBox(parent, title, text, None, QtWidgets.QMessageBox.Warning) remove_button = msg.addButton('Remove Data', QtWidgets.QMessageBox.AcceptRole) cancel_button = msg.addButton('Cancel', QtWidgets.QMessageBox.RejectRole) msg.setEscapeButton(cancel_button) button_to_ret = { remove_button: MessageButton.REMOVE, cancel_button: MessageButton.CANCEL } msg.exec() return button_to_ret[msg.clickedButton()]
[docs]def trajectory_not_loaded_dlg(parent=None): """ Shows question message for trajectory not loaded :return: Whether the Ok button was pressed :rtype: bool """ text = textwrap.dedent(""" The trajectory corresponding to the clicked plot is not currently loaded into the Trajectory Player. Do you want to load it now? Loading the trajectory will exclude all other entries from the Workspace. """) title = 'Requested Trajectory Not Loaded' return QtWidgets.QMessageBox.question( parent, title, text, QtWidgets.QMessageBox.Ok | QtWidgets.QMessageBox.Cancel) == QtWidgets.QMessageBox.Ok
[docs]def trajectory_not_found_dlg(parent=None): """ Shows warning message for trajectory not found :return: Whether the Ok button was pressed :rtype: bool """ text = textwrap.dedent(""" The trajectory corresponding to the clicked plot cannot be found in this project. The entry may have been deleted, or its trajectory data may have been removed. Delete all plots associated with this missing trajectory? """) title = 'Requested Trajectory Not Found' return QtWidgets.QMessageBox.warning( parent, title, text, QtWidgets.QMessageBox.Ok | QtWidgets.QMessageBox.Cancel) == QtWidgets.QMessageBox.Ok
[docs]class SaveDefinitionsDialog(FileDialog): """ Save file dialog for .st2 files. Has an additional combo box at the bottom for saving a specific trajectory definition. """
[docs] def __init__(self, *args, **kwargs): super().__init__(*args, **kwargs) self._setupFileDialog() self._additionalWidgets() self.definitions = {}
[docs] def resetDefinitions(self): self.definitions.clear() self.definition_cb.clear()
[docs] def setDefinitions(self, new_definitions): """ Sets the available definitions for the save dialog to use :param new_definitions: New dictionary of defintions :type new_definitions: dict """ self.definitions = new_definitions self.definition_cb.clear() self.definition_cb.addItems(self.definitions.keys())
def _setupFileDialog(self): self.setOption(FileDialog.DontUseNativeDialog, False) self.setWindowTitle('Save Definitions') self.setDefaultSuffix('.st2') self.setNameFilter('Simulation Analysis Keyword file (*.st2)') self.setAcceptMode(FileDialog.AcceptSave) self.setFileMode(FileDialog.AnyFile) def _additionalWidgets(self): dlg_layout = self.layout() hbl = QtWidgets.QHBoxLayout() self.definition_label = QtWidgets.QLabel('Definitions from:') self.definition_label.setAlignment(QtCore.Qt.AlignLeft) self.definition_cb = SComboBox() hbl.addWidget(self.definition_label, 15) hbl.addWidget(self.definition_cb, 85) dlg_layout.addLayout(hbl, 4, 0, 1, 0)
[docs] def getSaveFileAndDefinition(self): """ Gets a filepath and definition for the st2 file :return: tuple of (filepath, definition) for that file """ if not self.definitions: return success = self.exec() definition_key = self.definition_cb.currentText() definition = self.definitions[definition_key] if success: return self.selectedFiles()[0], definition return None, definition