Example #1
0
    def start_drag(self, info_id):
        _logger.info( "started dragging" )
        mimeData = QMimeData()
        mimeData.data =("/" + info_id.partition("/")[2].partition("/")[0], moose.element(info_id))
        mimeData.setText(info_id)
        drag = QDrag(self)
        drag.setMimeData(mimeData)
        pixmap = QPixmap("")

        drag.setPixmap(pixmap)
        # drag.setHotSpot(e.pos() - self.rect().topLeft())
        dropAction = drag.start(QtCore.Qt.MoveAction)
        print((" => ", dropAction))
        self.select_info.set_event_type(0)
        self._timer.start(0)
        return
Example #2
0
    def start_drag(self, info_id):
        _logger.info( "started dragging" )
        mimeData = QMimeData()
        mimeData.data =("/" + info_id.partition("/")[2].partition("/")[0], moose.element(info_id))
        mimeData.setText(info_id)
        drag = QDrag(self)
        drag.setMimeData(mimeData)
        pixmap = QPixmap("")

        drag.setPixmap(pixmap)
        # drag.setHotSpot(e.pos() - self.rect().topLeft())
        dropAction = drag.start(QtCore.Qt.MoveAction)
        print((" => ", dropAction))
        self.select_info.set_event_type(0)
        self._timer.start(0)
        return
Example #3
0
 def delete(self, event):
     """FIXME: The last element should not be deleted """
     _logger.info("Deleting PlotWidget " )
     self.deleteGraph()
     self.close()
     self.widgetClosedSignal.emit(self)
