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)
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 __init__(self, x, y, size=20, parent=None, scene=None): if parent: self._color = parent._color TableBase.__init__(self, x, y, size, parent, scene) if not self._pencolor: self._pencolor = QColor('#666666') self._pen = QPen(self._pencolor, 1) self._pen.setBrush(QBrush(self._pencolor)) sz = size / 3 self._polygon = QGraphicsRectItem( QRectF(-QPointF(sz, sz), QPointF(sz, sz)), self) self._polygon.setBrush(QBrush(self._pencolor)) self._l1 = QGraphicsLineItem(-size, 0, size, 0, self) self._l1.setPen(self._pen) self._l2 = QGraphicsLineItem(0, -size, 0, size, self) self._l2.setPen(self._pen)
def _add_timeline(self): """Draw the timeline.""" # height is either the necessary space to display all items or the # maximal available display size, so it's looks nicely in larger # windows and enables scrolling in smaller ones. height = self.TIMEPOINT_DIAMETER * len(self._time_points) height += self.TIMEPOINT_SPACING * len(self._time_points) height = max(height, self.viewport().height()) # draw the timeline left aligned with enough space to draw the items # and the selection ring. x = self.MARGIN_HORIZONTAL + (self.SELECTION_DIAMETER / 2) # position the line on the left side of the item item = QGraphicsLineItem(0, 0, 0, height) # The used color for the timeline is the lightest one of the FRM II # colors item.setPen(QPen(QBrush(QColor(0xa3, 0xc1, 0xe7)), self.TIMELINE_WIDTH)) self.scene().addItem(item) # move the whole item to the desired timeline position item.setPos(x, 0) return item
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)
def __init__(self, parent=None): scene = QGraphicsScene() QGraphicsView.__init__(self, scene) self.setRenderHints(QPainter.Antialiasing) self._tube = Tube(scene=scene) self._tube.setRotation(1) self._yoke = Yoke(scene=scene) t1 = QTransform() t1.translate(500, 0) self._yoke.setTransform(t1) self._pivotline = QGraphicsLineItem(-200, 0, 700, 0) scene.addItem(self._pivotline) self._pivot = QGraphicsRectItem(0, 0, 6, 10) t2 = QTransform() t2.translate(-3, -10) self._pivot.setTransform(t2) self._pivot.setBrush(QBrush(QColor('#1F1F1F'))) scene.addItem(self._pivot) for i in range(13): txt = '%d' % (i + 1) self.t = QGraphicsTextItem(txt) bw = self.t.boundingRect().size().width() chrwidth = bw / (len(txt) + 1) x = (i - 9) * self.pivotdist - chrwidth / 2 + bw / len(txt) self.t.setX(x) scene.addItem(self.t) self._det = Detector(parent=self._tube, scene=scene) self.values = { 'tubeangle': -1.0, 'pivot': 1, 'detpos': 620, } self.targets = self.values.copy() self.status = { 'tubeangle': status.OK, 'pivot': status.OK, 'detpos': status.OK, }
def boundingRect(self): # This refreshes the bounding rect self.setLine(QLineF(self._start.scenePos(), self._end.scenePos())) return QGraphicsLineItem.boundingRect(self)
def setLine(self, line): self._beam.setLine(line) QGraphicsLineItem.setLine(self, line)
def paint(self, painter, options, widget): self.setLine(QLineF(self._start.scenePos(), self._end.scenePos())) QGraphicsLineItem.paint(self, painter, options, widget)
class RefsansView(QGraphicsView): pivotdist = 20 def __init__(self, parent=None): scene = QGraphicsScene() QGraphicsView.__init__(self, scene) self.setRenderHints(QPainter.Antialiasing) self._tube = Tube(scene=scene) self._tube.setRotation(1) self._yoke = Yoke(scene=scene) t1 = QTransform() t1.translate(500, 0) self._yoke.setTransform(t1) self._pivotline = QGraphicsLineItem(-200, 0, 700, 0) scene.addItem(self._pivotline) self._pivot = QGraphicsRectItem(0, 0, 6, 10) t2 = QTransform() t2.translate(-3, -10) self._pivot.setTransform(t2) self._pivot.setBrush(QBrush(QColor('#1F1F1F'))) scene.addItem(self._pivot) for i in range(13): txt = '%d' % (i + 1) self.t = QGraphicsTextItem(txt) bw = self.t.boundingRect().size().width() chrwidth = bw / (len(txt) + 1) x = (i - 9) * self.pivotdist - chrwidth / 2 + bw / len(txt) self.t.setX(x) scene.addItem(self.t) self._det = Detector(parent=self._tube, scene=scene) self.values = { 'tubeangle': -1.0, 'pivot': 1, 'detpos': 620, } self.targets = self.values.copy() self.status = { 'tubeangle': status.OK, 'pivot': status.OK, 'detpos': status.OK, } def resizeEvent(self, rsevent): s = rsevent.size() w, h = s.width(), s.height() scale = min( w / self._pivotline.boundingRect().width(), h / (self._yoke.boundingRect().height() + 10 + self.t.boundingRect().y() + self.t.boundingRect().height())) transform = self.transform() transform.reset() transform.scale(scale, scale) self.setTransform(transform) QGraphicsView.resizeEvent(self, rsevent) def update(self): self._tube.setState(self.status['tubeangle']) self._tube.setRotation(-self.values['tubeangle']) p = (self.values['pivot'] - 9) * self.pivotdist self._pivot.setX(p) self._tube.setX(p) self._yoke.setX(p) self._det.setState(self.status['detpos']) # 1 / 20 is the scaling of the tube length self._det.setX(self.values['detpos'] / 20) QGraphicsView.update(self)