Пример #1
0
 def itemAt(self, pos):
     items = self.scene.items(
         QtCore.QRectF(pos - QtCore.QPointF(DB, DB),
                       QtCore.QSizeF(2 * DB, 2 * DB)))
     for item in items:
         if isinstance(item, QGraphicsItem):
             return item
     return None
Пример #2
0
 def find_itemAt(self, pos):
     items = self.items(
         QtCore.QRectF(pos - QtCore.QPointF(1, 1), QtCore.QSizeF(3, 3)))
     for item in items:
         if isinstance(item,
                       QGraphicsItem) and not isinstance(item, Connection):
             return item
     return None
Пример #3
0
 def loadConn(self, item):
     c = Connection(None, self)
     pt1 = QtCore.QPointF(float(item.findtext('pos1X')),
                          float(item.findtext('pos1Y')))
     pt2 = QtCore.QPointF(float(item.findtext('pos2X')),
                          float(item.findtext('pos2Y')))
     c.pos1 = pt1
     c.pos2 = pt2
     c.update_ports_from_pos()
Пример #4
0
 def genInterPoint(self, p2):
     p1 = self.conn.pos1
     dx = np.abs(p2.x() - p1.x())
     dy = np.abs(p2.y() - p1.y())
     if isinstance(self.conn.port1, OutPort):
         pt = QtCore.QPointF(p2.x(), p1.y())
     else:
         if dx > dy:
             pt = QtCore.QPointF(p2.x(), p1.y())
         else:
             pt = QtCore.QPointF(p1.x(), p2.y())
     return pt
Пример #5
0
 def pasteAct(self):
     if self.scene.selection != []:
         for item in self.scene.selection:
             if isinstance(item, Block) or isinstance(item, Node):
                 try:
                     item.clone(QtCore.QPointF(200, 200))
                 except:
                     pass
         for item in self.scene.selection:
             if isinstance(item, Connection):
                 try:
                     c = item.clone(QtCore.QPointF(200, 200))
                     c.update_ports_from_pos()
                 except:
                     pass
Пример #6
0
    def __init__(self, library, fname, mypath, runflag, parent=None):
        super(SupsiSimMainWindow, self).__init__(parent)
        self.resize(1024, 768)
        self.centralWidget = QWidget(self)
        self.verticalLayout = QVBoxLayout(self.centralWidget)
        #self.verticalLayout.setMargin(0)
        self.view = GraphicsView(self.centralWidget)
        self.view.setMouseTracking(True)
        self.scene = Scene(self)
        self.view.setScene(self.scene)
        self.view.setRenderHint(QPainter.Antialiasing)
        self.verticalLayout.addWidget(self.view)
        self.setCentralWidget(self.centralWidget)
        self.addactions()
        self.addMenubar()
        self.addToolbars()
        self.filename = fname
        self.path = mypath
        self.library = library
        self.runflag = runflag
        if fname != 'untitled':
            self.scene.loadDgm(self.getFullFileName())

        self.setWindowTitle(self.filename)
        self.status = self.statusBar()
        self.evpos = QtCore.QPointF(0, 0)
        self.editor = Editor(self)
        self.editor.install(self.scene)
        self.status.showMessage('Ready')

        self.modified = False
Пример #7
0
 def __init__(self, parent=None):
     super(GraphicsView, self).__init__(parent)
     self.setDragMode(QGraphicsView.RubberBandDrag)
     self.setSceneRect(QtCore.QRectF(-2000, -2000, 4000, 4000))
     self.setRenderHint(QPainter.Antialiasing)
     self.setRenderHint(QPainter.TextAntialiasing)
     self.setAcceptDrops(True)
Пример #8
0
    def openFile(self):
        fname = self.filename
        try:
            os.remove(fname + '.py')
        except:
            pass
        if self.modified:
            ret = self.askSaving()
            if ret == QMessageBox.Save:
                self.saveFile()
            elif ret == QMessageBox.Cancel:
                return
            self.scene.newDgm()

        filename = QFileDialog.getOpenFileName(self,
                                               'Open',
                                               '.',
                                               filter='*.dgm')
        filename = filename[0]
        if filename != '':
            fname = QtCore.QFileInfo(filename)
            self.filename = str(fname.baseName())
            self.path = str(fname.absolutePath())
            self.setWindowTitle(self.filename)
            self.scene.loadDgm(self.getFullFileName())
            self.modified = False
Пример #9
0
    def P09(self, obj, event):
        try:
            item = self.itemAt(event.scenePos())
        except:
            item = None
        if isinstance(item, InPort):
            if len(item.connections) == 0:
                self.scene.DgmToUndo()
                self.conn.port2 = item
                self.conn.pos2 = item.scenePos()
                self.conn.port1.connections.append(self.conn)
                self.conn.port2.connections.append(self.conn)
                if isinstance(self.conn.port1, OutPort):
                    pos = QtCore.QPointF(
                        (self.conn.pos2.x() + self.conn.pos1.x()) / 2,
                        self.conn.pos1.y())
                    self.newNode(self.conn, pos)

                self.conn.update_path()
                self.conn = None
                self.state = IDLE
                #self.scene.mainw.status.showMessage('IDLE')
        else:
            pt = self.genInterPoint(self.conn.pos2)
            b = Node(None, self.scene)
            b.setPos(pt)
            self.conn.port2 = b.port_in
            self.conn.pos2 = b.scenePos()
            self.conn.port1.connections.append(self.conn)
            self.conn.port2.connections.append(self.conn)
            self.conn.update_path()
            self.conn = None
            self.state = IDLE
Пример #10
0
 def setPos(self, *args):
     if len(args) == 1:
         pt = self.gridPos(args[0])
         super(Block, self).setPos(pt)
     else:
         pt = QtCore.QPointF(args[0], args[1])
         pt = self.gridPos(pt)
         super(Block, self).setPos(pt)