Example #4
0
def checkCreate(
        scene,
        view,
        modelpath,
        mobj,
        string,
        ret_string,
        num,
        event_pos,
        layoutPt):
    """
    Check each element created by drag and drop.
    """

    _logger.info("28 %s " % modelpath)
    if moose.exists(modelpath + '/info'):
        mType = moose.Annotator((moose.element(modelpath + '/info'))).modeltype
    _logger.info(" 1 event_pos %s" % event_pos)
    itemAtView = view.sceneContainerPt.itemAt(view.mapToScene(event_pos))
    _logger.info("2 %s" % itemAtView)
    pos = view.mapToScene(event_pos)
    _logger.info(" 3 %s " % pos)
    modelpath = moose.element(modelpath)
    _logger.info(" model path @34 %s " % modelpath)

    if num:
        string_num = ret_string + str(num)
    else:
        string_num = ret_string

    if string == "CubeMesh" or string == "CylMesh":
        if string == "CylMesh":
            mobj = moose.CylMesh(modelpath.path + '/' + string_num)
        else:
            mobj = moose.CubeMesh(modelpath.path + '/' + string_num)

        mobj.volume = 1e-15
        mesh = moose.element(mobj.path + '/mesh')
        qGItem = ComptItem(
            scene,
            pos.toPoint().x(),
            pos.toPoint().y(),
            90,
            90,
            mobj
            )
        qGItem.setPen(
            QtGui.QPen(
                Qt.QColor( 66, 66, 66, 100),
                1,
                Qt.Qt.SolidLine,
                Qt.Qt.RoundCap,
                Qt.Qt.RoundJoin)
            )
        view.sceneContainerPt.addItem(qGItem)
        qGItem.cmptEmitter.connect(
            qGItem.cmptEmitter,
            QtCore.SIGNAL("qgtextPositionChange(PyQt_PyObject)"),
            layoutPt.positionChange1)
        qGItem.cmptEmitter.connect(
            qGItem.cmptEmitter,
            QtCore.SIGNAL("qgtextItemSelectedChange(PyQt_PyObject)"),
            layoutPt.objectEditSlot)
        compartment = qGItem
        layoutPt.qGraCompt[mobj] = qGItem
        view.emit(QtCore.SIGNAL("dropped"), mobj)

    elif string == "Pool" or string == "BufPool":
        # getting pos with respect to compartment otherwise if compartment is
        # moved then pos would be wrong
        posWrtComp = (itemAtView.mapFromScene(pos)).toPoint()
        if string == "Pool":
            poolObj = moose.Pool(mobj.path + '/' + string_num)
        else:
            poolObj = moose.BufPool(mobj.path + '/' + string_num)

        poolinfo = moose.Annotator(poolObj.path + '/info')
        # Compartment's one Pool object is picked to get the font size

        qGItem = PoolItem(poolObj, itemAtView)
        layoutPt.mooseId_GObj[poolObj] = qGItem
        posWrtComp = (itemAtView.mapFromScene(pos)).toPoint()
        bgcolor = getRandColor()
        qGItem.setDisplayProperties(
            posWrtComp.x(),
            posWrtComp.y(),
            QtGui.QColor('green'),
            bgcolor)
        poolinfo.color = str(bgcolor.getRgb())
        # if mType == "new_kkit":
        poolinfo.x = posWrtComp.x()
        poolinfo.y = posWrtComp.y()
        view.emit(QtCore.SIGNAL("dropped"), poolObj)
        setupItem(modelpath.path, layoutPt.srcdesConnection)
        layoutPt.drawLine_arrow(False)
        poolinfo.x = posWrtComp.x()
        poolinfo.y = posWrtComp.y()

        # Dropping is on compartment then update Compart size
        if isinstance(mobj, moose.ChemCompt):
            compt = layoutPt.qGraCompt[moose.element(mobj)]
            updateCompartmentSize(compt)

    elif string == "Reac":
        posWrtComp = (itemAtView.mapFromScene(pos)).toPoint()
        reacObj = moose.Reac(mobj.path + '/' + string_num)
        reacinfo = moose.Annotator(reacObj.path + '/info')
        qGItem = ReacItem(reacObj, itemAtView)
        qGItem.setDisplayProperties(
            posWrtComp.x(), posWrtComp.y(), "white", "white")
        # if mType == "new_kkit":
        reacinfo.x = posWrtComp.x()
        reacinfo.y = posWrtComp.y()
        layoutPt.mooseId_GObj[reacObj] = qGItem
        view.emit(QtCore.SIGNAL("dropped"), reacObj)
        setupItem(modelpath.path, layoutPt.srcdesConnection)
        layoutPt.drawLine_arrow(False)
        # Dropping is on compartment then update Compart size
        if isinstance(mobj, moose.ChemCompt):
            compt = layoutPt.qGraCompt[moose.element(mobj)]
            updateCompartmentSize(compt)

    elif string == "StimulusTable":
        posWrtComp = (itemAtView.mapFromScene(pos)).toPoint()
        tabObj = moose.StimulusTable(mobj.path + '/' + string_num)
        tabinfo = moose.Annotator(tabObj.path + '/info')
        qGItem = TableItem(tabObj, itemAtView)
        qGItem.setDisplayProperties(
            posWrtComp.x(),
            posWrtComp.y(),
            QtGui.QColor('white'),
            QtGui.QColor('white'))
        # if mType == "new_kkit":
        tabinfo.x = posWrtComp.x()
        tabinfo.y = posWrtComp.y()
        layoutPt.mooseId_GObj[tabObj] = qGItem
        view.emit(QtCore.SIGNAL("dropped"), tabObj)
        setupItem(modelpath.path, layoutPt.srcdesConnection)
        layoutPt.drawLine_arrow(False)
        # Dropping is on compartment then update Compart size
        if isinstance(mobj, moose.ChemCompt):
            compt = layoutPt.qGraCompt[moose.element(mobj)]
            updateCompartmentSize(compt)
    elif string == "Function":
        posWrtComp = (itemAtView.mapFromScene(pos)).toPoint()
        funcObj = moose.Function(mobj.path + '/' + string_num)
        funcinfo = moose.Annotator(funcObj.path + '/info')
        #moose.connect( funcObj, 'valueOut', mobj ,'setN' )
        poolclass = ["ZombieBufPool", "BufPool"]
        comptclass = ["CubeMesh", "cyclMesh"]
        if mobj.className in poolclass:
            funcParent = layoutPt.mooseId_GObj[element(mobj.path)]
        elif mobj.className in comptclass:
            funcParent = layoutPt.qGraCompt[moose.element(mobj)]
            posWrtComp = funcParent.mapFromScene(pos).toPoint()
            #posWrtComp = (itemAtView.mapFromScene(pos)).toPoint()
        qGItem = FuncItem(funcObj, funcParent)
        # print " function ", posWrtComp.x(),posWrtComp.y()
        qGItem.setDisplayProperties(
            posWrtComp.x(),
            posWrtComp.y(),
            QtGui.QColor('red'),
            QtGui.QColor('green'))
        layoutPt.mooseId_GObj[funcObj] = qGItem
        # if mType == "new_kkit":
        funcinfo.x = posWrtComp.x()
        funcinfo.y = posWrtComp.y()
        view.emit(QtCore.SIGNAL("dropped"), funcObj)
        setupItem(modelpath.path, layoutPt.srcdesConnection)
        layoutPt.drawLine_arrow(False)
        # Dropping is on compartment then update Compart size
        mooseCmpt = findCompartment(mobj)
        if isinstance(mooseCmpt, moose.ChemCompt):
            compt = layoutPt.qGraCompt[moose.element(mooseCmpt)]
            updateCompartmentSize(compt)

    elif string == "Enz" or string == "MMenz":
        # If 2 enz has same pool parent, then pos of the 2nd enz shd be
        # displaced by some position, need to check how to deal with it
        posWrtComp = pos
        enzPool = layoutPt.mooseId_GObj[mobj]
        if ((mobj.parent).className == "Enz"):
            QtGui.QMessageBox.information(
                None,
                'Drop Not possible',
                '\'{newString}\' has to have Pool as its parent and not Enzyme Complex'.format(
                    newString=string),
                QtGui.QMessageBox.Ok)
            return
        else:
            enzparent = findCompartment(mobj)
            parentcompt = layoutPt.qGraCompt[enzparent]
        if string == "Enz":
            enzObj = moose.Enz(moose.element(mobj).path + '/' + string_num)
            enzinfo = moose.Annotator(enzObj.path + '/info')
            moose.connect(enzObj, 'enz', mobj, 'reac')
            qGItem = EnzItem(enzObj, parentcompt)
            layoutPt.mooseId_GObj[enzObj] = qGItem
            posWrtComp = pos
            bgcolor = getRandColor()
            qGItem.setDisplayProperties(
                posWrtComp.x(),
                posWrtComp.y() - 40,
                QtGui.QColor('green'),
                bgcolor)
            # if mType == "new_kkit":
            enzinfo.x = posWrtComp.x()
            enzinfo.y = posWrtComp.y()

            enzinfo.color = str(bgcolor.name())
            e = moose.Annotator(enzinfo)
            #e.x = posWrtComp.x()
            #e.y = posWrtComp.y()
            Enz_cplx = enzObj.path + '/' + string_num + '_cplx'
            cplxItem = moose.Pool(Enz_cplx)
            cplxinfo = moose.Annotator(cplxItem.path + '/info')
            qGEnz = layoutPt.mooseId_GObj[enzObj]
            qGItem = CplxItem(cplxItem, qGEnz)
            layoutPt.mooseId_GObj[cplxItem] = qGItem
            enzboundingRect = qGEnz.boundingRect()
            moose.connect(enzObj, 'cplx', cplxItem, 'reac')
            qGItem.setDisplayProperties(
                enzboundingRect.height() / 2,
                enzboundingRect.height() - 40,
                QtGui.QColor('white'),
                QtGui.QColor('white'))
            cplxinfo.x = enzboundingRect.height() / 2
            cplxinfo.y = enzboundingRect.height() - 60
            view.emit(QtCore.SIGNAL("dropped"), enzObj)

        else:
            enzObj = moose.MMenz(mobj.path + '/' + string_num)
            enzinfo = moose.Annotator(enzObj.path + '/info')
            moose.connect(mobj, "nOut", enzObj, "enzDest")
            qGItem = MMEnzItem(enzObj, parentcompt)
            posWrtComp = pos
            bgcolor = getRandColor()
            qGItem.setDisplayProperties(
                posWrtComp.x(),
                posWrtComp.y() - 30,
                QtGui.QColor('green'),
                bgcolor)
            enzinfo.x = posWrtComp.x()
            enzinfo.y = posWrtComp.y()
            enzinfo.color = str(bgcolor.name())
            layoutPt.mooseId_GObj[enzObj] = qGItem
            view.emit(QtCore.SIGNAL("dropped"), enzObj)
        setupItem(modelpath.path, layoutPt.srcdesConnection)
        layoutPt.drawLine_arrow(False)
        # Dropping is on compartment then update Compart size
        if isinstance(enzparent, moose.ChemCompt):
            updateCompartmentSize(parentcompt)
    if view.iconScale != 1:
        view.updateScale(view.iconScale)