Source code for schrodinger.infra.exception_handler_dir.exception_dialog
from schrodinger.infra.exception_handler_dir import exception_dialog_ui
from schrodinger.Qt import QtWidgets
[docs]class ExceptionDialog(QtWidgets.QDialog):
    """
    A dialog for showing exceptions to users
    """
[docs]    def __init__(self, msg_html, exception_msg, *, show_ignore=True):
        """
        :param msg_html: The message formatted as html
        :type msg_html: str
        :param msg_plaintext: The message formatted as plaintext
        :type msg_plaintext: str
        :param show_ignore: Whether to show the ignore checkbox
        :type show_ignore: bool
        """
        super().__init__(parent=None)
        self.msg_html = msg_html
        self.exception_msg = exception_msg
        # Add HTML pre tag so whitespace is preserved
        self._plain_html = f"<pre>{self.exception_msg}</pre>"
        self.ignore_in_future = False
        self.ui = exception_dialog_ui.Ui_Dialog()
        self.ui.setupUi(self)
        self.ui.ok_button.clicked.connect(self.accept)
        self.ui.copy_to_clipboard_button.clicked.connect(self.copyToClipboard)
        self.ui.error_text.setHtml(self.msg_html)
        self.ui.error_text.setOpenExternalLinks(True)
        self.ui.back_button.setVisible(False)
        self.ui.back_button.clicked.connect(self.backClicked)
        self.ui.error_text.anchorClicked.connect(self.linkFollowed)
        if not show_ignore:
            self.ui.ignore_checkbox.setVisible(False)
        else:
            self.ui.ignore_checkbox.toggled.connect(self.ignoreCheckboxChanged) 
[docs]    def copyToClipboard(self):
        """
        Copy the text (as plaintext) currently displayed into the clipboard.
        """
        clipboard = QtWidgets.QApplication.clipboard()
        clipboard.setText(self.exception_msg) 
[docs]    def ignoreCheckboxChanged(self, checked):
        """
        Callback that synchronizes the selection state of the ignore_checkbox
        with the bool, self.ignore_in_future
        :param state: whether the checkbox is checked
        :type checked: bool
        """
        self.ignore_in_future = checked 
[docs]    def linkFollowed(self, link):
        """
        Callback that shows the back_button if the file link is followed
        :param link: The link that was clicked
        :type link: `QtCore.QUrl`
        """
        if str(link.scheme()) == 'file':
            self.ui.error_text.setHtml(self._plain_html)
            self.ui.back_button.setVisible(True) 
[docs]    def backClicked(self):
        """
        Callback that hides the back_button and resets the error text
        """
        self.ui.back_button.setVisible(False)
        self.ui.error_text.setHtml(self.msg_html)