def __init__(self, color, edgeColor, highlightColor, ioType, parent=None): super(Plug, self).__init__(parent=parent) size = QtCore.QSizeF(self._diameter, self._diameter) self.ioType = "" self.setSizePolicy(QtWidgets.QSizePolicy(QtWidgets.QSizePolicy.Fixed, QtWidgets.QSizePolicy.Fixed)) self.setPreferredSize(size) self.setWindowFrameMargins(0, 0, 0, 0) self._defaultPen = QtGui.QPen(edgeColor, 2.5) self._hoverPen = QtGui.QPen(highlightColor, 3.0) self._defaultBrush = QtGui.QBrush(color) self._currentBrush = QtGui.QBrush(color) self.setAcceptHoverEvents(True)
def querybrush(self): if self.mode == self.modes.mode_render: brush = qg.QBrush(qc.Qt.NoBrush) else: if self.state == self.states.state_hover: brush = qg.QBrush(qg.QColor.fromRgbF(1, .5, 0, 1), qc.Qt.SolidPattern) if self.state == self.states.state_pressed: brush = qg.QBrush(qg.QColor.fromRgbF(1, 0, 0, 1), qc.Qt.SolidPattern) if self.state == self.states.state_neutral: brush = qg.QBrush(qg.QColor.fromRgbF(0, 0, 0, 1), qc.Qt.SolidPattern) return brush
def showtraceback(self): self._outputBrush = QtGui.QBrush(QtGui.QColor('#ff0000')) try: InteractiveInterpreter.showtraceback(self) finally: self._outputBrush = None
def __init__(self, generic, *args, **kwargs): try: self.pen_color = kwargs.pop('pen_color ') except KeyError: pass try: self.brush_color = kwargs.pop('brush_color') except KeyError: pass self.generic = generic super(Static, self).__init__(*args, **kwargs) self.setZValue(self.z_value) self.setAcceptHoverEvents(True) self.setselectable(False) pen = qg.QPen(qg.QColor.fromRgbF(*self.pen_color), self.linewidth, self.style, self.capstyle, self.joinstyle) pen.setCosmetic(True) self.setPen(pen) brush = qg.QBrush(qg.QColor.fromRgbF(*self.brush_color), self.brushpattern) self.setBrush(brush) self.refreshview() self.updateshape()
def showsyntaxerror(self, filename = None): self._outputBrush = QtGui.QBrush(QtGui.QColor('#ffcc63')) try: InteractiveInterpreter.showsyntaxerror(self, filename) finally: self._outputBrush = None
def __init__(self): self.setItemIndexMethod(self.NoIndex) self.constraints_on = False self.setSceneRect(qc.QRectF(0, 0, 1000, 1000)) self.setBackgroundBrush( qg.QBrush( qg.QColor.fromRgbF(*popupcad.graphics_scene_background_color), qc.Qt.SolidPattern)) self.temp = None self.extraobjects = [] self.nextgeometry = None
def paint(self, painter, option, widget=0): if not self.selected: return contents = self.contentsRect() painter.save() # temp painter.setPen(QtGui.QPen(QtGui.QColor(125, 162, 206, 192))) painter.setBrush(QtGui.QBrush(QtGui.QColor(217, 232, 252, 192))) painter.drawRoundedRect(QtCore.QRectF(contents.topLeft(), self.geometry().size()), 3, 3) painter.restore()
def drawRect(painter, option, color): points = (QtCore.QPoint(option.rect.x() + 5, option.rect.y()), QtCore.QPoint(option.rect.x(), option.rect.y()), QtCore.QPoint(option.rect.x(), option.rect.y() + 5)) polygonTriangle = QtGui.QPolygon.fromList(points) painter.save() painter.setRenderHint(painter.Antialiasing) painter.setBrush(QtGui.QBrush(color)) painter.setPen(QtGui.QPen(color)) painter.drawPolygon(polygonTriangle) painter.restore()
def paint(self, painter, option, widget=None): """ Paint the node in the graphic view. """ if self.isSelected(): color = self.selectedColor else: color = self.unSelectedColor painter.setBrush(QtGui.QBrush(color)) painter.setPen(QtGui.QPen(self.edgeColor, 1.0, QtCore.Qt.SolidLine)) painter.drawRect(self.rect()) painter.setRenderHint(QtGui.QPainter.Antialiasing) if self.hovering: painter.setBrush(QtGui.QBrush(self.handleColor)) painter.setPen( QtGui.QPen(self.edgeColor, 1.0, QtCore.Qt.SolidLine, QtCore.Qt.RoundCap, QtCore.Qt.RoundJoin)) for handle, rect in self.handles.items(): if self.handleSelected is None or handle == self.handleSelected: painter.drawEllipse(rect)
def __init__(self, objectModel, position=(0, 0, 0)): super(GraphicsNode, self).__init__() self.setFlag(QtWidgets.QGraphicsItem.ItemIsSelectable, True) self.setSizePolicy( QtWidgets.QSizePolicy(QtWidgets.QSizePolicy.Expanding, QtWidgets.QSizePolicy.Expanding)) self.setMinimumWidth(objectModel.minimumWidth()) self.setMinimumHeight(objectModel.minimumHeight()) self.model = objectModel self.backgroundColour = QtGui.QBrush(self.model.backgroundColour()) self.cornerRounding = self.model.cornerRounding() self.setZValue(1) self.setPos(position)
def __init__(self, generic, *args, **kwargs): super(TextParent, self).__init__(*args, **kwargs) self.generic = generic self.editchild = TextItem(generic, self) self.setFlag(qg.QGraphicsItem.ItemIsMovable, True) self.setFlag(qg.QGraphicsItem.ItemIsSelectable, True) self.setFlag(qg.QGraphicsItem.ItemIsFocusable, True) self.pen = qg.QPen(qg.QColor.fromRgbF(0,0,0,1),1,qc.Qt.SolidLine,qc.Qt.RoundCap,qc.Qt.RoundJoin) self.pen.setCosmetic(True) self.brush = qg.QBrush(qg.QColor.fromRgbF(0, 0, 0, .25), qc.Qt.SolidPattern) self.setPen(self.pen) self.setBrush(self.brush) self.setPos(*self.generic.pos.getpos(scaling = popupcad.view_scaling)) self.setFlag(self.ItemSendsGeometryChanges, True) self.changed_trigger = False
# Unless required by applicable law or agreed to in writing, software # distributed under the Apache License with the above modification is # distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY # KIND, either express or implied. See the Apache License for the specific # language governing permissions and limitations under the Apache License. # from qt import QtCore, QtGui, QtWidgets import os from pxr import Usd, Sdf from customAttributes import CustomAttribute # Color constants. # We use color in the prim browser to discriminate important scenegraph-state # (active, isInstance, isInMaster, has arcs) HasArcsColor = QtGui.QBrush(QtGui.QColor(222, 158, 46)) NormalColor = QtGui.QBrush(QtGui.QColor(227, 227, 227)) InstanceColor = QtGui.QBrush(QtGui.QColor(135, 206, 250)) # lightskyblue MasterColor = QtGui.QBrush(QtGui.QColor(118, 136, 217)) HeaderColor = QtGui.QBrush(QtGui.QColor(201, 199, 195)) # We use color in the attribute browser to specify value source RedColor = QtGui.QBrush(QtGui.QColor(230, 132, 131)) FallbackTextColor = HasArcsColor TimeSampleTextColor = QtGui.QBrush(QtGui.QColor(177, 207, 153)) DefaultTextColor = InstanceColor NoValueTextColor = QtGui.QBrush(QtGui.QColor(140, 140, 140)) ValueClipsTextColor = QtGui.QBrush(QtGui.QColor(230, 150, 230)) # Font constants. We use font in the prim browser to distinguish # "resolved" prim specifier
class UIPropertyValueSourceColors(ConstantGroup): FALLBACK = UIBaseColors.DARK_YELLOW TIME_SAMPLE = QtGui.QBrush(QtGui.QColor(177, 207, 153)) DEFAULT = UIBaseColors.LIGHT_SKY_BLUE NONE = QtGui.QBrush(QtGui.QColor(140, 140, 140)) VALUE_CLIPS = QtGui.QBrush(QtGui.QColor(230, 150, 230))
class UIPrimTypeColors(ConstantGroup): HAS_ARCS = UIBaseColors.DARK_YELLOW NORMAL = QtGui.QBrush(QtGui.QColor(227, 227, 227)) INSTANCE = UIBaseColors.LIGHT_SKY_BLUE MASTER = QtGui.QBrush(QtGui.QColor(118, 136, 217))
class UIBaseColors(ConstantGroup): RED = QtGui.QBrush(QtGui.QColor(230, 132, 131)) LIGHT_SKY_BLUE = QtGui.QBrush(QtGui.QColor(135, 206, 250)) DARK_YELLOW = QtGui.QBrush(QtGui.QColor(222, 158, 46))
def unhighlight(self): self._currentBrush = QtGui.QBrush(self._defaultBrush) self.update()
def highlight(self): self._currentBrush = QtGui.QBrush(self.color.lighter())
def color(self, color): self._currentBrush = QtGui.QBrush(color) self.update()
def querybrush(self): brush = qg.QBrush(qg.QColor.fromRgbF(*self.brush_colors[self.mode]), self.brushstyle) return brush
def querybrush(self): return qg.QBrush(qc.Qt.NoBrush)
class TreeItem(QtGui.QStandardItem): backgroundColor = QtGui.QColor(70, 70, 80) backgroundColorSelected = QtGui.QColor(50, 180, 240) backgroundColorHover = QtGui.QColor(50, 180, 150) textColorSelected = QtGui.QColor(255, 255, 255) textColor = QtGui.QColor(255, 255, 255) backgroundBrush = QtGui.QBrush(backgroundColor) backgroundColorSelectedBrush = QtGui.QBrush(backgroundColorSelected) backgroundColorHoverBrush = QtGui.QBrush(backgroundColorHover) def __init__(self, item, parent=None): super(TreeItem, self).__init__(parent=parent) self.padding = 2.5 self.textHeight = 15 self.showText = True self._item = item self._pixmap = QtGui.QPixmap() self.iconSize = QtCore.QSize(256, 256) self.loaderThread = ThreadedIcon(item.iconPath) self.setEditable(False) def item(self): return self._item def applyFromImage(self, image): pixmap = QtGui.QPixmap() pixmap = pixmap.fromImage(image) self._pixmap = pixmap self.model().dataChanged.emit(self.index(), self.index()) def setIconPath(self, iconPath): self._item.iconPath = iconPath self._pixmap = QtGui.QPixmap(iconPath) def pixmap(self): if not self._pixmap.isNull(): return self._pixmap elif not os.path.exists(self._item.iconPath): return QtGui.QPixmap() return self._pixmap def toolTip(self): return self._item.description() def isEditable(self, *args, **kwargs): return False def iconAlignment(self): return QtCore.Qt.AlignHCenter | QtCore.Qt.AlignVCenter def sizeHint(self): return self.model().view.iconSize() def font(self, index): return QtGui.QFont("Courier") def textAlignment(self, index): return QtCore.Qt.AlignHCenter | QtCore.Qt.AlignVCenter def removeRow(self, item): if item.loaderThread.isRunning: item.loaderThread.wait() return super(TreeItem, self).removeRow(item) def removeRows(self, items): for item in items: if item.loaderThread.isRunning: item.loaderThread.wait() return super(TreeItem, self).removeRows(items) def paint(self, painter, option, index): painter.save() self._paintBackground(painter, option, index) if self.showText: self._paintText(painter, option, index) self._paintIcon(painter, option, index) painter.restore() def _paintText(self, painter, option, index): text = self._item.name isSelected = option.state & QtWidgets.QStyle.State_Selected color = self.textColorSelected if isSelected else self.textColor rect = option.rect width = rect.width() height = rect.height() padding = self.padding x, y = padding, padding rect.translate(x, y) rect.setWidth(width - padding) rect.setHeight(height - padding) font = self.font(index) align = QtCore.Qt.AlignCenter | QtCore.Qt.AlignBottom metrics = QtGui.QFontMetricsF(font) textWidth = metrics.width(text) # does the text fit? if not cut off the text if textWidth > rect.width() - padding: text = metrics.elidedText(text, QtCore.Qt.ElideRight, rect.width()) pen = QtGui.QPen(color) painter.setPen(pen) painter.setFont(font) painter.drawText(rect, align, text) def _paintBackground(self, painter, option, index): isSelected = option.state & QtWidgets.QStyle.State_Selected isMouseOver = option.state & QtWidgets.QStyle.State_MouseOver painter.setPen(QtGui.QPen(QtCore.Qt.NoPen)) if isSelected: brush = self.backgroundColorSelectedBrush elif isMouseOver: brush = self.backgroundColorHoverBrush else: brush = self.backgroundBrush painter.setBrush(brush) painter.drawRect(option.rect) def _paintIcon(self, painter, option, index): rect = self.iconRect(option) pixmap = self.pixmap() if pixmap.isNull(): return pixmap = pixmap.scaled( rect.width(), rect.height(), QtCore.Qt.KeepAspectRatio, QtCore.Qt.SmoothTransformation, ) pixmapRect = QtCore.QRect(rect) pixmapRect.setWidth(pixmap.width()) pixmapRect.setHeight(pixmap.height()) x = float(rect.width() - pixmap.width()) * 0.5 y = float(rect.height() - pixmap.height()) * 0.5 pixmapRect.translate(x, y) painter.drawPixmap(pixmapRect, pixmap) def iconRect(self, option): padding = self.padding rect = option.rect width = rect.width() - padding height = rect.height() - padding # deal with the text if self.showText: height -= self.textHeight rect.setWidth(width) rect.setHeight(height) x = padding + (float(width - rect.width()) * 0.5) y = padding + (float(height - rect.height()) * 0.5) rect.translate(x, y) return rect
class UIPrimTreeColors(ConstantGroup): SELECTED = QtGui.QBrush(QtGui.QColor(189, 155, 84)) SELECTED_HOVER = QtGui.QBrush(QtGui.QColor(227, 186, 101)) ANCESTOR_OF_SELECTED = QtGui.QBrush(QtGui.QColor(189, 155, 84, 50)) ANCESTOR_OF_SELECTED_HOVER = QtGui.QBrush(QtGui.QColor(189, 155, 84, 100)) UNSELECTED_HOVER = QtGui.QBrush(QtGui.QColor(70, 70, 70))
def __init__(self, *args, **kwargs): super(StaticLine, self).__init__(*args, **kwargs) self.setBrush(qg.QBrush(qc.Qt.NoBrush))
def _stroke(self, painter, x, y, width, height): rect = QtCore.QRect(x, y, width, height) painter.setPen(self._defaultPen) painter.setBrush(QtGui.QBrush(QtGui.QColor(0.0, 0.0, 0.0, 0.0))) painter.drawRect(rect)
class Proto(Common): z_value = 20 isDeletable = True minradius = 20 basicpen = qg.QPen(qg.QColor.fromRgbF(0,0,0,1),1.0,qc.Qt.SolidLine,qc.Qt.RoundCap,qc.Qt.RoundJoin) basicpen.setCosmetic(True) basicbrush = qg.QBrush(qg.QColor.fromRgbF(1, 1, 0, .25), qc.Qt.SolidPattern) nobrush = qg.QBrush(qc.Qt.NoBrush) def __init__(self, *args, **kwargs): super(Proto, self).__init__(*args, **kwargs) self.setZValue(self.z_value) self.generic = self.shape_class([], [], False) self.temphandle = None self.setAcceptHoverEvents(True) self.setFlag(self.ItemIsMovable, True) self.setFlag(self.ItemIsSelectable, True) self.setFlag(self.ItemIsFocusable, True) self.setPen(self.basicpen) self.setBrush(self.basicbrush) def painterpath(self): ep = self.exteriorpoints(popupcad.view_scaling) ip = self.generic.interiorpoints(scaling=popupcad.view_scaling) return self.generic.gen_painterpath(ep, ip) def exteriorpoints(self,scaling=1): ep = self.generic.exteriorpoints(scaling=scaling) if self.temphandle is not None: ep.append( self.temphandle.generic.getpos(scaling=scaling)) return ep def deltemphandle(self): if not not self.temphandle: self.temphandle.setParentItem(None) del self.temphandle self.temphandle = None def checkdist(self, point0, point1): return not popupcad.algorithms.points.twopointsthesame( point0, point1, self.minradius / self.scene().views()[0].zoom()) def finish_definition(self): scene = self.scene() self.deltemphandle() scene.addItem(self.generic.outputinteractive()) self.harddelete() scene.childfinished() def mousedoubleclick(self, point): if self.generic.is_valid_bool(): self.finish_definition() self.updateshape() def mouserelease(self, point): pass def mousemove(self, point): import numpy point = tuple(numpy.array(qh.to_tuple(point)) / popupcad.view_scaling) if not not self.temphandle: self.temphandle.generic.setpos(point) self.temphandle.updateshape() self.updateshape()
def renderprocess(self, basename, scaling, exportdir): tempmodes = [] for item in self.items(): try: tempmodes.append(item.mode) except AttributeError: tempmodes.append(None) selected = self.selectedItems() tempbrush = self.backgroundBrush() # prerender self.setBackgroundBrush(qg.QBrush()) for item in self.items(): try: item.updatemode(item.modes.mode_render) except AttributeError: pass pen = item.pen() pen.setWidth(pen.width() / scaling) item.setPen(pen) item.setSelected(False) filename = os.path.normpath(os.path.join(exportdir, basename)) self.setSceneRect(self.itemsBoundingRect()) generator = qs.QSvgGenerator() generator.setFileName(filename) generator.setSize(qc.QSize(self.width(), self.height())) generator.setResolution(90.0 / scaling) generator.setTitle('SVG Generator Example Drawing') generator.setDescription('An SVG drawing created by the SVG Generator') painter = qg.QPainter() painter.begin(generator) painter.setWorldMatrixEnabled(True) t = qg.QTransform() if popupcad.flip_y: t.scale(1, -1) s = scaling t.scale(s, s) t.translate(0, -self.height()) # if center: # v1 = numpy.array([-self.width() / 2, -self.height() / 2]) # theta = -rotation * pi / 180 # R = numpy.array( # [[cos(theta), sin(theta)], [-sin(theta), cos(theta)]]) # v2 = R.dot(v1) # t.translate(*v2) # t.rotate(rotation) painter.setWorldTransform(t) self.render(painter) painter.end() for item in selected: item.setSelected(True) for item, mode in zip(self.items(), tempmodes): pen = item.pen() pen.setWidth(pen.width() * scaling) item.setPen(pen) try: item.updatemode(mode) except AttributeError: pass self.setBackgroundBrush(tempbrush) self.update()