示例#1
0
文件: edge.py 项目: schudds/framework
    def __init__(self, graph, destPort, sourcePort):
        super(EdgeTracer, self).__init__()

        # show a faux copy of the delete menu
        menu = QtWidgets.QMenu()
        menu.addAction("Delete")

        # position of pipe end based on port type
        bindout_y = 5
        bindin_y = -1
        p1 = self.mapFromItem(sourcePort, 3.5, bindin_y)
        p2 = self.mapFromItem(destPort, 3.5, bindout_y)

        pos = graph.mapToGlobal(graph.mapFromScene((p1 - p2) / 2 + p2))

        # render the menu without executing it
        try:
            # PyQt4
            menupixmap = QtGui.QPixmap().grabWidget(menu)
        except AttributeError:
            menupixmap = menu.grab()  # QtGui.QPixmap().grabWidget(menu)

        # round edges
        #mask = menupixmap.createMaskFromColor(QtGui.QColor(255, 255, 255), QtCore.Qt.MaskOutColor)
        #p = QtGui.QPainter(menupixmap)
        #p.setRenderHint(QtGui.QPainter.Antialiasing)
        #p.drawRoundedRect(0,0,menupixmap.width(),menupixmap.height(), 5,5)
        #p.drawPixmap(menupixmap.rect(), mask, mask.rect())
        #p.end()

        # display the menu image (as a dummy menu as its being built)
        # TODO: this could probably be moved to the FauxMenu
        self._tracer = QtWidgets.QLabel()
        self._tracer.setWindowFlags(QtCore.Qt.Tool
                                    | QtCore.Qt.FramelessWindowHint)
        self._tracer.move(pos)
        self._tracer.setPixmap(menupixmap)
        self._tracer.show()
        self._tracer.raise_()

        # draw a faux selected line
        line = QtCore.QLineF(p1, p2)
        self.setPen(
            QtGui.QPen(QtGui.QColor(QtCore.Qt.red), 2, QtCore.Qt.DashLine,
                       QtCore.Qt.RoundCap, QtCore.Qt.RoundJoin))
        self.setLine(line)
        self.setZValue(0)

        # cleanup both menu item and line by removing from scene (parent).
        self._timer = QtCore.QTimer()
        self._timer.singleShot(300, lambda: graph.scene().removeItem(self))
示例#2
0
    def searchMenu(self, txt, parent, mousemenu):
        # this menu needs to be rebuilt everytime a character changes

        # don't bother if the user just cleared the search
        if len(txt) == 0:
            return

        pos = self._parent.mapToGlobal(self._parent._event_pos + QtCore.QPoint(mousemenu.sizeHint().width(), 0))

        # generate the menu
        menu = QtGui.QMenu(self._parent)
        self.generateNodeSearchActions(str(txt), menu, mousemenu)

        # render the menu without executing it
        menupixmap = QtGui.QPixmap().grabWidget(menu)

        # display the menu image (as a dummy menu as its being built)
        # TODO: this could probably be moved to the FauxMenu
        self._listwdg = FauxMenu(menu, pos)
        self._listwdg.setWindowFlags(QtCore.Qt.Tool | QtCore.Qt.FramelessWindowHint)
        self._listwdg.move(pos)
        self._listwdg.setPixmap(menupixmap)
        self._listwdg.show()
        self._listwdg.raise_()
示例#3
0
 def clearPixmap(self):
     self.setPixmap(QtGui.QPixmap())