Esempio n. 1
0
class Beam(QGraphicsLineItem):
    """Class representing the neutron beam."""
    def __init__(self, fromObj, toObj, parent=None, scene=None):
        self._start = fromObj
        self._end = toObj
        QGraphicsLineItem.__init__(self, parent)
        self.setPen(QPen(QColor('white'), 4))
        self._beam = QGraphicsLineItem(parent)
        self._beam.setPen(QPen(QColor('blue'), 1))
        if not parent and scene:
            scene.addItem(self)
            scene.addItem(self._beam)
        self.update()
        self.setZValue(50)
        self._beam.setZValue(51)

    def paint(self, painter, options, widget):
        self.setLine(QLineF(self._start.scenePos(), self._end.scenePos()))
        QGraphicsLineItem.paint(self, painter, options, widget)

    def setLine(self, line):
        self._beam.setLine(line)
        QGraphicsLineItem.setLine(self, line)

    def boundingRect(self):
        # This refreshes the bounding rect
        self.setLine(QLineF(self._start.scenePos(), self._end.scenePos()))
        return QGraphicsLineItem.boundingRect(self)
Esempio n. 2
0
class Crystal(TableBase):
    """Display a crystal on a table."""

    _pencolor = None

    def __init__(self, x, y, size=10, parent=None, scene=None):
        TableBase.__init__(self, x, y, size, parent, scene)
        sz = size / 2
        self._crystal = QGraphicsLineItem(-sz, 0, sz, 0, self)
        if not self._pencolor:
            self._pencolor = QColor('black')
        self._crystal.setPen(QPen(self._pencolor, 3))
        self._crystal.setZValue(100)