Source code for schrodinger.application.job_monitor.job_monitor_progress_bar

from schrodinger.application.job_monitor import job_monitor_models
from schrodinger.models import mappers
from schrodinger.Qt import QtCore
from schrodinger.Qt import QtGui
from schrodinger.Qt import QtWidgets
from schrodinger.ui.qt.widgetmixins import basicmixins

BORDER_COLOR = QtGui.QColor(108, 108, 108)
BACKGROUND_COLOR = QtGui.QColor(255, 255, 255)
FILL_COLOR = QtGui.QColor(203, 203, 203)
BORDER_SIZE = 1  # outer border width
FILL_PADDING = 3  # space between outer border and inner fill


[docs]class ProgressBar(mappers.MapperMixin, basicmixins.InitMixin, QtWidgets.QWidget): model_class = job_monitor_models.JobModel
[docs] def defineMappings(self): return [ (self.update, self.model_class.current_progress), (self.update, self.model_class.max_progress), ]
[docs] def paintEvent(self, event): if not should_paint_progress(self.model): # the job backend is not reporting progress return painter = QtGui.QPainter(self) h = self.height() w = self.width() target_rect = QtCore.QRect(0, 0, w, h) progress = self.model.current_progress / self.model.max_progress paint_progress(painter, target_rect, progress)
[docs] def sizeHint(self) -> QtCore.QSize: return QtCore.QSize(130, 28)
[docs]def paint_progress(painter, target_rect, progress): """ Paint the progress bar using the given painter. :param painter: A QPainter that will be used to paint the progress bar :type painter: QtGui.QPainter :param target_rect: A QRect defining the paint device's target to paint on :type target_rect: QtCore.QRect :param progress: The total progress given as a decimal number between 0 and 1 :type progress: float """ base_rect = QtCore.QRect( target_rect.left(), target_rect.top(), target_rect.width() - BORDER_SIZE, target_rect.height() - BORDER_SIZE, ) max_fill_width = base_rect.width() - BORDER_SIZE - 2 * FILL_PADDING fill_width = int(max_fill_width * progress) fill_rect = QtCore.QRect( base_rect.left() + FILL_PADDING + BORDER_SIZE, base_rect.top() + FILL_PADDING + BORDER_SIZE, fill_width, base_rect.height() - BORDER_SIZE - 2 * (FILL_PADDING), ) painter.save() pen = QtGui.QPen(BORDER_COLOR) pen.setWidth(BORDER_SIZE) painter.setPen(pen) painter.setBrush(QtGui.QBrush(BACKGROUND_COLOR)) painter.drawRect(base_rect) painter.restore() painter.fillRect(fill_rect, QtGui.QBrush(FILL_COLOR))
[docs]def should_paint_progress(job_model): return bool(job_model.is_active and job_model.max_progress)