Source code for schrodinger.ui.qt.basewidgets
import sys
import schrodinger
from schrodinger.models import mappers
from schrodinger.Qt import QtCore
from schrodinger.Qt import QtWidgets
from schrodinger.ui import maestro_ui
from schrodinger.ui.qt import widgetmixins
from schrodinger.ui.qt.appframework2.appmethods import custom as bottom_button  # noqa: F401
from schrodinger.ui.qt.widgetmixins import panelmixins
maestro = schrodinger.get_maestro()
[docs]class BaseDialog(widgetmixins.BaseMixinCollection, QtWidgets.QDialog):
    """
    `QDialog` with several mixins. See `QDialog` and
    `widgetmixins.BaseMixinCollection` for full documentation.
    """ 
[docs]class Panel(widgetmixins.PanelMixin, BaseWidget):
    """
    A `BaseWidget` with MapperMixin, is a window by default, and has the `panel`
    method to run the singleton panel.
    """ 
[docs]class TaskPanel(widgetmixins.TaskPanelMixin, BaseWidget):
    pass 
[docs]class BaseOptionsDialog(panelmixins.CleanStateMixin, mappers.MapperMixin,
                        BaseDialog):
    """
    Base class for options dialogs. Includes:
        - An "OK" button that closes the dialog (hotkeyed to "Enter")
        - A cancel button that resets the model to the state it was in when
            the dialog was run (hotkeyed to "Esc")
        - A reset button that resets the dialog to default state specified in
            `initSetDefaults`
    Subclasses can define `self.help_topic = 'HELP_TOPIC_KEY'` to define
    a help button.
    Subclasses must have models that are deepcopyable. Subclasses can define custom
    actions for the standard buttons after `initSetOptions` of base class gets called.
    """
[docs]    def initSetOptions(self):
        self.std_btn_specs = {
            self.StdBtn.Ok: self.accept,
            self.StdBtn.Cancel: self._onCancelClicked,
            self.StdBtn.Reset: None
        }
        super().initSetOptions() 
    def _onCancelClicked(self):
        self.discardChanges()
[docs]    def reject(self):
        self._onCancelClicked()
        return super().reject()  
class _DockablePanel(widgetmixins.DockableMixinCollection,
                     maestro_ui.MM_QDockWidget):
    """
    This is a base class for panels that dock into Maestro. There is a small
    amount of boilerplate that this base class provides, that is necessary for
    getting docking to work properly in Maestro.
    """
    def __init__(self, object_name=None, dockarea=None):
        if object_name is None:
            object_name = str(self)
        if dockarea is None:
            dockarea = QtCore.Qt.RightDockWidgetArea
        super().__init__(object_name, dockarea, True, True)
        self.setObjectName(object_name)
        self.setAllowedAreas(dockarea)
        if maestro:
            self.setupDockWidget.emit()
            self.hide()
    def closeEvent(self, event):
        """
        Do not close the floating python panel and instead emit a
        SIGNAL to Maestro which redocks the panel back into main window.
        This is a temporary workaround for Qt5 redock issues
        """
        if sys.platform.startswith("darwin") and self.isFloating() and maestro:
            # If the panel is currently undocked, re-dock it instead of
            # closing it:
            event.ignore()
            self.pythonPanelAboutToBeClosed.emit(self)
        else:
            return super().closeEvent(event)
[docs]class MaestroDockPanel(widgetmixins.PanelMixin, _DockablePanel):
    pass 
[docs]class MaestroDockTaskPanel(widgetmixins.TaskPanelMixin, _DockablePanel):
    pass