Coverage for modules/org/openteacher/interfaces/qt/progressViewer/progressViewer : 46%
Hot-keys on this page
r m x p toggle line displays
j k next/prev highlighted chunk
0 (zero) top of page
1 (one) first highlighted chunk
|
#! /usr/bin/env python3 # -*- coding: utf-8 -*-
# Copyright 2011-2013, Marten de Vries # # This file is part of OpenTeacher. # # OpenTeacher is free software: you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by # the Free Software Foundation, either version 3 of the License, or # (at your option) any later version. # # OpenTeacher is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # # You should have received a copy of the GNU General Public License # along with OpenTeacher. If not, see <http://www.gnu.org/licenses/>.
global Graph, ProgressViewer
"""Raises KeyError if 'test' doesn't contain time info."""
QtWidgets.QSizePolicy.Expanding, QtWidgets.QSizePolicy.MinimumExpanding )
def _amountOfUniqueItems(self): ids = set() for result in self._test["results"]: ids.add(result["itemId"]) return len(ids)
second = event.x() / self._secondsPerPixel moment = self.start + datetime.timedelta(seconds=second) for pause in self._test["pauses"]: if pause["start"] < moment and pause["end"] > moment: text = _("Pause") break try: text except NameError: for result in self._test["results"]: if result["active"]["start"] < moment and result["active"]["end"] > moment: text = _("Thinking") try: text except NameError: text = _("Answering") QtWidgets.QToolTip.showText( event.globalPos(), text, ) return True
x = (item["start"] - self.start).total_seconds() * self._secondsPerPixel width = (item["end"] - item["start"]).total_seconds() * self._secondsPerPixel
p.drawRect(x, 0, width, self._h)
p = QtGui.QPainter() p.begin(self)
p.setPen(QtCore.Qt.NoPen)
w = self.width() self._h = self.height()
try: #float, because one pixel might be more than one second. #When int was used, secondsPerPixel could become 0 showing #nothing in that case. self._secondsPerPixel = float(w) / self._totalSeconds except ZeroDivisionError: self._secondsPerPixel = 0 colors = {} baseColor = self.palette().highlight().color() steps = 0 colorDifference = (255 - baseColor.lightness()) / (self._amountOfUniqueItems +1)#+1 so it doesn't become 0 for result in self._test["results"]: try: p.setBrush(QtGui.QBrush(colors[result["itemId"]])) except KeyError: color = QtGui.QColor(baseColor) hsl = list(color.getHsl()) hsl[2] = hsl[2] + colorDifference * steps color.setHsl(*hsl)
steps += 1
colors[result["itemId"]] = QtGui.QBrush(color) p.setBrush(colors[result["itemId"]])
if "active" in result: self._paintItem(p, result["active"])
p.setBrush(self.palette().dark()) for pause in self._test.get("pauses", []): self._paintItem(p, pause)
p.setBrush(QtGui.QBrush())
p.end() super().paintEvent(event, *args, **kwargs)
"""Raises KeyError if 'test' doesn't contain time info."""
self._mm.mods(type="ui"), )
global QtCore, QtGui, QtWidgets except ImportError: return
except IndexError: pass else:
#Translations global _ global ngettext
except IndexError: _, ngettext = str, lambda a, b, n: a if n == 1 else b else: self._mm.resourcePath("translations") )
|