예제 #1
0
파일: EmployeeView.py 프로젝트: wiz21b/koi
    def __init__(self, image, employee, text=u""):
        super(EmployeePictureItem, self).__init__(image)

        self.employee = employee

        # FIXME Clear ownership issues if any
        name = QGraphicsTextItem(self.employee.fullname + u" " + text, self)
        if image:
            name.setPos((image.width() - name.boundingRect().width()) / 2,
                        image.height())
            self.boundingBox = QRectF(0, 0, image.width(), 180)
        else:
            self.boundingBox = QRectF(0, 0,
                                      name.boundingRect().width(),
                                      name.boundingRect().height())
예제 #2
0
class QNEPort(QGraphicsPathItem):
    (NamePort, TypePort) = (1, 2)
    (Type) = (QGraphicsItem.UserType +1)

    def __init__(self, parent):
        super(QNEPort, self).__init__(parent)

        self.label = QGraphicsTextItem(self)
        self.radius_ = 4
        self.margin = 3
        self.widgetWidth = 50

        self.setPen(QPen(QApplication.palette().text().color(), 1))
        self.setBrush(QApplication.palette().highlight())
        self.setFlag(QGraphicsItem.ItemSendsScenePositionChanges)
        
        self.valueText = QNEValue(self)
        self.valueText.setPort(self)

        self.outputPort = QNEOutputPort(self)

        self.m_portFlags = 0
        self.hasInput_ = False
        self.hasOutput_ = False

        self.m_block = None
        self.m_connections = []


    def __del__(self):
        #print("Del QNEPort %s" % self.name)
        pass


    def delete(self):
        for connection in self.m_connections:
            connection.delete()
        if self.scene():
            self.scene().removeItem(self)
        self.m_block = None
        self.m_connections = []


    def setName(self, name):
        self.name = name
        self.label.setPlainText(name)
        self.label.setPos(self.radius_ + self.margin, -self.label.boundingRect().height()/2)


    def setValue(self, value):
        self.value = value
        self.valueText.showValue(value)


    def setAccess(self, access):
        self.valueText.setAccess(access)


    def setCanConnect(self, hasInput, hasOutput):
        self.hasInput_ = hasInput
        self.hasOutput_ = hasOutput

        if self.hasOutput_:
            self.outputPort.setVisible(True)
        else:
            self.outputPort.setVisible(False)

        path = QPainterPath()
        if self.hasInput_:
            path.addEllipse(0, -self.radius_, 2*self.radius_, 2*self.radius_)
        else:
            pass
        self.setPath(path)


    def setWidth(self, width):
        self.outputPort.setPos(width, 0)
        self.valueText.setPos(width - self.widgetWidth - self.radius_ - self.margin,
                              -self.valueText.boundingRect().height()/2)

        
    def setNEBlock(self, block):
        self.m_block = block


    def setPortFlags(self, flags):
        self.m_portFlags = flags

        if self.m_portFlags & self.TypePort:
            font = self.scene().font()
            font.setItalic(True)
            self.label.setFont(font)
            self.valueText.setVisible(False)
            self.setPath(QPainterPath())
        elif self.m_portFlags & self.NamePort:
            font = self.scene().font()
            font.setBold(True)
            self.label.setFont(font)
            self.valueText.setVisible(False)
            self.setPath(QPainterPath())


    def innerSize(self):
        fontmetrics = QFontMetrics(self.scene().font())
        height = fontmetrics.height()
        width = fontmetrics.width(self.name)

        if self.m_portFlags == 0:
            width = width + self.widgetWidth

        return QSize(width, height)


    def type(self):
        return self.Type


    def radius(self):
        return self.radius_


    def portName(self):
        return self.name


    def hasInput(self):
        return self.hasInput_


    def hasOutput(self):
        return self.hasOutput_


    def isInput(self):
        return True


    def isOutput(self):
        return False


    def block(self):
        return self.m_block


    def portFlags(self):
        return self.m_portFlags
	

    def addConnection(self, connection):
        self.m_connections.append(connection)


    def removeConnection(self, connection):
        try:
            self.m_connections.remove(connection)
        except: pass


    def connections(self):
        return self.m_connections


    def isConnected(self, other):
        for connection in self.m_connections:
            if connection.port1() == other or connection.port2() == other:
                return True

        return False


    def itemChange(self, change, value):
        if change == QGraphicsItem.ItemScenePositionHasChanged:
            for connection in self.m_connections:
                connection.updatePosFromPorts()
                connection.updatePath()

        return value
