Source code for schrodinger.ui.qt.icons
"""
Icons for use in Python scripts
To use:
import icons
icon = QtGui.QIcon(icons.PROJECT_ICON)
Copyright Schrodinger, LLC. All rights reserved.
"""
from schrodinger.Qt import QtGui
from schrodinger.Qt import QtWidgets
# The icons_rc import loads the icons into Qt
from schrodinger.ui.qt import icons_rc # noqa # pylint: disable=unused-import
[docs]def get_standard_icon_pixmap(icon_index, size=24):
"""
Get a pixmap of a standard Qt icon
This method will not work if called before the QApplication is started - it
will raise a RuntimeError
:type icon_index: int
:param icon_index: The `QtWidgets.QStyle` index of the desired icon
:type size: int
:param size: The pixmap will be a square of size pixels on each side.
:rtype: `QtGui.QPixmap`
:return: A pixmap of the requested icon
:raise RuntimeError: If a QApplication has not been started
"""
current_style = QtWidgets.QApplication.style()
if current_style:
pixmap = current_style.standardIcon(icon_index).pixmap(size, size)
return pixmap
else:
raise RuntimeError('A QApplication has not been started so no icon '
'resources are available.')
_VALID_PIXMAP = None
_INVALID_PIXMAP = None
_INTERMEDIATE_PIXMAP = None
[docs]def get_validation_pixmaps(size=24):
"""
Get pixmaps used for validation icons - invalid, intermediate and valid
See also `schrodinger.ui.qt.swidgets.SValidIndicator` for usage of these
icons
Note that this method (or any method that calls get_standard_icon_pixmap)
will not work if called before the QApplication is started.
:type size: int
:param size: The pixmap will be a square of size pixels on each side.
:rtype: `QtGui.QPixmap`, `QtGui.QPixmap`, `QtGui.QPixmap`
:return: The valid, intermediate and invalid icons to use to display the
current status of a validated widget
"""
global _VALID_PIXMAP, _INTERMEDIATE_PIXMAP, _INVALID_PIXMAP
# We can't create the icons on load because this module gets loaded before
# a QApplication is valid. Therefore we create the icons the first time this
# method is called and then cache them for later use.
if not _VALID_PIXMAP:
_VALID_PIXMAP = get_standard_icon_pixmap(
QtWidgets.QStyle.SP_DialogApplyButton, size=size)
_INTERMEDIATE_PIXMAP = get_standard_icon_pixmap(
QtWidgets.QStyle.SP_MessageBoxWarning, size=size)
_INVALID_PIXMAP = get_standard_icon_pixmap(
QtWidgets.QStyle.SP_MessageBoxCritical, size=size)
return _VALID_PIXMAP, _INTERMEDIATE_PIXMAP, _INVALID_PIXMAP
[docs]def get_icon(myicon):
# get_icon() is present for backwards compatibility. New code should
# instantiate a QIcon directly.
return QtGui.QIcon(myicon)
# Project icon for filedialogs
PROJECT_ICON = ":/schrodinger/ui/qt/icons_dir/project"
# Locked project icon for filedialogs
PROJECT_LOCKED_ICON = ":/schrodinger/ui/qt/icons_dir/project_locked"
# Checkbox icon for matplotlib toolbars
MATPLOTLIB_TOOLBAR_OPTIONS_ICON = ":/schrodinger/ui/qt/icons_dir/matplotlib_toolbar_options"
# Maestro icon for main window
MAESTRO_ICON = ":/schrodinger/ui/qt/icons_dir/maestro"
CLIPBOARD_ICON = ":/schrodinger/ui/qt/icons_dir/clipboard"
# Icons for edit delegates
PENCIL_ICON = ":/schrodinger/ui/qt/icons_dir/pencil_icon.ico"
COMBOBOX_ICON = ":/schrodinger/ui/qt/icons_dir/combobox_icon.ico"