def startLineDraw(self, event): # highlight all ports that match startItems = self.items(event.scenePos()) if len(startItems): if isinstance(startItems[0], OutPort): if QtCore.Qt.AltModifier == getKeyboardModifiers(): startItems[0].toggleMemSaver() return self.portMatches = startItems[0].findMatchingInPorts() for port in self.portMatches: port.scaleUp() self.graph.viewAndSceneForcedUpdate() if isinstance(startItems[0], InPort): self.portMatches = startItems[0].findMatchingOutPorts() for port in self.portMatches: port.scaleUp() self.graph.viewAndSceneForcedUpdate() self.line = QtGui.QGraphicsLineItem( QtCore.QLineF(event.scenePos(), event.scenePos())) fade = QtGui.QColor(QtCore.Qt.red) fade.setAlpha(150) self.line.setPen(QtGui.QPen(fade, 2)) self.line.setZValue(10) self.addItem(self.line)
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))
def paint(self, painter, option, widget): # EDGE if not self.source or not self.dest: return # Draw the line itself. line = QtCore.QLineF(self.sourcePoint, self.destPoint) if line.length() == 0.0: return if self.isSelected( ) or self._beingHovered or self.connectedPortIsHovered(): fade = QtGui.QColor(QtCore.Qt.red) fade.setAlpha(200) #painter.setPen(QtGui.QPen(QtCore.Qt.red, 1, QtCore.Qt.DashLine, painter.setPen( QtGui.QPen(fade, 2, QtCore.Qt.SolidLine, QtCore.Qt.RoundCap, QtCore.Qt.RoundJoin)) elif self.isCyclicConnection(): painter.setPen( QtGui.QPen(QtCore.Qt.red, 2, QtCore.Qt.SolidLine, QtCore.Qt.RoundCap, QtCore.Qt.RoundJoin)) else: fade = QtGui.QColor(QtCore.Qt.black) fade.setAlpha(150) #painter.setPen(QtGui.QPen(QtCore.Qt.black, 2, QtCore.Qt.SolidLine, painter.setPen( QtGui.QPen(fade, 2, QtCore.Qt.SolidLine, QtCore.Qt.RoundCap, QtCore.Qt.RoundJoin)) painter.drawLine(line) x = (line.x1() + line.x2()) / 2.0 y = (line.y1() + line.y2()) / 2.0 xa = (line.x1() - line.x2()) ya = (line.y1() - line.y2()) m = math.sqrt(xa * xa + ya * ya) a = math.atan2(ya, xa) * 180.0 / math.pi buf = self.source.getDataString() if self._beingHovered: f = QtGui.QFont("Times New Roman", 8) else: f = QtGui.QFont("Times New Roman", 6) fm = QtGui.QFontMetricsF(f) bw = fm.width(buf) bw2 = -bw * 0.5 #bh = fm.height() # bezier curves if False: sa = (a + 90.) * 0.5 path = QtGui.QPainterPath(line.p1()) path.cubicTo(x - sa, y - sa, x + sa, y + sa, line.x2(), line.y2()) painter.drawPath(path) # bezier curves, change direction on the angle if False: sa = (a + 90.) * 0.5 if a > 90 or a < -90: path = QtGui.QPainterPath(line.p1()) path.cubicTo(x - sa, y - sa, x + sa, y + sa, line.x2(), line.y2()) painter.drawPath(path) else: path = QtGui.QPainterPath(line.p1()) path.cubicTo(x + sa, y + sa, x - sa, y - sa, line.x2(), line.y2()) painter.drawPath(path) painter.setFont(f) if self._beingHovered: painter.setPen(QtGui.QPen(QtCore.Qt.red, 1)) else: painter.setPen(QtGui.QPen(QtCore.Qt.darkGray, 1)) painter.save() painter.translate(QtCore.QPointF(x, y)) if m > bw * 1.1 or self._beingHovered: if a > 90 or a < -90: painter.rotate(a + 180.0) painter.drawText(QtCore.QPointF(bw2, -2.0), buf) else: painter.rotate(a) painter.drawText(QtCore.QPointF(bw2, -2.0), buf) else: painter.drawText(QtCore.QPointF(bw2, -2.0), '') painter.restore()
def paint(self, painter, option, widget): # NODE w = self.getNodeWidth() # h = self.getTitleWidth()[1] # draw shadow painter.setPen(QtCore.Qt.NoPen) painter.setBrush(QtCore.Qt.darkGray) painter.drawRoundedRect(-8, -8, w, 20, 3, 3) # choose module color gradient = QtGui.QRadialGradient(-10, -10, 40) # update the face node based on the state of internal nodes. if self._role == 'Macro': if self._macroParent.isProcessing(): gradient.setColorAt(0, QtGui.QColor(QtCore.Qt.gray).lighter(70)) gradient.setColorAt( 1, QtGui.QColor(QtCore.Qt.darkGray).lighter(70)) elif (option.state & QtGui.QStyle.State_Sunken) or ( self._macroParent.inComputeErrorState()): gradient.setColorAt(0, QtGui.QColor(QtCore.Qt.red).lighter(150)) gradient.setColorAt(1, QtGui.QColor(QtCore.Qt.red).lighter(170)) elif self._macroParent.inValidateErrorState(): gradient.setColorAt( 0, QtGui.QColor(QtCore.Qt.yellow).lighter(190)) gradient.setColorAt( 1, QtGui.QColor(QtCore.Qt.yellow).lighter(170)) elif self._macroParent.inInitUIErrorState(): gradient.setColorAt(0, QtGui.QColor(QtCore.Qt.red).lighter(150)) gradient.setColorAt( 1, QtGui.QColor(QtCore.Qt.yellow).lighter(170)) else: gradient.setColorAt(0, QtGui.QColor(QtCore.Qt.gray).lighter(150)) gradient.setColorAt( 1, QtGui.QColor(QtCore.Qt.darkGray).lighter(150)) # let the src and sink nodes update themselves normally else: conf = self.getCurState() if self._computeState is conf: gradient.setColorAt(0, QtGui.QColor(QtCore.Qt.gray).lighter(70)) gradient.setColorAt( 1, QtGui.QColor(QtCore.Qt.darkGray).lighter(70)) elif (option.state & QtGui.QStyle.State_Sunken) or ( self._computeErrorState is conf): gradient.setColorAt(0, QtGui.QColor(QtCore.Qt.red).lighter(150)) gradient.setColorAt(1, QtGui.QColor(QtCore.Qt.red).lighter(170)) elif self._validateError is conf: gradient.setColorAt( 0, QtGui.QColor(QtCore.Qt.yellow).lighter(190)) gradient.setColorAt( 1, QtGui.QColor(QtCore.Qt.yellow).lighter(170)) else: gradient.setColorAt(0, QtGui.QColor(QtCore.Qt.gray).lighter(150)) gradient.setColorAt( 1, QtGui.QColor(QtCore.Qt.darkGray).lighter(150)) # draw module box (apply color) painter.setBrush(QtGui.QBrush(gradient)) if self.beingHovered or self.isSelected(): #painter.setPen(QtGui.QPen(QtCore.Qt.red, 1)) fade = QtGui.QColor(QtCore.Qt.red) fade.setAlpha(100) painter.setPen(QtGui.QPen(fade, 2)) else: #painter.setPen(QtGui.QPen(QtCore.Qt.black, 0)) fade = QtGui.QColor(QtCore.Qt.black) fade.setAlpha(50) painter.setPen(QtGui.QPen(fade, 0)) painter.drawRoundedRect(-10, -10, w, 20, 3, 3) # title painter.setPen(QtGui.QPen(QtCore.Qt.black, 0)) painter.setFont(self.title_font) buf = self.getMacroNodeName() # paint the node title painter.drawText(-5, -9, w, 20, (QtCore.Qt.AlignLeft | QtCore.Qt.AlignVCenter), str(buf))
def paint(self, painter, option, widget): # PORT # choose module color gradient = QtGui.QRadialGradient(-1, -1, 10) if option.state & QtGui.QStyle.State_Sunken: gradient.setColorAt(0, QtGui.QColor(QtCore.Qt.red).lighter(150)) gradient.setColorAt(1, QtGui.QColor(QtCore.Qt.darkRed).lighter(150)) # elif self._beingHovered: # gradient.setColorAt(0, QtGui.QColor(QtCore.Qt.darkRed).lighter(150)) # gradient.setColorAt(1, QtGui.QColor(QtCore.Qt.red).lighter(150)) elif isinstance(self, InPort): # if self.menuWidget: if self.isREQUIRED(): # gradient.setColorAt(0, QtGui.QColor(QtCore.Qt.yellow).lighter(200)) # gradient.setColorAt(1, # QtGui.QColor(QtCore.Qt.darkYellow).lighter(200)) gradient.setColorAt(0, QtGui.QColor(QtCore.Qt.blue).lighter(200)) gradient.setColorAt( 1, QtGui.QColor(QtCore.Qt.darkBlue).lighter(200)) # gradient.setColorAt(1, QtGui.QColor(QtCore.Qt.gray).lighter(300)) # gradient.setColorAt(0, # QtGui.QColor(QtCore.Qt.darkGray).lighter(150)) else: gradient.setColorAt(0, QtGui.QColor(QtCore.Qt.green).lighter(200)) gradient.setColorAt( 1, QtGui.QColor(QtCore.Qt.darkGreen).lighter(150)) # gradient.setColorAt(0, QtGui.QColor(QtCore.Qt.gray).lighter(150)) # gradient.setColorAt(1, # QtGui.QColor(QtCore.Qt.darkGray).lighter(100)) elif isinstance(self, OutPort): # if self.menuWidget: # orange=QtGui.QColor().fromRgbF(1.,0.5,0.) # gradient.setColorAt(0, orange.lighter(200)) # gradient.setColorAt(1, orange.lighter(100)) # gradient.setColorAt(0, QtGui.QColor(QtCore.Qt.blue).lighter(300)) # gradient.setColorAt(1, # QtGui.QColor(QtCore.Qt.darkBlue).lighter(300)) if self.dataIsNone(): gradient.setColorAt(1, QtGui.QColor(QtCore.Qt.red).lighter(300)) gradient.setColorAt( 0, QtGui.QColor(QtCore.Qt.darkRed).lighter(150)) elif self.dataHasChanged(): # gradient.setColorAt(1, QtGui.QColor(QtCore.Qt.gray).lighter(200)) # gradient.setColorAt(0, # QtGui.QColor(QtCore.Qt.darkGray).lighter(100)) gradient.setColorAt(1, QtGui.QColor(QtCore.Qt.blue).lighter(200)) gradient.setColorAt( 0, QtGui.QColor(QtCore.Qt.darkBlue).lighter(200)) else: gradient.setColorAt( 1, QtGui.QColor(QtCore.Qt.yellow).lighter(200)) gradient.setColorAt( 0, QtGui.QColor(QtCore.Qt.darkYellow).lighter(150)) # else: # gradient.setColorAt(0, QtGui.QColor(QtCore.Qt.blue).lighter(175)) # gradient.setColorAt(1, QtGui.QColor(QtCore.Qt.darkBlue).lighter(175)) # gradient.setColorAt(0, QtGui.QColor(QtCore.Qt.gray).lighter(150)) # gradient.setColorAt(1, QtGui.QColor(QtCore.Qt.darkGray).lighter(100)) # if self.dataIsNone(): # gradient.setColorAt(0, QtGui.QColor(QtCore.Qt.red).lighter(150)) # gradient.setColorAt(1, QtGui.QColor(QtCore.Qt.darkRed).lighter(100)) # elif self.dataHasChanged(): # gradient.setColorAt(0, QtGui.QColor(QtCore.Qt.gray).lighter(150)) # gradient.setColorAt(1, QtGui.QColor(QtCore.Qt.darkGray).lighter(100)) # else: # gradient.setColorAt(0, QtGui.QColor(QtCore.Qt.yellow).lighter(200)) # gradient.setColorAt(1, # QtGui.QColor(QtCore.Qt.darkYellow).lighter(150)) # draw module box (apply color) painter.setBrush(QtGui.QBrush(gradient)) #painter.setPen(QtGui.QPen(QtCore.Qt.black, 0)) fade = QtGui.QColor(QtCore.Qt.black) fade.setAlpha(50) painter.setPen(QtGui.QPen(fade, 0)) # if isinstance(self,InPort): # if self.isREQUIRED(): # painter.setPen(QtGui.QPen(QtCore.Qt.red, 0)) # else: # painter.setPen(QtGui.QPen(QtCore.Qt.black, 0)) # #painter.setPen(QtGui.QPen(QtCore.Qt.yellow, 0)) if self.isMemSaver(): painter.drawPolygon(self.portShape_memSave) else: if self.menuWidget: painter.drawEllipse(1, 0, 5, 5) else: painter.drawPolygon(self.portShape)
def __init__(self, image_path): # find the limiting desktop dimension (w or h) pm = QtGui.QPixmap.fromImage(QtGui.QImage(image_path)) g = QtGui.QDesktopWidget().availableGeometry() w = g.width() h = g.height() r = float(pm.width()) / pm.height() # aspect ratio if (w <= pm.width()): h = int(w / r) if (h <= pm.height()): w = int(h * r) # the splash is almost useless below 500pts if w < 500: w = 500 # resize the image based on new width if (w != g.width()) or (h != g.height()): pm = pm.scaledToWidth(int(w * 0.8), mode=QtCore.Qt.SmoothTransformation) # scale subsequent parameters based on new image width iw = pm.width() ih = pm.height() super(Splash, self).__init__(pm) # use a timer instead of the EULA self._timer = QtCore.QTimer() self._timer.timeout.connect(self.terms_accepted.emit) self._timer.setSingleShot(True) if not INCLUDE_EULA: self._timer.start(2000) panel = QtGui.QWidget() pal = QtGui.QPalette(QtGui.QColor(255, 255, 255)) # white panel.setAutoFillBackground(True) panel.setPalette(pal) lic = ''' THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. ''' self.lic = QtGui.QTextEdit(lic) self.lic.setReadOnly(True) button_title = 'Agree' self.wdg1 = QtGui.QPushButton(button_title, self) self.wdg1.setCheckable(False) self.wdg1.setFixedSize(int(iw * 0.2), int(iw * 0.05)) self.wdg1.clicked[bool].connect(self.accept) button_title = 'Quit' self.wdg2 = QtGui.QPushButton(button_title, self) self.wdg2.setCheckable(False) self.wdg2.setFixedSize(int(iw * 0.2), int(iw * 0.05)) self.wdg2.clicked[bool].connect(self.reject) buf = 'Click Agree to start GPI or Quit to exit.' new_fw = iw * 0.45 for fw_i in range(20, 0, -1): f = QtGui.QFont('gill sans', fw_i) fm = QtGui.QFontMetricsF(f) cfw = fm.width(buf) if cfw < new_fw: break f = QtGui.QFont('gill sans', fw_i) self.prompt = QtGui.QLabel(buf) self.prompt.setAlignment(QtCore.Qt.AlignCenter) self.prompt.setFont(f) wdgLayout = QtGui.QHBoxLayout() #wdgLayout.setContentsMargins(0, 0, 0, 0) # no spaces around this item #wdgLayout.setSpacing(0) #wdgLayout.addSpacerItem(QtGui.QSpacerItem(iw/2,1,hPolicy=QtGui.QSizePolicy.Minimum)) wdgLayout.addWidget(self.prompt) wdgLayout.addWidget(self.wdg1) #wdgLayout.addSpacerItem(QtGui.QSpacerItem(int(iw*0.01),1,hPolicy=QtGui.QSizePolicy.Minimum)) wdgLayout.addWidget(self.wdg2) #wdgLayout.addSpacerItem(QtGui.QSpacerItem(1,1,hPolicy=QtGui.QSizePolicy.MinimumExpanding)) # a small panel vbox_p = QtGui.QVBoxLayout() vbox_p.setContentsMargins(10, 10, 10, 10) vbox_p.setSpacing(10) vbox_p.addWidget(self.lic) vbox_p.addLayout(wdgLayout) panel.setLayout(vbox_p) # white space | panel vbox = QtGui.QVBoxLayout() #vbox.setContentsMargins(0, 0, 0, int(iw*0.02)) # no spaces around this item vbox.setContentsMargins(0, 0, 0, 0) # no spaces around this item vbox.setSpacing(0) vbox.addSpacerItem( QtGui.QSpacerItem(iw, (1 - 0.28) * ih, hPolicy=QtGui.QSizePolicy.Minimum, vPolicy=QtGui.QSizePolicy.Minimum)) #vbox.addWidget(self.lic) vbox.addWidget(panel) #vbox.addLayout(wdgLayout) if INCLUDE_EULA: self.setLayout(vbox) self._accept = False