Пример #11
0
    def update_path(self):
        p = QPainterPath()
        item = None
        if self.port2 == None:
            item = self.scene.find_itemAt(self.pos2)
        if isinstance(self.port1, OutPort):
            pt = QtCore.QPointF(self.pos2.x(),self.pos1.y())
        elif isinstance(self.port2, InPort) or isinstance(item, InPort):
            pt = QtCore.QPointF(self.pos1.x(),self.pos2.y())
        else:
            dx = np.abs(self.pos2.x()-self.pos1.x())
            dy = np.abs(self.pos2.y()-self.pos1.y())
            if dx > dy:
                pt = QtCore.QPointF(self.pos2.x(),self.pos1.y())
            else:
                pt = QtCore.QPointF(self.pos1.x(),self.pos2.y())

        p.moveTo(self.pos1)
        p.lineTo(pt)
        p.lineTo(self.pos2)
        self.setPath(p)
Пример #12
0
 def saveFile(self):
     filename = QFileDialog.getSaveFileName(self,
                                            'Save',
                                            self.path + '/' + self.filename,
                                            filter='*.dgm')
     filename = filename[0]
     if filename != '':
         fname = QtCore.QFileInfo(filename)
         self.filename = str(fname.baseName())
         self.path = str(fname.absolutePath())
         self.setWindowTitle(self.filename)
         self.scene.saveDgm(self.getFullFileName())
         self.modified = False
Пример #13
0
 def mouseMoveEvent(self, event):
     if event.buttons() == QtCore.Qt.LeftButton and isinstance(
             self.actComp, Block):
         mimeData = QtCore.QMimeData()
         if self.actComp.iosetble:
             io = '1'
         else:
             io = '0'
         data = self.actComp.name + '@' + self.actComp.inp.__str__(
         ) + '@' + self.actComp.outp.__str__(
         ) + '@' + io + '@' + self.actComp.icon + '@' + self.actComp.params
         mimeData.setText(data)
         drag = QDrag(self.parent)
         drag.setMimeData(mimeData)
         drag.exec_(QtCore.Qt.CopyAction)
Пример #14
0
 def bindNode(self):
     self.scene.DgmToUndo()
     item = self.scene.item
     if len(item.port_out.connections) == 1:
         c1 = item.port_in.connections[0]
         c2 = item.port_out.connections[0]
         c = Connection(None, self.scene)
         c.pos1 = c1.pos1
         c.pos2 = c2.pos2
         item.remove()
         c.update_ports_from_pos()
         if isinstance(c.port1, OutPort) and isinstance(c.port2, InPort):
             pos = QtCore.QPointF((c.pos2.x() + c.pos1.x()) / 2, c.pos1.y())
             self.newNode(c, pos)
     else:
         self.scene.clearLastUndo()
Пример #15
0
    def P08(self, obj, event):
        item = self.itemAt(event.scenePos())
        if isinstance(item, InPort):
            if len(item.connections) == 0:
                self.scene.DgmToUndo()
                self.conn.port2 = item
                self.conn.pos2 = item.scenePos()
                self.conn.port1.connections.append(self.conn)
                self.conn.port2.connections.append(self.conn)
                if isinstance(self.conn.port1, OutPort):
                    pos = QtCore.QPointF(
                        (self.conn.pos2.x() + self.conn.pos1.x()) / 2,
                        self.conn.pos1.y())
                    self.newNode(self.conn, pos)

                self.conn.update_path()
                self.conn = None
                self.state = IDLE
                #self.scene.mainw.status.showMessage('IDLE')

        if isinstance(item, Node):
            if item.port_in.connections == []:
                self.scene.DgmToUndo()
                self.conn.port2 = item.port_in
                self.conn.pos2 = item.scenePos()
                self.conn.port1.connections.append(self.conn)
                self.conn.port2.connections.append(self.conn)  # Problema qui!

                self.conn.update_path()
                self.conn = None
                self.state = IDLE
                #self.scene.mainw.status.showMessage('IDLE')

        if item == None:
            pt = self.genInterPoint(event.scenePos())
            b = Node(None, self.scene)
            b.setPos(pt)
            self.conn.port2 = b.port_in
            self.conn.pos2 = b.scenePos()
            self.conn.port1.connections.append(self.conn)
            self.conn.port2.connections.append(self.conn)
            self.conn.update_path()

            self.conn = Connection(None, self.scene)
            self.conn.port1 = b.port_out
            self.conn.pos1 = b.scenePos()
            self.conn.pos2 = b.scenePos()
Пример #16
0
    def __init__(self, filename='untitled', runflag=False):
        if filename != 'untitled':
            self.fname = QtCore.QFileInfo(filename)
            self.mypath = str(self.fname.absolutePath())
            self.fname = str(self.fname.baseName())
        else:
            self.fname = 'untitled'
            self.mypath = os.getcwd()
        self.runflag = runflag

        app = QApplication(sys.argv)
        library = Library()
        library.setGeometry(20, 20, 400, 980)
        library.show()
        main = SupsiSimMainWindow(library, self.fname, self.mypath,
                                  self.runflag)
        main.setGeometry(500, 100, 1024, 768)

        main.show()
        ret = app.exec_()
        app.deleteLater()
Пример #17
0
 def cloneBlock(self):
     self.scene.DgmToUndo()
     item = self.scene.item
     item.clone(QtCore.QPointF(100, 100))
Пример #18
0
 def gridPos(self, pt):
     gr = GRID
     x = gr * ((pt.x() + gr / 2) // gr)
     y = gr * ((pt.y() + gr / 2) // gr)
     return QtCore.QPointF(x, y)