class FuncItem(KineticsDisplayItem): name = constants.ITEM """Class for displaying Functions""" #fontMetrics = None font = QtGui.QFont(KineticsDisplayItem.defaultFontName) font.setPointSize(KineticsDisplayItem.defaultFontSize) fontMetrics = QtGui.QFontMetrics(font) def __init__(self, mobj, parent): super(FuncItem, self).__init__(mobj, parent) self.setFlag(QGraphicsItem.ItemIsMovable, True) iconmap_file = (os.path.join(config.settings[config.KEY_ICON_DIR], 'classIcon/Function.png')) self.funcImage = QtGui.QImage(iconmap_file).scaled(15, 33) self.bg = QGraphicsRectItem(self) self.bg.setAcceptHoverEvents(True) self.gobj = QGraphicsPixmapItem( QtGui.QPixmap.fromImage(self.funcImage), self.bg) self.gobj.setAcceptHoverEvents(True) self.gobj.mobj = self.mobj funcdoc = (moose.element(self.mobj.path)).expr self.gobj.setToolTip(funcdoc) def setDisplayProperties(self, x, y, textcolor, bgcolor): """Set the display properties of this item.""" poolt = ["ZombieBufPool", "BufPool", "ZombiePool", "Pool"] if self.gobj.mobj.parent.className in poolt: self.setGeometry(0, 30, self.gobj.boundingRect().width(), self.gobj.boundingRect().height()) else: self.setGeometry(x, y, self.gobj.boundingRect().width(), self.gobj.boundingRect().height()) self.bg.setBrush(QtGui.QBrush(bgcolor)) self.setFlag(QGraphicsItem.ItemIsMovable, False) def refresh(self, scale): pass def boundingRect(self): ''' reimplimenting boundingRect for redrawning ''' return QtCore.QRectF(0, 0, self.gobj.boundingRect().width(), self.gobj.boundingRect().height()) def updateSlot(self): return None def updateColor(self, bgcolor): return None def updateRect(self, ratio): return None def returnColor(self): return (self.bg.brush().color()) def updateValue(self, gobj, funcdoc='Not Available'): self.gobj.setToolTip(funcdoc)
def __init__(self, process, *__args): super().__init__() rect = QGraphicsRectItem(*__args) self.addToGroup(rect) rect.setAcceptHoverEvents(True) self.process = process self.neighbours = [] self.action = process if process.process['thread']: rect.setBrush(QColor(255, 250, 205))
class PoolItem(KineticsDisplayItem): name = constants.ITEM """Class for displaying pools. Uses a QGraphicsSimpleTextItem to display the name.""" #fontMetrics = None font = QtGui.QFont(KineticsDisplayItem.defaultFontName) font.setPointSize(KineticsDisplayItem.defaultFontSize) fontMetrics = QtGui.QFontMetrics(font) def __init__(self, mobj, parent): KineticsDisplayItem.__init__(self, mobj, parent) self.bg = QGraphicsRectItem(self) self.bg.setAcceptHoverEvents(True) self.gobj = QtGui.QGraphicsSimpleTextItem(self.mobj.name, self.bg) self.gobj.mobj = self.mobj self._conc = self.mobj.conc self._n = self.mobj.n doc = "Conc\t: " + str(self._conc) + "\nn\t: " + str(self._n) self.gobj.setToolTip(doc) self.gobj.setFont(PoolItem.font) if not PoolItem.fontMetrics: PoolItem.fontMetrics = QtGui.QFontMetrics(self.gobj.font()) self.bg.setRect( 0, 0, self.gobj.boundingRect().width() + PoolItem.fontMetrics.width(' '), self.gobj.boundingRect().height()) self.bg.setPen(Qt.QColor(0, 0, 0, 0)) self.gobj.setPos(PoolItem.fontMetrics.width(' '), 0) def setDisplayProperties(self, x, y, textcolor, bgcolor): """Set the display properties of this item.""" self.setGeometry( x, y, self.gobj.boundingRect().width() + PoolItem.fontMetrics.width(''), self.gobj.boundingRect().height()) self.bg.setBrush(QtGui.QBrush(bgcolor)) def refresh(self, scale): fontsize = KineticsDisplayItem.defaultFontSize * scale font = QtGui.QFont(KineticsDisplayItem.defaultFontName) if (fontsize < 1): fontsize = self.gobj.font().pointSize() font.setPointSize(fontsize) #self.gobj.setFont(PoolItem.font) self.gobj.setFont(font) def boundingRect(self): ''' reimplimenting boundingRect for redrawning ''' return QtCore.QRectF( 0, 0, self.gobj.boundingRect().width() + PoolItem.fontMetrics.width(' '), self.gobj.boundingRect().height()) def updateSlot(self): #This func will adjust the background color with respect to text size self.gobj.setText(self.mobj.name) self.bg.setRect( 0, 0, self.gobj.boundingRect().width() + PoolItem.fontMetrics.width(' '), self.gobj.boundingRect().height()) self.setGeometry( self.pos().x(), self.pos().y(), self.gobj.boundingRect().width() + PoolItem.fontMetrics.width(''), self.gobj.boundingRect().height()) def updateColor(self, bgcolor): self.bg.setBrush(QtGui.QBrush(QtGui.QColor(bgcolor))) def updateRect(self, ratio=1.0): width = self.gobj.boundingRect().width() + PoolItem.fontMetrics.width( ' ') height = self.gobj.boundingRect().height() adjustw = width * ratio adjusth = height * ratio self.bg.setRect(width / 2 - abs(adjustw / 2), height / 2 - abs(adjusth / 2), adjustw, adjusth) def returnColor(self): return (self.bg.brush().color()) def updateValue(self, gobj): self._gobj = gobj if (isinstance(self._gobj, moose.PoolBase)): self._conc = self.mobj.conc self._n = self.mobj.n doc = "Conc\t: " + str(self._conc) + "\nn\t: " + str(self._n) self.gobj.setToolTip(doc)