def __init__(self, txt='', font_size=12, set_bold=False, color=QtGui.QColor(255, 255, 255), pm_node=False): super(StandardItem, self).__init__() fnt = QtGui.QFont("Open Sans", font_size) fnt.setBold(set_bold) self.setEditable(False) self.setForeground(color) self.setFont(fnt) self.setText(txt) self.pm_node = pm_node
def populate_animSet(self, fileName): animSetTemplate = re_motion.read_mot_list(fileName) self.loadedAnimSet = animSetTemplate #load animSet object #animSet object is just animation set #read all the animations??? #populate the tree with that object #animsTreeView treeModel = QtGui.QStandardItemModel() rootNode = treeModel.invisibleRootItem() animSet = tree.StandardItem(animSetTemplate.filepath, 10, set_bold=True) animSet.setEditable(False) animSet.setSelectable(False) animSet.setCheckable(False) for animation in animSetTemplate.header.POINTERS: name = animation.motName animSet2 = tree.StandardItem(name, 10, pm_node=animation) animSet.appendRow(animSet2) rootNode.appendRow(animSet) self.animsTreeView.setHeaderHidden(True) self.animsTreeView.setModel(treeModel) self.animsTreeView.expandAll() #self.animsTreeView.doubleClicked.connect(self.getValue) self.animsTreeView.clicked.connect(self.getValue)
def initialize(self): # add validators self.data['lineedit']['x'].setValidator(QtGui.QDoubleValidator(0, 180, 2)) self.data['lineedit']['y'].setValidator(QtGui.QDoubleValidator(0, 180, 2)) self.data['lineedit']['z'].setValidator(QtGui.QDoubleValidator(0, 180, 2)) self.data['lineedit']['insertJoints'].setValidator(QtGui.QIntValidator(1, 100)) # set button id in buttongroups self.data['rbg']['aimAxis'].setId(self.data['radio']['aimAxisX'], 1) self.data['rbg']['aimAxis'].setId(self.data['radio']['aimAxisY'], 2) self.data['rbg']['aimAxis'].setId(self.data['radio']['aimAxisZ'], 3) self.data['rbg']['upAxis'].setId(self.data['radio']['upAxisX'], 4) self.data['rbg']['upAxis'].setId(self.data['radio']['upAxisY'], 5) self.data['rbg']['upAxis'].setId(self.data['radio']['upAxisZ'], 6) self.data['rbg']['worldUpAxis'].setId(self.data['radio']['worldUpAxisX'], 1) self.data['rbg']['worldUpAxis'].setId(self.data['radio']['worldUpAxisY'], 2) self.data['rbg']['worldUpAxis'].setId(self.data['radio']['worldUpAxisZ'], 3)
def __drawTriangle(self, painter, x, y): brush = QtGui.QBrush(QtGui.QColor(255, 255, 255, 160), QtCore.Qt.SolidPattern) if not self.isCollapsed(): tl, tr, tp = (QtCore.QPoint(x + 9, y + 8), QtCore.QPoint(x + 19, y + 8), QtCore.QPoint(x + 14, y + 13.0)) points = [tl, tr, tp] triangle = QtGui.QPolygon(points) else: tl, tr, tp = QtCore.QPoint(x + 11, y + 6), QtCore.QPoint( x + 16, y + 11), QtCore.QPoint(x + 11, y + 16.0) points = [tl, tr, tp] triangle = QtGui.QPolygon(points) currentBrush = painter.brush() painter.setBrush(brush) painter.drawPolygon(triangle) painter.setBrush(currentBrush)
def addFonts(fontDir): """Add fonts to QApplication. Args: fontDir: Absolute path to fonts folder. Returns: bool: True if successful, False if not. """ validTypes = ['ttf', 'otf'] fonts = QtGui.QFontDatabase() for font in os.listdir(fontDir): fontPath = os.path.join(fontDir, font) if os.path.isfile(fontPath): if font.split('.')[1] in validTypes: fonts.addApplicationFont(fontPath) return True return False
def initialize(self): # add validators self.data['lineedit']['x'].setValidator( QtGui.QDoubleValidator(0, 180, 2)) self.data['lineedit']['y'].setValidator( QtGui.QDoubleValidator(0, 180, 2)) self.data['lineedit']['z'].setValidator( QtGui.QDoubleValidator(0, 180, 2)) self.data['lineedit']['minScale'].setValidator( QtGui.QDoubleValidator(1.0, 100, 2)) self.data['lineedit']['maxScale'].setValidator( QtGui.QDoubleValidator(1.0, 100, 2)) # add buttons - add control curve dirs = os.listdir(ctrls.CONTROLS_DIRECTORY) col = 6 row = 0 count = 0 self.mapperAddCurve = QtCore.QSignalMapper() for fileName in dirs: if fileName.endswith('.json'): if count == 6: count = 0 row += 1 btn = QtWidgets.QPushButton() btn.setToolTip(fileName) iconName = fileName.replace('.json', '.png') if iconName in dirs: iconPath = os.path.join(ctrls.CONTROLS_DIRECTORY, iconName) btn.setIcon(QtGui.QIcon(iconPath)) btn.setIconSize(QtCore.QSize(30, 30)) self.data['layouts']['addCurve'].addWidget(btn, row, count) count += 1 self.mapperAddCurve.setMapping(btn, fileName) btn.clicked.connect(self.mapperAddCurve.map) self.mapperAddCurve.mapped['QString'].connect(self.addCtrlShape) # add buttons - color self.mapperColor = QtCore.QSignalMapper() col = 8 row = 0 count = 4 for i in xrange(1, 32): if count == col: count = 0 row += 1 rgb = cmds.colorIndex(i, q=True) r, g, b = rgb[0], rgb[1], rgb[2] btn = QtWidgets.QPushButton() btn.btnIndex = count btn.setAutoFillBackground(True) values = "{r}, {g}, {b}, {a}".format(r=r * 255, g=g * 255, b=b * 255, a=255) btn.setStyleSheet("QPushButton { background-color: rgba(" + values + "); }") self.data['layouts']['color'].addWidget(btn, row, count) count += 1 self.mapperColor.setMapping(btn, i) btn.clicked.connect(self.mapperColor.map) self.mapperColor.mapped['int'].connect(self.colorShapes)
def paintEvent(self, event): painter = QtGui.QPainter() painter.begin(self) painter.setRenderHint(painter.Antialiasing) font = painter.font() font.setBold(True) painter.setFont(font) x = self.rect().x() y = self.rect().y() w = self.rect().width() - 1 h = self.rect().height() - 1 r = 8 # draw a rounded style if self._rolloutStyle == 2: # draw the text painter.drawText(x + 33, y + 3, w, 16, QtCore.Qt.AlignLeft | QtCore.Qt.AlignTop, self.title()) # draw the triangle self.__drawTriangle(painter, x, y) # draw the borders pen = QtGui.QPen(self.palette().color(QtGui.QPalette.Light)) pen.setWidthF(0.6) painter.setPen(pen) painter.drawRoundedRect(x + 1, y + 1, w - 1, h - 1, r, r) pen.setColor(self.palette().color(QtGui.QPalette.Shadow)) painter.setPen(pen) painter.drawRoundedRect(x, y, w - 1, h - 1, r, r) # draw a square style if self._rolloutStyle == 3: # draw the text painter.drawText(x + 33, y + 3, w, 16, QtCore.Qt.AlignLeft | QtCore.Qt.AlignTop, self.title()) self.__drawTriangle(painter, x, y) # draw the borders pen = QtGui.QPen(self.palette().color(QtGui.QPalette.Light)) pen.setWidthF(0.6) painter.setPen(pen) painter.drawRect(x + 1, y + 1, w - 1, h - 1) pen.setColor(self.palette().color(QtGui.QPalette.Shadow)) painter.setPen(pen) painter.drawRect(x, y, w - 1, h - 1) # draw a Maya style if self._rolloutStyle == 4: # draw the text painter.drawText(x + 33, y + 3, w, 16, QtCore.Qt.AlignLeft | QtCore.Qt.AlignTop, self.title()) painter.setRenderHint(QtGui.QPainter.Antialiasing, False) self.__drawTriangle(painter, x, y) # draw the borders - top headerHeight = 20 headerRect = QtCore.QRect(x + 1, y + 1, w - 1, headerHeight) headerRectShadow = QtCore.QRect(x - 1, y - 1, w + 1, headerHeight + 2) # Highlight pen = QtGui.QPen(self.palette().color(QtGui.QPalette.Light)) pen.setWidthF(0.4) painter.setPen(pen) painter.drawRect(headerRect) painter.fillRect(headerRect, QtGui.QColor(255, 255, 255, 18)) # Shadow pen.setColor(self.palette().color(QtGui.QPalette.Dark)) painter.setPen(pen) painter.drawRect(headerRectShadow) if not self.isCollapsed(): # draw the lover border pen = QtGui.QPen(self.palette().color(QtGui.QPalette.Dark)) pen.setWidthF(0.8) painter.setPen(pen) offSet = headerHeight + 3 bodyRect = QtCore.QRect(x, y + offSet, w, h - offSet) bodyRectShadow = QtCore.QRect(x + 1, y + offSet, w + 1, h - offSet + 1) painter.drawRect(bodyRect) pen.setColor(self.palette().color(QtGui.QPalette.Light)) pen.setWidthF(0.4) painter.setPen(pen) painter.drawRect(bodyRectShadow) # draw a boxed style elif self._rolloutStyle == 1: if self.isCollapsed(): arect = QtCore.QRect(x + 1, y + 9, w - 1, 4) brect = QtCore.QRect(x, y + 8, w - 1, 4) text = '+' else: arect = QtCore.QRect(x + 1, y + 9, w - 1, h - 9) brect = QtCore.QRect(x, y + 8, w - 1, h - 9) text = '-' # draw the borders pen = QtGui.QPen(self.palette().color(QtGui.QPalette.Light)) pen.setWidthF(0.6) painter.setPen(pen) painter.drawRect(arect) pen.setColor(self.palette().color(QtGui.QPalette.Shadow)) painter.setPen(pen) painter.drawRect(brect) painter.setRenderHint(painter.Antialiasing, False) painter.setBrush(self.palette().color( QtGui.QPalette.Window).darker(120)) painter.drawRect(x + 10, y + 1, w - 20, 16) painter.drawText(x + 16, y + 1, w - 32, 16, QtCore.Qt.AlignLeft | QtCore.Qt.AlignVCenter, text) painter.drawText(x + 10, y + 1, w - 20, 16, QtCore.Qt.AlignCenter, self.title()) if self.dragDropMode(): rect = self.dragDropRect() # draw the lines l = rect.left() r = rect.right() cy = rect.center().y() for y in (cy - 3, cy, cy + 3): painter.drawLine(l, y, r, y) painter.end()