class ReacItem(KineticsDisplayItem): defaultWidth = 30 defaultHeight = 30 defaultPenWidth = 2 name = constants.ITEM def __init__(self, *args, **kwargs): KineticsDisplayItem.__init__(self, *args, **kwargs) points = [ QtCore.QPointF(ReacItem.defaultWidth / 4, 0), QtCore.QPointF(0, ReacItem.defaultHeight / 4), QtCore.QPointF(ReacItem.defaultWidth, ReacItem.defaultHeight / 4), QtCore.QPointF(3 * ReacItem.defaultWidth / 4, ReacItem.defaultHeight / 2) ] path = QtGui.QPainterPath() path.moveTo(points[0]) for p in points[1:]: path.lineTo(p) path.moveTo(p) self.gobj = QGraphicsPathItem(path, self) self.gobj.setPen( QtGui.QPen(QtCore.Qt.black, 2, Qt.Qt.SolidLine, Qt.Qt.RoundCap, Qt.Qt.RoundJoin)) self.gobj.mobj = self.mobj self._Kf = self.gobj.mobj.Kf self._Kb = self.gobj.mobj.Kb doc = "Kf\t: " + str(self._Kf) + "\nKb\t: " + str(self._Kb) self.gobj.setToolTip(doc) def updateValue(self, gobj): self._gobj = gobj if (isinstance(self._gobj, moose.ReacBase)): self._Kf = self._gobj.Kf self._Kb = self._gobj.Kb doc = "Kf\t: " + str(self._Kf) + "\nKb\t: " + str(self._Kb) self.gobj.setToolTip(doc) def refresh(self, scale): defaultWidth = ReacItem.defaultWidth * scale defaultHeight = ReacItem.defaultHeight * scale points = [ QtCore.QPointF(defaultWidth / 4, 0), QtCore.QPointF(0, defaultHeight / 4), QtCore.QPointF(defaultWidth, defaultHeight / 4), QtCore.QPointF(3 * defaultWidth / 4, defaultHeight / 2) ] path = QtGui.QPainterPath() path.moveTo(points[0]) for p in points[1:]: path.lineTo(p) path.moveTo(p) self.gobj.setPath(path) ReacPen = self.gobj.pen() defaultpenwidth = ReacItem.defaultPenWidth reacWidth = defaultpenwidth * scale ReacPen.setWidth(reacWidth) self.gobj.setPen(ReacPen) def setDisplayProperties(self, x, y, textcolor, bgcolor): """Set the display properties of this item.""" self.setGeometry(x, y, self.gobj.boundingRect().width(), self.gobj.boundingRect().height())
class TableItem(KineticsDisplayItem): defaultWidth = 30 defaultHeight = 30 defaultPenWidth = 2 name = constants.ITEM def __init__(self, *args, **kwargs): KineticsDisplayItem.__init__(self, *args, **kwargs) points = [ QtCore.QPointF(0, TableItem.defaultWidth / 2), QtCore.QPointF(TableItem.defaultHeight / 2 - 2, 0), QtCore.QPointF(TableItem.defaultWidth / 2 + 2, 0), QtCore.QPointF(TableItem.defaultWidth, TableItem.defaultHeight / 2), ] path = QtGui.QPainterPath() path.moveTo(points[0]) for p in points[1:]: path.lineTo(p) path.moveTo(p) path.moveTo(0, 0) path.lineTo(TableItem.defaultWidth, 0) path.moveTo(-(TableItem.defaultWidth / 3), TableItem.defaultHeight / 4) path.lineTo((TableItem.defaultWidth + 10), TableItem.defaultHeight / 4) self.gobj = QGraphicsPathItem(path, self) #self.gobj.setToolTip("Need to see what to show unlike conc/nint for pool") tabledoc = (moose.element(self.mobj.path)).outputValue self.gobj.setToolTip(str(tabledoc)) self.gobj.setPen( QtGui.QPen(QtCore.Qt.black, 2, Qt.Qt.SolidLine, Qt.Qt.RoundCap, Qt.Qt.RoundJoin)) self.gobj.mobj = self.mobj def refresh(self, scale): defaultWidth = TableItem.defaultWidth * scale defaultHeight = TableItem.defaultHeight * scale points = [ QtCore.QPointF(0, defaultWidth / 2), QtCore.QPointF(defaultHeight / 2 - 2, 0), QtCore.QPointF(defaultWidth / 2 + 2, 0), QtCore.QPointF(defaultWidth, defaultHeight / 2) ] path = QtGui.QPainterPath() path.moveTo(points[0]) for p in points[1:]: path.lineTo(p) path.moveTo(p) path.moveTo(0, 0) path.lineTo(defaultWidth, 0) path.moveTo(-(defaultWidth / 3), defaultHeight / 4) path.lineTo((defaultWidth + 10), defaultHeight / 4) self.gobj.setPath(path) TablePen = self.gobj.pen() tableWidth = TableItem.defaultPenWidth * scale TablePen.setWidth(tableWidth) self.gobj.setPen(TablePen) def setDisplayProperties(self, x, y, textcolor, bgcolor): """Set the display properties of this item.""" # TODO: check the table bounding reactangle b'cos selection looks ugly self.setGeometry(x, y, self.gobj.boundingRect().width(), self.gobj.boundingRect().height())