예제 #3
0
class QNEPort(QGraphicsPathItem):
    (NamePort, TypePort) = (1, 2)
    (Type) = (QGraphicsItem.UserType + 1)

    def __init__(self, parent):
        super(QNEPort, self).__init__(parent)

        self.label = QGraphicsTextItem(self)
        self.radius_ = 4
        self.margin = 3
        self.widgetWidth = 50

        self.setPen(QPen(QApplication.palette().text().color(), 1))
        self.setBrush(QApplication.palette().highlight())
        self.setFlag(QGraphicsItem.ItemSendsScenePositionChanges)

        self.valueText = QNEValue(self)
        self.valueText.setPort(self)

        self.outputPort = QNEOutputPort(self)

        self.m_portFlags = 0
        self.hasInput_ = False
        self.hasOutput_ = False

        self.m_block = None
        self.m_connections = []

    def __del__(self):
        #print("Del QNEPort %s" % self.name)
        pass

    def delete(self):
        for connection in self.m_connections:
            connection.delete()
        if self.scene():
            self.scene().removeItem(self)
        self.m_block = None
        self.m_connections = []

    def setName(self, name):
        self.name = name
        self.label.setPlainText(name)
        self.label.setPos(self.radius_ + self.margin,
                          -self.label.boundingRect().height() / 2)

    def setValue(self, value):
        self.value = value
        self.valueText.showValue(value)

    def setCanConnect(self, hasInput, hasOutput):
        self.hasInput_ = hasInput
        self.hasOutput_ = hasOutput

        if self.hasOutput_:
            self.outputPort.setVisible(True)
        else:
            self.outputPort.setVisible(False)

        path = QPainterPath()
        if self.hasInput_:
            path.addEllipse(0, -self.radius_, 2 * self.radius_,
                            2 * self.radius_)
        else:
            pass
        self.setPath(path)

    def setWidth(self, width):
        self.outputPort.setPos(width, 0)
        self.valueText.setPos(
            width - self.widgetWidth - self.radius_ - self.margin,
            -self.valueText.boundingRect().height() / 2)

    def setNEBlock(self, block):
        self.m_block = block

    def setPortFlags(self, flags):
        self.m_portFlags = flags

        if self.m_portFlags & self.TypePort:
            font = self.scene().font()
            font.setItalic(True)
            self.label.setFont(font)
            self.valueText.setVisible(False)
            self.setPath(QPainterPath())
        elif self.m_portFlags & self.NamePort:
            font = self.scene().font()
            font.setBold(True)
            self.label.setFont(font)
            self.valueText.setVisible(False)
            self.setPath(QPainterPath())

    def innerSize(self):
        fontmetrics = QFontMetrics(self.scene().font())
        height = fontmetrics.height()
        width = fontmetrics.width(self.name)

        if self.m_portFlags == 0:
            width = width + self.widgetWidth

        return QSize(width, height)

    def type(self):
        return self.Type

    def radius(self):
        return self.radius_

    def portName(self):
        return self.name

    def hasInput(self):
        return self.hasInput_

    def hasOutput(self):
        return self.hasOutput_

    def isInput(self):
        return True

    def isOutput(self):
        return False

    def block(self):
        return self.m_block

    def portFlags(self):
        return self.m_portFlags

    def addConnection(self, connection):
        self.m_connections.append(connection)

    def removeConnection(self, connection):
        try:
            self.m_connections.remove(connection)
        except:
            pass

    def connections(self):
        return self.m_connections

    def isConnected(self, other):
        for connection in self.m_connections:
            if connection.port1() == other or connection.port2() == other:
                return True

        return False

    def itemChange(self, change, value):
        if change == QGraphicsItem.ItemScenePositionHasChanged:
            for connection in self.m_connections:
                connection.updatePosFromPorts()
                connection.updatePath()

        return value
예제 #4
0
class QNEPort(QGraphicsPathItem):
    (NamePort, TypePort) = (1, 2)
    (Type) = (QGraphicsItem.UserType +1)

    def __init__(self, parent):
        super(QNEPort, self).__init__(parent)

        self.label = QGraphicsTextItem(self)
        self.radius_ = 4
        self.margin = 3

        path = QPainterPath()
        path.addEllipse(-self.radius_, -self.radius_, 2*self.radius_, 2*self.radius_);
        self.setPath(path)

        self.setPen(QPen(Qt.darkRed))
        self.setBrush(Qt.red)

        self.setFlag(QGraphicsItem.ItemSendsScenePositionChanges)

        self.m_portFlags = 0
        self.isOutput_ = False

        self.m_block = None
        self.m_connections = []


    def __del__(self):
        #print("Del QNEPort %s" % self.name)
        pass


    def delete(self):
        for connection in self.m_connections:
            connection.delete()
        self.scene().removeItem(self)
        self.m_block = None
        self.m_connections = []


    def setName(self, name):
        self.name = name
        self.label.setPlainText(name)


    def setIsOutput(self, isOutput):
        self.isOutput_ = isOutput

        if self.isOutput_:
            self.label.setPos(-self.radius_ - self.margin - self.label.boundingRect().width(),
                -self.label.boundingRect().height()/2);
        else:
            self.label.setPos(self.radius_ + self.margin,
                -self.label.boundingRect().height()/2);



    def setNEBlock(self, block):
        self.m_block = block


    def setPortFlags(self, flags):
        self.m_portFlags = flags

        if self.m_portFlags & self.TypePort:
            font = self.scene().font()
            font.setItalic(True)
            self.label.setFont(font)
            self.setPath(QPainterPath())
        elif self.m_portFlags & self.NamePort:
            font = self.scene().font()
            font.setBold(True)
            self.label.setFont(font)
            self.setPath(QPainterPath())


    def setPtr(self, ptr):
        self.m_ptr = ptr


    def type(self):
        return self.Type


    def radius(self):
        return self.radius_


    def portName(self):
        return self.name


    def isOutput(self):
        return self.isOutput_


    def block(self):
        return self.m_block


    def portFlags(self):
        return self.m_portFlags


    def ptr(self):
        return self.m_ptr;


    def addConnection(self, connection):
        self.m_connections.append(connection)


    def removeConnection(self, connection):
        try:
            self.m_connections.remove(connection)
        except: pass


    def connections(self):
        return self.m_connections


    def isConnected(self, other):
        for connection in self.m_connections:
            if connection.port1() == other or connection.port2() == other:
                return True

        return False


    def itemChange(self, change, value):
        if change == QGraphicsItem.ItemScenePositionHasChanged:
            for connection in self.m_connections:
                connection.updatePosFromPorts()
                connection.updatePath()

        return value