def applyShape(self): '''Grab external QT rendering command. ''' GL.glColor4d(*self._RGBA) f = QtGui.QFont(str(self._font), self._ptsize) p = self._position if self._glwdg is None: log.critical('Reference to GLWidget is not set! Aborting render.') else: self._glwdg.renderText(p[0], p[1], p[2], self._text, f)
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 __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
def paint(self, painter, option, widget): 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 painter.setPen( QtGui.QPen(QtCore.Qt.gray, self.penWidth, QtCore.Qt.SolidLine, QtCore.Qt.RoundCap, QtCore.Qt.RoundJoin)) painter.drawLine(line) # drawing text 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 = "Macro" f = QtGui.QFont("times", 20) fm = QtGui.QFontMetricsF(f) bw = fm.width(buf) bw2 = -bw * 0.5 # bh = fm.height() # Draw the arrows if there's enough room. angle = math.acos(line.dx() / line.length()) if line.dy() >= 0: angle = self.TwoPi - angle sourceArrowP1 = self.sourcePoint + QtCore.QPointF( math.sin(angle + self.Pi / 3) * self.arrowSize, math.cos(angle + self.Pi / 3) * self.arrowSize) sourceArrowP2 = self.sourcePoint + QtCore.QPointF( math.sin(angle + self.Pi - self.Pi / 3) * self.arrowSize, math.cos(angle + self.Pi - self.Pi / 3) * self.arrowSize) destArrowP1 = self.destPoint + QtCore.QPointF( math.sin(angle - self.Pi / 3) * self.arrowSize, math.cos(angle - self.Pi / 3) * self.arrowSize) destArrowP2 = self.destPoint + QtCore.QPointF( math.sin(angle - self.Pi + self.Pi / 3) * self.arrowSize, math.cos(angle - self.Pi + self.Pi / 3) * self.arrowSize) painter.setBrush(QtCore.Qt.gray) painter.drawPolygon( QtGui.QPolygonF([line.p1(), sourceArrowP1, sourceArrowP2])) painter.drawPolygon( QtGui.QPolygonF([line.p2(), destArrowP1, destArrowP2])) # drawing text painter.setFont(f) painter.setPen(QtGui.QPen(QtCore.Qt.darkGray, 1)) painter.save() painter.translate(QtCore.QPointF(x, y)) if m > bw * 1.1: if a > 90 or a < -90: painter.rotate(a + 180.0) painter.drawText(QtCore.QPointF(bw2, -5.0), buf) else: painter.rotate(a) painter.drawText(QtCore.QPointF(bw2, -5.0), buf) else: painter.drawText(QtCore.QPointF(bw2, -5.0), '') painter.restore()
def __init__(self, node): super(NodeAPI, self).__init__() #self.setToolTip("Double Click to Show/Hide each Widget") self.node = node self.label = '' self._detailLabel = '' self._docText = None self.parmList = [] # deprecated, since dicts have direct name lookup self.parmDict = {} # mirror parmList for now self.parmSettings = {} # for buffering wdg parms before copying to a PROCESS self.shdmDict = {} # for storing base addresses # grid for module widgets self.layout = QtWidgets.QGridLayout() # this must exist before user-widgets are added so that they can get # node label updates self.wdglabel = QtWidgets.QLineEdit(self.label) # allow logger to be used in initUI() self.log = manager.getLogger(node.getModuleName()) try: self._initUI_ret = self.initUI() except: log.error('initUI() failed. '+str(node.item.fullpath)+'\n'+str(traceback.format_exc())) self._initUI_ret = -1 # error # make a label box with the unique id labelGroup = HidableGroupBox("Node Label") labelLayout = QtWidgets.QGridLayout() self.wdglabel.textChanged.connect(self.setLabel) labelLayout.addWidget(self.wdglabel, 0, 1) labelGroup.setLayout(labelLayout) self.layout.addWidget(labelGroup, len(self.parmList) + 1, 0) labelGroup.set_collapsed(True) labelGroup.setToolTip("Displays the Label on the Canvas (Double Click)") # make an about box with the unique id self.aboutGroup = HidableGroupBox("About") aboutLayout = QtWidgets.QGridLayout() self.about_button = QtWidgets.QPushButton("Open Node &Documentation") self.about_button.clicked.connect(self.openNodeDocumentation) aboutLayout.addWidget(self.about_button, 0, 1) self.aboutGroup.setLayout(aboutLayout) self.layout.addWidget(self.aboutGroup, len(self.parmList) + 2, 0) self.aboutGroup.set_collapsed(True) self.aboutGroup.setToolTip("Node Documentation (docstring + autodocs, Double Click)") # window (just a QTextEdit) that will show documentation text self.doc_text_win = QtWidgets.QTextEdit() self.doc_text_win.setPlainText(self.generateHelpText()) self.doc_text_win.setReadOnly(True) doc_text_font = QtGui.QFont("Monospace", 14) self.doc_text_win.setFont(doc_text_font) self.doc_text_win.setLineWrapMode(QtWidgets.QTextEdit.NoWrap) self.doc_text_win.setWindowTitle(node.getModuleName() + " Documentation") hbox = QtWidgets.QHBoxLayout() self._statusbar_sys = QtWidgets.QLabel('') self._statusbar_usr = QtWidgets.QLabel('') hbox.addWidget(self._statusbar_sys) hbox.addWidget(self._statusbar_usr, 0, (QtCore.Qt.AlignRight | QtCore.Qt.AlignVCenter)) # window resize grip self._grip = QtWidgets.QSizeGrip(self) hbox.addWidget(self._grip) self.layout.addLayout(hbox, len(self.parmList) + 3, 0) self.layout.setRowStretch(len(self.parmList) + 3, 0) # uid display # uid = QtWidgets.QLabel("uid: "+str(self.node.getID())) # uid.setTextInteractionFlags(QtCore.Qt.TextSelectableByMouse) # self.layout.addWidget(uid,len(self.parmList)+2,0) # instantiate the layout self.setLayout(self.layout) # run through all widget titles since each widget parent is now set. for parm in self.parmList: parm.setDispTitle() # instantiate the layout # self.setGeometry(50, 50, 300, 40) self.setTitle(node.getModuleName()) self._starttime = 0 self._startline = 0