def layoutRadialScene(self): """ A convenience method for drawing the sensitivity scene in radial fashion """ self.scene.clear() width = self.scene.width() height = self.scene.height() minDim = min([width, height ]) - 24. # 12 point font * 2 for top and bottom, ## width is a bit harder... centerX = width / 2. centerY = height / 2. radius = minDim / 2. axisPen = qtg.QPen(qtc.Qt.black) self.scene.addEllipse(centerX - radius, centerY - radius, minDim, \ minDim, axisPen) names = self.amsc.GetNames()[:-1] for i, name in enumerate(names): if len(names) <= 2: theta = 3 * math.pi * float(i) / 2. else: theta = 2 * math.pi * float(i) / float(len(names)) endX = radius * math.cos(theta) + centerX endY = radius * math.sin(theta) + centerY self.scene.addLine(centerX, centerY, endX, endY, axisPen) if self.showLabelsAction.isChecked(): txtItem = self.scene.addSimpleText(name, self.font) txtItem.setPos(endX, endY) txtItem.setFlag(qtw.QGraphicsItem.ItemIsMovable) txtItem.setFlag(qtw.QGraphicsItem.ItemIsSelectable) txtItem.setFlag(qtw.QGraphicsItem.ItemIgnoresTransformations) selection = self.amsc.GetSelectedSegments() colorMap = self.amsc.GetColors() if self.valueGroup.checkedAction().text() == 'Linear coefficients': fits = self.amsc.SegmentFitCoefficients() elif self.valueGroup.checkedAction().text() == 'Pearson correlation': fits = self.amsc.SegmentPearsonCoefficients() elif self.valueGroup.checkedAction().text( ) == 'Spearman rank correlation': fits = self.amsc.SegmentSpearmanCoefficients() ## Check if they selected any extrema if selection is None or len(selection) == 0: selection = [] selectedExts = self.amsc.GetSelectedExtrema() allSegments = self.amsc.GetCurrentLabels() for minMaxPair in allSegments: for extIdx in selectedExts: if extIdx in minMaxPair: selection.append(minMaxPair) ## Okay, well then we will just plot everything we have for the current ## level if len(selection) == 0: selection = allSegments if self.valueGroup.checkedAction().text() == 'Linear coefficients': maxValue = 0 for extPair in selection: if maxValue < max(map(abs, fits[extPair])): maxValue = max(map(abs, fits[extPair])) else: maxValue = 1 for extPair in selection: myColor = colorMap[extPair] myPen = qtg.QPen(qtg.QColor('#000000')) brushColor = qtg.QColor(myColor) brushColor.setAlpha(127) myBrush = qtg.QBrush(brushColor) myPoly = qtg.QPolygonF() for i, val in enumerate(map(abs, fits[extPair])): if len(names) <= 2: theta = 3 * math.pi * float(i) / 2. else: theta = 2 * math.pi * float(i) / float(len(names)) dimX = (val / maxValue) * radius * math.cos(theta) + centerX dimY = (val / maxValue) * radius * math.sin(theta) + centerY myPoly.append(qtc.QPointF(dimX, dimY)) if len(names) <= 2: myPoly.append(qtc.QPointF(centerX, centerY)) self.scene.addPolygon(myPoly, myPen, myBrush)
def getPenWhileMoving(self): ret = QtGui.QPen(QtGui.QColor(255, 0, 255, 255)) return ret
self.ViewResult = XML self.Name = 'dummyViewObject' self.X = 0 self.Y = 0 viewObject = dummyViewObject(XML) def onClickFun(event, referer, elementXML, elementParms, elementViewObject): print(elementXML) print(elementParms) referer.adjustScale(2) maskBrush = QtGui.QBrush(QtGui.QColor(0, 255, 0, 100)) maskPen = QtGui.QPen(QtGui.QColor(0, 255, 0, 100)) maskPen.setWidth(4) maskHoverPen = QtGui.QPen(QtGui.QColor(0, 255, 0, 255)) maskHoverPen.setWidthF(5) generateSelectionGraphicsItems([viewObject], onClickFun, sceneToAddTo=graphicsScene, doPoints=True, doCircles=True, doTextItems=True, doLines=True, doFittedCircles=True, doEllipses=True, maskPen=maskPen, maskBrush=maskBrush,
def setupUi(self, MainWindow): MainWindow.setObjectName("MainWindow") MainWindow.resize(692, 605) sizePolicy = QtGui.QSizePolicy(QtGui.QSizePolicy.Fixed, QtGui.QSizePolicy.Fixed) sizePolicy.setHorizontalStretch(0) sizePolicy.setVerticalStretch(0) sizePolicy.setHeightForWidth( MainWindow.sizePolicy().hasHeightForWidth()) MainWindow.setSizePolicy(sizePolicy) self.centralwidget = QtGui.QWidget(MainWindow) self.centralwidget.setObjectName("centralwidget") self.label = QtGui.QLabel(self.centralwidget) self.label.setGeometry(QtCore.QRect(30, 30, 101, 16)) self.label.setObjectName("label") self.label_2 = QtGui.QLabel(self.centralwidget) self.label_2.setGeometry(QtCore.QRect(250, 30, 101, 16)) self.label_2.setObjectName("label_2") self.lineEdit_frameStart = QtGui.QLineEdit(self.centralwidget) self.lineEdit_frameStart.setGeometry(QtCore.QRect(100, 30, 110, 20)) self.lineEdit_frameStart.setObjectName("lineEdit_frameStart") self.lineEdit_frameEnd = QtGui.QLineEdit(self.centralwidget) self.lineEdit_frameEnd.setGeometry(QtCore.QRect(320, 30, 110, 20)) self.lineEdit_frameEnd.setObjectName("lineEdit_frameEnd") self.lineEdit_Project = QtGui.QLineEdit(self.centralwidget) self.lineEdit_Project.setGeometry(QtCore.QRect(140, 150, 531, 20)) self.lineEdit_Project.setObjectName("lineEdit_Project") self.lineEdit_filePath = QtGui.QLineEdit(self.centralwidget) self.lineEdit_filePath.setGeometry(QtCore.QRect(140, 180, 531, 20)) self.lineEdit_filePath.setObjectName("lineEdit_filePath") self.pushButton_createBatchCmd = QtGui.QPushButton(self.centralwidget) self.pushButton_createBatchCmd.setGeometry( QtCore.QRect(30, 270, 181, 31)) palette = QtGui.QPalette() brush = QtGui.QBrush(QtGui.QColor(90, 112, 103)) brush.setStyle(QtCore.Qt.SolidPattern) palette.setBrush(QtGui.QPalette.Active, QtGui.QPalette.Button, brush) brush = QtGui.QBrush(QtGui.QColor(90, 112, 103)) brush.setStyle(QtCore.Qt.SolidPattern) palette.setBrush(QtGui.QPalette.Inactive, QtGui.QPalette.Button, brush) brush = QtGui.QBrush(QtGui.QColor(90, 112, 103)) brush.setStyle(QtCore.Qt.SolidPattern) palette.setBrush(QtGui.QPalette.Disabled, QtGui.QPalette.Button, brush) self.pushButton_createBatchCmd.setPalette(palette) font = QtGui.QFont() font.setFamily("Calibri") font.setPointSize(11) font.setWeight(75) font.setBold(True) self.pushButton_createBatchCmd.setFont(font) self.pushButton_createBatchCmd.setObjectName( "pushButton_createBatchCmd") self.pushButton_setProject = QtGui.QPushButton(self.centralwidget) self.pushButton_setProject.setGeometry(QtCore.QRect(30, 150, 91, 23)) palette = QtGui.QPalette() brush = QtGui.QBrush(QtGui.QColor(0, 71, 104)) brush.setStyle(QtCore.Qt.SolidPattern) palette.setBrush(QtGui.QPalette.Active, QtGui.QPalette.Button, brush) brush = QtGui.QBrush(QtGui.QColor(0, 71, 104)) brush.setStyle(QtCore.Qt.SolidPattern) palette.setBrush(QtGui.QPalette.Inactive, QtGui.QPalette.Button, brush) brush = QtGui.QBrush(QtGui.QColor(0, 71, 104)) brush.setStyle(QtCore.Qt.SolidPattern) palette.setBrush(QtGui.QPalette.Disabled, QtGui.QPalette.Button, brush) self.pushButton_setProject.setPalette(palette) self.pushButton_setProject.setObjectName("pushButton_setProject") self.pushButton_setFilePath = QtGui.QPushButton(self.centralwidget) self.pushButton_setFilePath.setGeometry(QtCore.QRect(30, 180, 91, 23)) palette = QtGui.QPalette() brush = QtGui.QBrush(QtGui.QColor(0, 71, 104)) brush.setStyle(QtCore.Qt.SolidPattern) palette.setBrush(QtGui.QPalette.Active, QtGui.QPalette.Button, brush) brush = QtGui.QBrush(QtGui.QColor(0, 71, 104)) brush.setStyle(QtCore.Qt.SolidPattern) palette.setBrush(QtGui.QPalette.Inactive, QtGui.QPalette.Button, brush) brush = QtGui.QBrush(QtGui.QColor(0, 71, 104)) brush.setStyle(QtCore.Qt.SolidPattern) palette.setBrush(QtGui.QPalette.Disabled, QtGui.QPalette.Button, brush) self.pushButton_setFilePath.setPalette(palette) self.pushButton_setFilePath.setObjectName("pushButton_setFilePath") self.lineEdit_filePath_renderCmd = QtGui.QLineEdit(self.centralwidget) self.lineEdit_filePath_renderCmd.setGeometry( QtCore.QRect(230, 270, 441, 31)) font = QtGui.QFont() font.setFamily("Calibri") font.setPointSize(11) self.lineEdit_filePath_renderCmd.setFont(font) self.lineEdit_filePath_renderCmd.setObjectName( "lineEdit_filePath_renderCmd") self.label_3 = QtGui.QLabel(self.centralwidget) self.label_3.setGeometry(QtCore.QRect(40, 210, 81, 16)) self.label_3.setObjectName("label_3") self.lineEdit_prmanReleated = QtGui.QLineEdit(self.centralwidget) self.lineEdit_prmanReleated.setGeometry(QtCore.QRect( 140, 210, 531, 20)) self.lineEdit_prmanReleated.setObjectName("lineEdit_prmanReleated") self.lineEdit_resX = QtGui.QLineEdit(self.centralwidget) self.lineEdit_resX.setEnabled(False) self.lineEdit_resX.setGeometry(QtCore.QRect(130, 70, 61, 20)) self.lineEdit_resX.setObjectName("lineEdit_resX") self.lineEdit_resY = QtGui.QLineEdit(self.centralwidget) self.lineEdit_resY.setEnabled(False) self.lineEdit_resY.setGeometry(QtCore.QRect(196, 70, 61, 20)) self.lineEdit_resY.setObjectName("lineEdit_resY") self.lineEdit_modifyMaxSample = QtGui.QLineEdit(self.centralwidget) self.lineEdit_modifyMaxSample.setEnabled(False) self.lineEdit_modifyMaxSample.setGeometry(QtCore.QRect( 400, 70, 61, 20)) self.lineEdit_modifyMaxSample.setObjectName("lineEdit_modifyMaxSample") self.checkBox_exportLog = QtGui.QCheckBox(self.centralwidget) self.checkBox_exportLog.setGeometry(QtCore.QRect(30, 102, 281, 16)) self.checkBox_exportLog.setChecked(True) self.checkBox_exportLog.setObjectName("checkBox_exportLog") self.checkBox_modifyRESXY = QtGui.QCheckBox(self.centralwidget) self.checkBox_modifyRESXY.setGeometry(QtCore.QRect(30, 70, 91, 16)) self.checkBox_modifyRESXY.setObjectName("checkBox_modifyRESXY") self.checkBox_modifyMaxSample = QtGui.QCheckBox(self.centralwidget) self.checkBox_modifyMaxSample.setGeometry( QtCore.QRect(280, 70, 121, 16)) self.checkBox_modifyMaxSample.setObjectName("checkBox_modifyMaxSample") self.line = QtGui.QFrame(self.centralwidget) self.line.setGeometry(QtCore.QRect(20, 120, 681, 16)) self.line.setFrameShape(QtGui.QFrame.HLine) self.line.setFrameShadow(QtGui.QFrame.Sunken) self.line.setObjectName("line") self.line_2 = QtGui.QFrame(self.centralwidget) self.line_2.setGeometry(QtCore.QRect(10, 380, 681, 16)) self.line_2.setFrameShape(QtGui.QFrame.HLine) self.line_2.setFrameShadow(QtGui.QFrame.Sunken) self.line_2.setObjectName("line_2") self.lineEdit_MayaFile = QtGui.QLineEdit(self.centralwidget) self.lineEdit_MayaFile.setGeometry(QtCore.QRect(190, 458, 471, 31)) self.lineEdit_MayaFile.setObjectName("lineEdit_MayaFile") self.pushButton_setMayaFile = QtGui.QPushButton(self.centralwidget) self.pushButton_setMayaFile.setGeometry(QtCore.QRect(20, 458, 151, 31)) palette = QtGui.QPalette() brush = QtGui.QBrush(QtGui.QColor(0, 71, 104)) brush.setStyle(QtCore.Qt.SolidPattern) palette.setBrush(QtGui.QPalette.Active, QtGui.QPalette.Button, brush) brush = QtGui.QBrush(QtGui.QColor(0, 71, 104)) brush.setStyle(QtCore.Qt.SolidPattern) palette.setBrush(QtGui.QPalette.Inactive, QtGui.QPalette.Button, brush) brush = QtGui.QBrush(QtGui.QColor(0, 71, 104)) brush.setStyle(QtCore.Qt.SolidPattern) palette.setBrush(QtGui.QPalette.Disabled, QtGui.QPalette.Button, brush) self.pushButton_setMayaFile.setPalette(palette) font = QtGui.QFont() font.setFamily("Calibri") font.setPointSize(11) font.setWeight(75) font.setBold(True) self.pushButton_setMayaFile.setFont(font) self.pushButton_setMayaFile.setObjectName("pushButton_setMayaFile") self.checkBox_frameStep = QtGui.QCheckBox(self.centralwidget) self.checkBox_frameStep.setGeometry(QtCore.QRect(500, 30, 51, 16)) self.checkBox_frameStep.setObjectName("checkBox_frameStep") self.lineEdit_frameStep = QtGui.QLineEdit(self.centralwidget) self.lineEdit_frameStep.setEnabled(False) self.lineEdit_frameStep.setGeometry(QtCore.QRect(560, 30, 61, 20)) self.lineEdit_frameStep.setObjectName("lineEdit_frameStep") self.pushButton_genRenderJob = QtGui.QPushButton(self.centralwidget) self.pushButton_genRenderJob.setGeometry(QtCore.QRect( 20, 520, 151, 31)) palette = QtGui.QPalette() brush = QtGui.QBrush(QtGui.QColor(193, 125, 113)) brush.setStyle(QtCore.Qt.SolidPattern) palette.setBrush(QtGui.QPalette.Active, QtGui.QPalette.Button, brush) brush = QtGui.QBrush(QtGui.QColor(193, 125, 113)) brush.setStyle(QtCore.Qt.SolidPattern) palette.setBrush(QtGui.QPalette.Inactive, QtGui.QPalette.Button, brush) brush = QtGui.QBrush(QtGui.QColor(193, 125, 113)) brush.setStyle(QtCore.Qt.SolidPattern) palette.setBrush(QtGui.QPalette.Disabled, QtGui.QPalette.Button, brush) self.pushButton_genRenderJob.setPalette(palette) font = QtGui.QFont() font.setFamily("Calibri") font.setPointSize(11) font.setWeight(75) font.setBold(True) self.pushButton_genRenderJob.setFont(font) self.pushButton_genRenderJob.setObjectName("pushButton_genRenderJob") self.label_4 = QtGui.QLabel(self.centralwidget) self.label_4.setGeometry(QtCore.QRect(30, 400, 91, 16)) self.label_4.setObjectName("label_4") self.lineEdit_fileNamePrefix = QtGui.QLineEdit(self.centralwidget) self.lineEdit_fileNamePrefix.setGeometry( QtCore.QRect(130, 400, 531, 20)) self.lineEdit_fileNamePrefix.setObjectName("lineEdit_fileNamePrefix") self.checkBox_divide = QtGui.QCheckBox(self.centralwidget) self.checkBox_divide.setGeometry(QtCore.QRect(500, 70, 71, 16)) self.checkBox_divide.setObjectName("checkBox_divide") self.lineEdit_divide = QtGui.QLineEdit(self.centralwidget) self.lineEdit_divide.setEnabled(False) self.lineEdit_divide.setGeometry(QtCore.QRect(560, 70, 61, 20)) self.lineEdit_divide.setObjectName("lineEdit_divide") self.radioButton_single = QtGui.QRadioButton(self.centralwidget) self.radioButton_single.setGeometry(QtCore.QRect(40, 240, 81, 16)) self.radioButton_single.setChecked(True) self.radioButton_single.setObjectName("radioButton_single") self.radioButton_multifiles = QtGui.QRadioButton(self.centralwidget) self.radioButton_multifiles.setGeometry(QtCore.QRect(130, 240, 91, 16)) self.radioButton_multifiles.setObjectName("radioButton_multifiles") self.pushButton_submitDeadLine = QtGui.QPushButton(self.centralwidget) self.pushButton_submitDeadLine.setGeometry( QtCore.QRect(30, 310, 181, 31)) palette = QtGui.QPalette() brush = QtGui.QBrush(QtGui.QColor(90, 112, 103)) brush.setStyle(QtCore.Qt.SolidPattern) palette.setBrush(QtGui.QPalette.Active, QtGui.QPalette.Button, brush) brush = QtGui.QBrush(QtGui.QColor(90, 112, 103)) brush.setStyle(QtCore.Qt.SolidPattern) palette.setBrush(QtGui.QPalette.Inactive, QtGui.QPalette.Button, brush) brush = QtGui.QBrush(QtGui.QColor(90, 112, 103)) brush.setStyle(QtCore.Qt.SolidPattern) palette.setBrush(QtGui.QPalette.Disabled, QtGui.QPalette.Button, brush) self.pushButton_submitDeadLine.setPalette(palette) font = QtGui.QFont() font.setFamily("Calibri") font.setPointSize(11) font.setWeight(75) font.setBold(True) self.pushButton_submitDeadLine.setFont(font) self.pushButton_submitDeadLine.setObjectName( "pushButton_submitDeadLine") MainWindow.setCentralWidget(self.centralwidget) self.menubar = QtGui.QMenuBar(MainWindow) self.menubar.setGeometry(QtCore.QRect(0, 0, 692, 21)) self.menubar.setObjectName("menubar") MainWindow.setMenuBar(self.menubar) self.statusbar = QtGui.QStatusBar(MainWindow) self.statusbar.setObjectName("statusbar") MainWindow.setStatusBar(self.statusbar) self.retranslateUi(MainWindow) QtCore.QMetaObject.connectSlotsByName(MainWindow)
def getNormalPen(self): ret = QtGui.QPen() ret.setColor(QtGui.QColor(255, 255, 255, 150)) ret.setStyle(QtCore.Qt.DotLine) return ret
def getColorFromIcon(self, icon): "gets pixel color from the given icon" pixel = icon.pixmap(16, 16).toImage().pixel(0, 0) return str(QtGui.QColor(pixel).getRgbF())
def draw_profile(self, qp): ''' Draws the storm relative wind profile. Parameters ---------- qp: QtGui.QPainter object ''' ## initialize a pen with a red color, thickness of 2, solid line pen = QtGui.QPen(QtGui.QColor(RED), 2) pen.setStyle(QtCore.Qt.SolidLine) ## if there are missing values, get the mask try: mask = np.maximum(self.sru.mask, self.srv.mask) sru = self.sru[~mask] srv = self.srv[~mask] hgt = self.prof.hght[~mask] ## otherwise the data is fine except: sru = self.sru srv = self.srv hgt = self.prof.hgtht ## loop through the vertical profile. ## we go through length - 1 because we index i and i+1 for i in range( hgt.shape[0] - 1 ): ## get the height and winds at two consecutive heights ## don't forget to convert the height from meters to ## kilometers; divide by 1000 hgt1 = (hgt[i] - self.prof.hght[self.prof.sfc]) / 1000; hgt2 = (hgt[i+1] - self.prof.hght[self.prof.sfc]) / 1000 sru1 = sru[i]; sru2 = sru[i+1] srv1 = srv[i]; srv2 = srv[i+1] ## calculate the storm relative wind speed spd1 = np.sqrt( sru1**2 + srv1**2 ) spd2 = np.sqrt( sru2**2 + srv2**2 ) ## convert the wind speeds to x pixels x1 = self.speed_to_pix( spd1 ); x2 = self.speed_to_pix(spd2) ## convert the height values to y pixels y1 = self.hgt_to_pix(hgt1); y2 = self.hgt_to_pix(hgt2) ## draw a line between the two points qp.setPen(pen) qp.drawLine(x1, y1, x2, y2) # Plot the 0-2 km mean SRW pen = QtGui.QPen(QtGui.QColor("#8B0000"), 2) pen.setStyle(QtCore.Qt.SolidLine) qp.setPen(pen) x1 = self.speed_to_pix(self.srw_0_2km); x2 = self.speed_to_pix(self.srw_0_2km) y1 = self.hgt_to_pix(0.0); y2 = self.hgt_to_pix(2.0) qp.drawLine(x1, y1, x2, y2) # Plot the 4-6 km mean SRW pen = QtGui.QPen(QtGui.QColor("#6495ED"), 2) pen.setStyle(QtCore.Qt.SolidLine) qp.setPen(pen) x1 = self.speed_to_pix(self.srw_4_6km); x2 = self.speed_to_pix(self.srw_4_6km) y1 = self.hgt_to_pix(4.0); y2 = self.hgt_to_pix(6.0) qp.drawLine(x1, y1, x2, y2) # Plot the 9-11 km mean SRW pen = QtGui.QPen(QtGui.QColor("#9400D3"), 2) pen.setStyle(QtCore.Qt.SolidLine) qp.setPen(pen) x1 = self.speed_to_pix(self.srw_9_11km); x2 = self.speed_to_pix(self.srw_9_11km) y1 = self.hgt_to_pix(9.0); y2 = self.hgt_to_pix(11.0) qp.drawLine(x1, y1, x2, y2)
def render_statechart(scene, graphtree=None, keep_pos=False, dump_gfx=''): ''' Render a graphviz/dot statechart on the QGraphicsScene set a filename to "dump_gfx" parameter to create a PNG of the graph input is resulting from sdl_to_statechart, it contains a tree of graphs in case of composite states. ''' if graphtree == None: raise TypeError("Statechart.py: 'render_statechart'" " called with no graph tree") # dot uses a 72 dpi value for converting its position coordinates # Get actual rendering DPI from Qt view for view in scene.views(): RENDER_DPI['X'] = view.physicalDpiX() RENDER_DPI['Y'] = view.physicalDpiY() break # Go recursive first: render children count = 0 for aname, agraph in graphtree['children'].viewitems(): # Render each child in a temporary scene to get the size of the scene # in order to resize the parent node accordingly temp_scene = type(scene)() render_statechart(temp_scene, agraph, keep_pos, dump_gfx) w = temp_scene.width() for node in graphtree['graph'].iternodes(): if node == aname: size = temp_scene.itemsBoundingRect() node.attr['width'] = ((temp_scene.width() + 35) / RENDER_DPI['X']) node.attr['height'] = ((temp_scene.height() + 35) / RENDER_DPI['Y']) graphtree['children'][aname]['scene'] = temp_scene break # Harmonize the size of states to avoid having huge composite state(s) # next to single, small states. Rule: there can't be a state with a size # that is less than a third of the biggest state. try: min_width = float( max( node.attr.get('width', 0.0) or 0.0 for node in graphtree['graph'].iternodes())) min_height = float( max( node.attr.get('height', 0.0) or 0.0 for node in graphtree['graph'].iternodes())) except ValueError as err: LOG.debug(str(err)) min_width, min_height = 0, 0 if min_width and min_height: for node in graphtree['graph'].iternodes(): if node.attr['shape'] != 'record': continue node.attr['width'] = node.attr.get('width') or (min_width / 3.0) node.attr['height'] = node.attr.get('height') or (min_height / 3.0) # Statechart symbols lookup table lookup = { 'point': Point, 'record': Record, 'diamond': Diamond, 'square': Stop } try: # Bonus: the tool can render any dot graph... graph = graphtree.get('graph', None) or dotgraph.AGraph('taste.dot') config = " ".join("{name}={val}".format(name=name, val=val) for name, val in graphtree['config'].viewitems()) except IOError: LOG.info('No statechart to display....') raise graph.graph_attr.update(dpi='72.0') EDGES[:] = graph.edges() for each in scene.visible_symb: each.setVisible(False) #scene.clear() #G_SYMBOLS.clear() # Compute all the coordinates (self-modifying function) # Force the fontsize of the nodes to be 12, as in OpenGEODE # use -n1 below to keep user-specified node coordinates if dump_gfx: dump_name = 'sc_' + os.path.basename(dump_gfx) dump_gfx = os.path.dirname(dump_gfx) or '.' + os.sep + dump_name if dump_gfx.split('.')[-1].lower() != 'png': dump_gfx += '.png' graph.layout(prog='neato', args='{cfg} {kp} {dump}'.format( cfg=config, kp='-n1' if keep_pos else '', dump=('-Tpng -o' + dump_gfx) if dump_gfx else '')) # bb is not visible directly - extract it from the low level api: bounding_rect = [ float(val) for val in dotgraph.graphviz.agget(graph.handle, 'bb').split(',') ] dot_dpi = float(dotgraph.graphviz.agget(graph.handle, 'dpi')) #fontname = graph.graph_attr.get('fontname') #fontsize = graph.graph_attr.get('fontsize') #with open('statechart.dot', 'w') as output: # output.write(graph.to_string()) nodes = preprocess_nodes(graph, bounding_rect, dot_dpi) node_symbols = [] for node in nodes: shape = node.get('shape') try: node_symbol = lookup[shape](node, graph) if unicode(node_symbol) in graphtree['children'] \ and shape == 'record': # Use a different color for non-terminal states node_symbol.setBrush(QtGui.QBrush(QtGui.QColor(249, 249, 249))) G_SYMBOLS.add(node_symbol) node_symbols.append(node_symbol) scene.addItem(node_symbol) except KeyError: raise TypeError('Statechart - unsupported shape: ' + shape) edges = preprocess_edges(graph, node_symbols, bounding_rect, dot_dpi) for edge in edges: Edge(edge, graph) # Make sure the scene has no negative coordinates scene.translate_to_origin() for aname, agraph in graphtree['children'].viewitems(): # At the end, place the content of the scene of the composite states # in the symbol by moving them from their temporary scene for symb in scene.visible_symb: if unicode(symb) == aname: deltapos = symb.scenePos() + QtCore.QPointF(30.0, 30.0) for each in agraph['scene'].floating_symb: # In principle we should change the parentItem to make sure # that all children items are moved together with their # parent. Unfortunately calls to setParentItem provoke # a segfault. To be tried again when PySide is fixed... # Update (04/2019) Workaround found (see sdlSymbols.py) if symb.scene() != each.scene(): symb.scene().addItem(each) each.setParent(symb) each.position += deltapos each.setZValue(each.zValue() + symb.zValue() + 1)
def createBrushFromGradient(color1, color2): gradient = QtGui.QLinearGradient(100, 100, 200, 200) gradient.setColorAt(0.2, QtGui.QColor(*color1)) gradient.setColorAt(0.8, QtGui.QColor(*color2)) return QtGui.QBrush(gradient)
def update_table(self): class NumberWidgetItem(QtGui.QTableWidgetItem): def __lt__(self, other): try: return float(self.text()) < float(other.text()) except Exception: return True class LocationWidgetItem(QtGui.QTableWidgetItem): def __lt__(self, other): self_lon = self.text()[1:].split(';')[0] other_lon = other.text()[1:].split(';')[0] self_lat = self.text()[:-1].split(';')[-1] other_lat = other.text()[:-1].split(';')[-1] logger.debug("%s %s < %s %s" % (self_lon, self_lat, other_lon, other_lat)) try: if self_lon == other_lon: return float(self_lat) < float(other_lat) return float(self_lon) < float(other_lon) except Exception: return True # set the top label self.active_label.setText("<b>Current project: %s</b>" % self.lib.current_project) lst = self.lib.db_list_profiles() # prepare the table self.ssp_list.setSortingEnabled(False) self.ssp_list.clear() self.ssp_list.setColumnCount(23) self.ssp_list.setHorizontalHeaderLabels([ 'id', 'time', 'location', 'sensor', 'probe', 'ss@min depth', 'min depth', 'max depth', 'max depth[no ext]', 'original path', 'institution', 'survey', 'vessel', 'sn', 'processing time', 'processing info', 'comments', 'pressure uom', 'depth uom', 'speed uom', 'temperature uom', 'conductivity uom', 'salinity uom', ]) # populate the table self.ssp_list.setRowCount(len(lst)) for i, ssp_ in enumerate(lst): processed = True tokens = ssp_[11].split(";") # Re-arrange index to match the new items and labels ssp = ssp_[0:5] + ssp_[19:23] + ssp_[5:19] if Dicts.proc_user_infos['PLOTTED'] not in tokens: processed = False for j, field in enumerate(ssp): if j == 3: label = '%s' % Dicts.first_match(Dicts.sensor_types, int(field)) # logger.debug('%s' % Dicts.first_match(Dicts.sensor_types, int(field))) elif j == 4: label = '%s' % Dicts.first_match(Dicts.probe_types, int(field)) # logger.debug('%s' % Dicts.first_match(Dicts.probe_types, int(field))) else: label = field if j in [ 0, 5, 6, 7, 8, ]: item = NumberWidgetItem("%s" % label) elif j in [ 2, ]: item = LocationWidgetItem("%s" % label) else: item = QtGui.QTableWidgetItem("%s" % label) if (j == 3) and (int(field) == Dicts.sensor_types['Future']): item.setForeground(QtGui.QColor(200, 100, 100)) elif (j == 4) and (int(field) == Dicts.sensor_types['Future']): item.setForeground(QtGui.QColor(200, 100, 100)) if not processed: item.setBackground(QtGui.QColor(200, 100, 100, 50)) item.setTextAlignment(QtCore.Qt.AlignVCenter | QtCore.Qt.AlignHCenter) item.setFlags(QtCore.Qt.ItemIsSelectable | QtCore.Qt.ItemIsEnabled) self.ssp_list.setItem(i, j, item) self.ssp_list.setSortingEnabled(True) self.ssp_list.resizeColumnsToContents()
class LogModel(QtCore.QAbstractTableModel): def __init__(self, *args, **kwargs): QtCore.QAbstractTableModel.__init__(self, *args, **kwargs) self.logLimit = 1000 rootlog.addHandler(LogHandler(self)) self.last_record = None self.records = [] log_colors = { #logging.DEBUG: (QtGui.QColor("white").darker(), QtGui.QColor("white")), logging.INFO: (QtGui.QColor("black"), QtGui.QColor("white")), logging.WARN: (QtGui.QColor("black"), QtGui.QColor("yellow").lighter()), logging.ERROR: (QtGui.QColor("red"), QtGui.QColor("white")), logging.CRITICAL: (QtGui.QColor("red"), QtGui.QColor("white")), } def add_logrecord(self, record): """ :type record: logging.LogRecord """ def clean_msg(msg): return msg.replace("\n", "") count = len(self.records) record.repeat_count = 1 if self.last_record: if record.getMessage() == self.last_record.getMessage(): item = self.records[-1] self.last_record.repeat_count += 1 item.setText("%s (repeated %s times)" % (clean_msg(self.last_record.getMessage()), self.last_record.repeat_count)) return if record.levelno == logging.DEBUG: return fg, bg = self.log_colors[record.levelno] item = QtGui.QStandardItem(clean_msg(record.getMessage())) try: item.setForeground(QtGui.QBrush(fg)) item.setBackground(QtGui.QBrush(bg)) item.record_levelno = record.levelno item.record_name = record.name except AttributeError as e: # WTF: AttributeError: 'PySide.QtOpenGL.QGLContext' object has no attribute 'setData' import pdb; pdb.set_trace() self.beginInsertRows(QtCore.QModelIndex(), len(self.records), len(self.records)) self.records.append(item) self.endInsertRows() if count > self.logLimit: self.beginRemoveRows(QtCore.QModelIndex(), 0, 0) self.records.pop(0) self.endRemoveRows() self.last_record = record self.dataChanged.emit(QtCore.QModelIndex(), QtCore.QModelIndex()) def rowCount(self, parent, index = QtCore.QModelIndex()): """ :type index: QtCore.QModelIndex """ return len(self.records) def columnCount(self, parent, index = QtCore.QModelIndex()): """ :type index: QtCore.QModelIndex """ return 1 def data(self, index, role=Qt.DisplayRole): item = self.records[index.row()] return item.data(role)
def drawBarb_old( qp, origin_x, origin_y, u, v, color='#FFFFFF' ): pen = QtGui.QPen(QtGui.QColor(color), 1, QtCore.Qt.SolidLine) pen.setWidthF(1.) qp.setPen(pen) wnd = np.ceil( tab.utils.mag(u, v) ) ## check if there are any 50kt triangles needed if wnd < 5.: point = QtCore.QPoint( origin_x, origin_y ) qp.drawEllipse(point, 3, 3) else: ## turn the vector into a normal vector u_norm = (u / wnd) v_norm = (v / wnd) ## get the end point of the vector. The scalar multiple is to give it length end_x = origin_x - u_norm * 25 end_y = origin_y + v_norm * 25 qp.drawLine(origin_x, origin_y, end_x, end_y) num_flag_barbs = int( wnd / 50. ) num_full_barbs = int( wnd / 10. ) % 5 num_half_barbs = int( wnd / 5. ) % 2 ## draw the flag barbs for i in xrange(num_flag_barbs): ## use this as a linear offset from the previous barb, ## starting at the end offset1 = 4. * i offset2 = 4. * (i+1) ## calculate the u nd v offset offset_x1 = u_norm * offset1 offset_x2 = u_norm * offset2 offset_y1 = v_norm * offset1 offset_y2 = v_norm * offset2 ## starting from the end of the wind barb, work back ## towards the origin in increments of the offset barbx_start = end_x + offset_x1 flagx_start = end_x + offset_x2 barby_start = end_y - offset_y1 flagy_start = end_y - offset_y2 ## then draw outward perpendicular to the wind barb barbx_end = barbx_start - v_norm * 10 barby_end = barby_start - u_norm * 10 ## draw the barb qp.drawLine(barbx_start, barby_start, barbx_end, barby_end) qp.drawLine(flagx_start, flagy_start, barbx_end, barby_end) for i in xrange(num_full_barbs): ## use this as a linear offset from the previous barb, ## starting at the end if num_flag_barbs > 0: offset = 4. * num_flag_barbs + 4 * i + 2 else: offset = 4. * i ## calculate the u nd v offset offset_x = u_norm * offset offset_y = v_norm * offset ## starting from the end of the wind barb, work back ## towards the origin in increments of the offset barbx_start = end_x + offset_x barby_start = end_y - offset_y ## then draw outward perpendicular to the wind barb barbx_end = barbx_start - v_norm * 10 barby_end = barby_start - u_norm * 10 ## draw the barb qp.drawLine(barbx_start, barby_start, barbx_end, barby_end) ## draw the half barbs for i in xrange(num_half_barbs): ## this time we want to index from 1 so that we don't ## draw on top of the full barbs if num_flag_barbs > 0: i = i + 1 offset = 4. * (num_flag_barbs + 1 + num_full_barbs) else: i = i + 1 offset = 4. * (num_full_barbs) * i ## start at the increment after the last full barb ## get the u and v offset offset_x = u_norm * offset offset_y = v_norm * offset ## starting from the end of the wind barb, work back ## towards the origin in increments of the offset barbx_start = end_x + offset_x barby_start = end_y - offset_y ## then draw outward perpendicular to the wind barb barbx_end = barbx_start - v_norm * 5 barby_end = barby_start - u_norm * 5 qp.drawLine(barbx_start, barby_start, barbx_end, barby_end)
def _create_rules(self): '''Create highlighting rules.''' # Identifiers identifier_format = QtGui.QTextCharFormat() foreground = QtGui.QColor( self.config_theme.get('tokens_highlight', 'identifier_color')) identifier_format.setForeground(foreground) for word in self.keywords.identifier: rule = QtCore.QRegExp('\\b{}\\b'.format(word)) self._highlighting_rules.append((rule, identifier_format)) # Special Identifier case for imported functions identifier_format = QtGui.QTextCharFormat() foreground = QtGui.QColor( self.config_theme.get('tokens_highlight', 'import_color')) identifier_format.setForeground(foreground) for word in self.keywords.imported_functions: rule = QtCore.QRegExp('\\b{}\\b'.format(word)) self._highlighting_rules.append((rule, identifier_format)) # Special Identifier case for banned functions identifier_format = QtGui.QTextCharFormat() foreground = QtGui.QColor( self.config_theme.get('tokens_highlight', 'banned_color')) identifier_format.setForeground(foreground) for word in self.keywords.banned_functions: rule = QtCore.QRegExp('\\b{}\\b'.format(word)) self._highlighting_rules.append((rule, identifier_format)) # Keywords keyword_format = QtGui.QTextCharFormat() foreground = QtGui.QColor( self.config_theme.get('tokens_highlight', 'keyword_color')) keyword_format.setForeground(foreground) keyword_format.setFontWeight(QtGui.QFont.Bold) for word in self.keywords.kkeyword: rule = QtCore.QRegExp('\\b{}\\b'.format(word)) self._highlighting_rules.append((rule, keyword_format)) # Literals literal_format = QtGui.QTextCharFormat() foreground = QtGui.QColor( self.config_theme.get('tokens_highlight', 'literal_color')) literal_format.setForeground(foreground) for word in self.keywords.literal: rule = QtCore.QRegExp('\\b{}\\b'.format(word)) self._highlighting_rules.append((rule, literal_format)) # Comments comment_format = QtGui.QTextCharFormat() foreground = QtGui.QColor( self.config_theme.get('tokens_highlight', 'comment_color')) comment_format.setForeground(foreground) rule = QtCore.QRegExp('//[^\n]*') self._highlighting_rules.append((rule, comment_format)) # Quotation quotation_format = QtGui.QTextCharFormat() foreground = QtGui.QColor( self.config_theme.get('tokens_highlight', 'quotation_color')) quotation_format.setForeground(foreground) rule = QtCore.QRegExp('".*"') self._highlighting_rules.append((rule, quotation_format)) self.comment_start_expression = QtCore.QRegExp('/\\*') self.comment_end_expression = QtCore.QRegExp('\\*/') return
def layoutBarScene(self): """ A convenience method for drawing the sensitivity scene in bar fashion. """ self.scene.clear() width = self.scene.width() height = self.scene.height() plotWidth = width - 2 * self.padding plotHeight = height - 2 * self.padding maxExtent = plotWidth axisPen = qtg.QPen(qtc.Qt.black) names = self.amsc.GetNames()[:-1] selection = self.amsc.GetSelectedSegments() colorMap = self.amsc.GetColors() if self.valueGroup.checkedAction().text() == 'Linear coefficients': fits = self.amsc.SegmentFitCoefficients() elif self.valueGroup.checkedAction().text() == 'Pearson correlation': fits = self.amsc.SegmentPearsonCoefficients() elif self.valueGroup.checkedAction().text( ) == 'Spearman rank correlation': fits = self.amsc.SegmentSpearmanCoefficients() ## Check if they selected any extrema if selection is None or len(selection) == 0: selection = [] selectedExts = self.amsc.GetSelectedExtrema() allSegments = self.amsc.GetCurrentLabels() for minMaxPair in allSegments: for extIdx in selectedExts: if extIdx in minMaxPair: selection.append(minMaxPair) ## Okay, well then we will just plot everything we have for the current ## level if len(selection) == 0: selection = allSegments if self.valueGroup.checkedAction().text() == 'Linear coefficients': maxValue = 0 for extPair in selection: if maxValue < max(map(abs, fits[extPair])): maxValue = max(map(abs, fits[extPair])) else: maxValue = 1 if self.bundledAction.isChecked(): axisHeight = plotHeight / float(len(names)) axisWidth = plotWidth / float(len(names)) for j, extPair in enumerate(selection): myColor = colorMap[extPair] myPen = qtg.QPen(qtg.QColor('#000000')) brushColor = qtg.QColor(myColor) brushColor.setAlpha(127) myBrush = qtg.QBrush(brushColor) for i, val in enumerate(fits[extPair]): absVal = abs(val) barExtent = (absVal / maxValue) * maxExtent if self.signedAction.isChecked(): x = self.padding + maxExtent / 2. if val > 0: w = barExtent / 2. else: w = -barExtent / 2. else: x = self.padding w = barExtent y = (height-self.padding) - i*axisHeight \ - j*axisHeight/float(len(selection)) h = -axisHeight / float(len(selection)) if self.showNumberAction.isChecked(): numTxtItem = self.scene.addSimpleText( '%.3g' % val, self.font) numTxtItem.setFlag( qtw.QGraphicsItem.ItemIgnoresTransformations) fm = qtg.QFontMetrics(numTxtItem.font()) fontWidth = fm.width(numTxtItem.text()) numTxtItem.setPos(self.padding + maxExtent - fontWidth, y + h) numTxtItem.setFlag(qtw.QGraphicsItem.ItemIsMovable) numTxtItem.setFlag(qtw.QGraphicsItem.ItemIsSelectable) numTxtItem.setZValue(2) myRect = self.scene.addRect(x, y, w, h, myPen, myBrush) myRect.setToolTip(str(val)) myRect.setAcceptHoverEvents(True) for i, name in enumerate(names): x = self.padding y = height - self.padding - i / float(len(names)) * plotHeight w = plotWidth h = -axisHeight if self.showLabelsAction.isChecked(): txtItem = self.scene.addSimpleText(name, self.font) txtItem.setFlag( qtw.QGraphicsItem.ItemIgnoresTransformations) fm = qtg.QFontMetrics(txtItem.font()) fontHeight = fm.height() fontWidth = fm.width(txtItem.text()) txtItem.setPos(self.padding - fontWidth, y + h + (axisHeight - fontHeight) / 2.) txtItem.setFlag(qtw.QGraphicsItem.ItemIsMovable) txtItem.setFlag(qtw.QGraphicsItem.ItemIsSelectable) txtItem.setZValue(2) myRect = self.scene.addRect(x, y, w, h, axisPen) myRect.setZValue( 2) # Any value greater than 1 should work to draw on top else: if len(selection) > 0: axisHeight = plotHeight / float(len(selection)) axisWidth = plotWidth / float(len(selection)) dimCount = len(names) self.font.setPointSizeF( np.clip(axisHeight / float(dimCount) - 2 * self.padding, 2, 18)) for j, extPair in enumerate(selection): myColor = colorMap[extPair] myPen = qtg.QPen(qtg.QColor('#000000')) brushColor = qtg.QColor(myColor) brushColor.setAlpha(127) myBrush = qtg.QBrush(brushColor) for i, val in enumerate(fits[extPair]): absVal = abs(val) name = names[i] barExtent = (absVal / maxValue) * maxExtent if self.signedAction.isChecked(): x = self.padding + maxExtent / 2. if val > 0: w = barExtent / 2. else: w = -barExtent / 2. else: x = self.padding w = barExtent y = (height-self.padding) - j*axisHeight \ - i*axisHeight/float(dimCount) h = -axisHeight / float(dimCount) if self.showLabelsAction.isChecked(): txtItem = self.scene.addSimpleText(name, self.font) ## this line can be useful for text sizing, although we cannot ## rotate the text if we ignore the transformations. # txtItem.setFlag(qtw.QGraphicsItem.ItemIgnoresTransformations) fm = qtg.QFontMetrics(txtItem.font()) fontHeight = fm.boundingRect(txtItem.text()).height() fontWidth = fm.boundingRect(txtItem.text()).width() txtItem.setPos(self.padding, y + 0.5 * (h - fontHeight)) txtItem.setFlag(qtw.QGraphicsItem.ItemIsMovable) txtItem.setFlag(qtw.QGraphicsItem.ItemIsSelectable) txtItem.setZValue(2) if self.showNumberAction.isChecked(): numTxtItem = self.scene.addSimpleText( '%.3g' % val, self.font) ## this line can be useful for text sizing, although we cannot ## rotate the text if we ignore the transformations. # numTxtItem.setFlag(qtw.QGraphicsItem.ItemIgnoresTransformations) fm = qtg.QFontMetrics(numTxtItem.font()) fontWidth = fm.boundingRect(numTxtItem.text()).width() fontHeight = fm.boundingRect( numTxtItem.text()).height() numTxtItem.setPos(self.padding + maxExtent - fontWidth, y + 0.5 * (h - fontHeight)) numTxtItem.setFlag(qtw.QGraphicsItem.ItemIsMovable) numTxtItem.setFlag(qtw.QGraphicsItem.ItemIsSelectable) numTxtItem.setZValue(2) myRect = self.scene.addRect(x, y, w, h, myPen, myBrush) myRect.setToolTip(str(val)) myRect.setAcceptHoverEvents(True) x = self.padding y = (height - self.padding) - j * axisHeight w = maxExtent h = -axisHeight myRect = self.scene.addRect(x, y, w, h, axisPen) myRect.setZValue( 2) # Any value greater than 1 should work to draw on top if self.signedAction.isChecked(): axisPen = qtg.QPen(qtc.Qt.black) axisPen.setWidthF(.5) x = self.padding + maxExtent / 2. y = self.padding h = plotHeight self.scene.addLine(x, y, x, y + h, axisPen)
def color(self): if self._color is None: self._color = QtGui.QColor(self._parts['color']) return self._color
def paint(self, painter, option, widget): painter.save() margin = 20 rect = self.boundingRect() dis_rect = QtCore.QRectF(rect.left() - (margin / 2), rect.top() - (margin / 2), rect.width() + margin, rect.height() + margin) pen = QtGui.QPen(QtGui.QColor(*self.color), 8) pen.setCapStyle(QtCore.Qt.RoundCap) painter.setPen(pen) painter.drawLine(dis_rect.topLeft(), dis_rect.bottomRight()) painter.drawLine(dis_rect.topRight(), dis_rect.bottomLeft()) bg_color = QtGui.QColor(*self.color) bg_color.setAlpha(100) bg_margin = -0.5 bg_rect = QtCore.QRectF(dis_rect.left() - (bg_margin / 2), dis_rect.top() - (bg_margin / 2), dis_rect.width() + bg_margin, dis_rect.height() + bg_margin) painter.setPen(QtGui.QPen(QtGui.QColor(0, 0, 0, 0))) painter.setBrush(bg_color) painter.drawRoundedRect(bg_rect, 5, 5) pen = QtGui.QPen(QtGui.QColor(155, 0, 0, 255), 0.5) painter.setPen(pen) painter.drawLine(dis_rect.topLeft(), dis_rect.bottomRight()) painter.drawLine(dis_rect.topRight(), dis_rect.bottomLeft()) point_size = 3.0 point_pos = (dis_rect.topLeft(), dis_rect.topRight(), dis_rect.bottomLeft(), dis_rect.bottomRight()) painter.setBrush(QtGui.QColor(255, 0, 0, 255)) for p in point_pos: p.setX(p.x() - (point_size / 2)) p.setY(p.y() - (point_size / 2)) point_rect = QtCore.QRectF(p, QtCore.QSizeF(point_size, point_size)) painter.drawEllipse(point_rect) if self.text: font = painter.font() font.setPointSize(10) painter.setFont(font) font_metrics = QtGui.QFontMetrics(font) font_width = font_metrics.width(self.text) font_height = font_metrics.height() txt_w = font_width * 1.25 txt_h = font_height * 2.25 text_bg_rect = QtCore.QRectF((rect.width() / 2) - (txt_w / 2), (rect.height() / 2) - (txt_h / 2), txt_w, txt_h) painter.setPen(QtGui.QPen(QtGui.QColor(255, 0, 0), 0.5)) painter.setBrush(QtGui.QColor(*self.color)) painter.drawRoundedRect(text_bg_rect, 2, 2) text_rect = QtCore.QRectF((rect.width() / 2) - (font_width / 2), (rect.height() / 2) - (font_height / 2), txt_w * 2, font_height * 2) painter.setPen(QtGui.QPen(QtGui.QColor(255, 0, 0), 1)) painter.drawText(text_rect, self.text) painter.restore()
def bdPopulateFiles(self): #Wip files #wipFileList = [f for f in sorted(os.listdir(self.wipFolderPath)) if (f.endswith('.ma') or f.endswith('.mb'))] #get files based on pattern , will fetch only files ending in version token ( double digit number) path, currentFile = os.path.split(pm.sceneName()) self.wipAnimTable.clearContents() self.wipAnimTable.setSortingEnabled(0) self.previewAnimTable.clearContents() self.previewAnimTable.setSortingEnabled(0) wipFileList = [] tempList = glob.glob(self.wipFolderPath + '/*_*[0-9][0-9].m[ab]') for ele in tempList: path, filename = os.path.split(ele) wipFileList.append(filename) self.wipAnimTable.setColumnCount(3) self.wipAnimTable.setRowCount(len(wipFileList)) for i in range(len(wipFileList)): item = QtGui.QTableWidgetItem(wipFileList[i]) item.setFlags(~QtCore.Qt.ItemIsEditable) if wipFileList[i] == currentFile: item.setBackground(QtGui.QColor(0, 100, 0)) self.wipAnimTable.setItem(i, 0, item) version = self.getAnimVersion(wipFileList[i]) item = QtGui.QTableWidgetItem(version) item.setFlags(~QtCore.Qt.ItemIsEditable) item.setTextAlignment(QtCore.Qt.AlignCenter) self.wipAnimTable.setItem(i, 1, item) hasPlayblast = 'No' if self.hasPlayblast(wipFileList[i]): hasPlayblast = 'Yes' item = QtGui.QTableWidgetItem(hasPlayblast) item.setFlags(~QtCore.Qt.ItemIsEditable) item.setTextAlignment(QtCore.Qt.AlignCenter) if hasPlayblast == 'Yes': item.setBackground(QtGui.QColor(0, 180, 50)) else: item.setBackground(QtGui.QColor(200, 150, 0)) self.wipAnimTable.setItem(i, 2, item) self.wipAnimTable.resizeColumnsToContents() self.wipAnimTable.setSortingEnabled(1) self.wipAnimTable.sortItems(0, QtCore.Qt.AscendingOrder) self.wipHheader.setStretchLastSection(True) self.previewHheader.setStretchLastSection(True) #Populate Preview files #previewFileList = [f for f in sorted(os.listdir(self.wipFolderPath.replace('01_wip','03_preview'))) if (f.endswith('.ma') or f.endswith('.mb'))] previewFileList = [] tempList = glob.glob( self.wipFolderPath.replace('01_wip', '03_preview') + '/*[0-9].m[ab]') for ele in tempList: path, filename = os.path.split(ele) previewFileList.append(filename) self.previewAnimTable.setColumnCount(3) self.previewAnimTable.setRowCount(len(previewFileList)) for i in range(len(previewFileList)): item = QtGui.QTableWidgetItem(previewFileList[i]) item.setFlags(~QtCore.Qt.ItemIsEditable) self.previewAnimTable.setItem(i, 0, item) version = self.getAnimVersion(previewFileList[i]) item = QtGui.QTableWidgetItem(version) item.setFlags(~QtCore.Qt.ItemIsEditable) item.setTextAlignment(QtCore.Qt.AlignCenter) self.previewAnimTable.setItem(i, 1, item) hasPlayblast = 'No' if self.hasPlayblast(previewFileList[i], 'preview'): hasPlayblast = 'Yes' item = QtGui.QTableWidgetItem(hasPlayblast) item.setFlags(~QtCore.Qt.ItemIsEditable) item.setTextAlignment(QtCore.Qt.AlignCenter) if hasPlayblast == 'Yes': item.setBackground(QtGui.QColor(0, 180, 50)) else: item.setBackground(QtGui.QColor(200, 150, 0)) self.previewAnimTable.setItem(i, 2, item) self.previewAnimTable.resizeColumnsToContents() self.previewAnimTable.setSortingEnabled(1) self.previewAnimTable.sortItems(0, QtCore.Qt.AscendingOrder)
def getColorHash(self, col, val=255): "returns a '#000000' string from a '(0.1,0.2,0.3)' string" col = [float(x.strip()) for x in col.strip("()").split(",")] color = QtGui.QColor(int(col[0] * val), int(col[1] * val), int(col[2] * val)) return color.name()
def convertcolor(c): return QtGui.QColor(int((c >> 24) & 0xFF), int((c >> 16) & 0xFF), int((c >> 8) & 0xFF))
def matProperWidget(parent=None, matproperty=None, Type="String", Value=None, minimum=None, maximum=None, stepsize=None, precision=None): '''customs widgets for the material stuff.''' if Type == "String": widget = ui.createWidget("Gui::PrefLineEdit") elif Type == "URL": widget = ui.createWidget("Gui::PrefLineEdit") elif Type == "File": widget = ui.createWidget("Gui::FileChooser") if Value: lineEdit = widget.children()[1] lineEdit.setText(Value) elif Type == "Quantity": widget = ui.createWidget("Gui::InputField") if hasattr(FreeCAD.Units, matproperty): unit = getattr(FreeCAD.Units, matproperty) quantity = FreeCAD.Units.Quantity(1, unit) widget.setProperty('unit', quantity.getUserPreferred()[2]) else: FreeCAD.Console.PrintError( 'Not known unit for property: {}\n'.format(matproperty)) elif Type == "Integer": widget = ui.createWidget("Gui::UIntSpinBox") elif Type == "Float": widget = ui.createWidget("Gui::PrefDoubleSpinBox") elif Type == "Enumerator": widget = ui.createWidget("Gui::PrefComboBox") elif Type == "Boolean": widget = ui.createWidget("Gui::PrefComboBox") widget.insertItems(0, ['', 'False', 'True']) elif Type == "Vector": widget = ui.createWidget("Gui::PrefLineEdit") elif Type == "Color": widget = ui.createWidget("Gui::PrefColorButton") if Value: value = string2tuple(Value) color = QtGui.QColor() color.setRgb(value[0], value[1], value[2], value[3]) widget.setProperty('color', color) else: widget = QtGui.QLineEdit() if minimum is not None: widget.setProperty('minimum', minimum) if maximum is not None: widget.setProperty('maximum', maximum) if stepsize is not None: widget.setProperty('stepsize', stepsize) if precision is not None: widget.setProperty('precision', precision) widget.setProperty('Type', Type) widget.setParent(parent) return widget
def __init__(self, parent, parentWidget, vialNo=None, behaviourName=None, annotator=None, color=None, geo=None): super(AnnoView, self).__init__(parentWidget) #QGraphicsView.__init__(parent) # draw center markers of graphics view self.parentVP = parent if geo is not None: self.setGeometry(geo) self.width = geo.width() amWidth = 10 cMarkerExtra = 5 topBuffer = (geo.height() - amWidth) / 2 self.activeMarker = QtGui.QLabel(parentWidget) self.activeMarker.setGeometry(QtCore.QRect(geo.x(), geo.y() + topBuffer, amWidth, amWidth)) self.activeMarker.setStyleSheet(""" QLabel {{ background-color: {0} }}""".format(color.name())) self.activeMarker.setVisible(False) self.setStyleSheet("* {margin: 0px; border-width: 0px; padding: 0px}") self.gV = QtGui.QGraphicsView(parentWidget) self.gV.setGeometry(QtCore.QRect(amWidth + 15, cMarkerExtra, geo.width(), geo.height())) self.gV.setFrameStyle(QtGui.QFrame.NoFrame) self.gV.setStyleSheet("* {margin: 0px; border-width: 0px; padding: 0px}") self.cMarker1 = QtGui.QLabel(parentWidget) gvGeo = self.gV.geometry() self.cMarker1.setGeometry(QtCore.QRect(gvGeo.x() + gvGeo.width() / 2, 0, 1, gvGeo.height() + cMarkerExtra * 2)) self.cMarker1.setFrameStyle(QtGui.QFrame.VLine) self.cMarker1.raise_() self.prevConnectHooks = [] parPos = self.mapToGlobal(QtCore.QPoint(0,0)) for i in range(100): self.prevConnectHooks += [[QtCore.QPoint(parPos.x(), parPos.y()), QtCore.QPoint(parPos.x(), parPos.y() - 3)]] parPos.setX(parPos.x() + 10) # initialization of parameters self.annotationDict = dict() self.color = QtGui.QColor(0,255,0,150) self.zoomLevels = [10,10,10,10,10,10,10]#[0.5, 0.6, 0.8, 1, 2, 5, 10] self.zoom = 2 self.lines = dict() self.frames = dict() self.absIdx = dict() self.chunks = dict() self.scene = None self.selKey = None self.idx = None self.boxHeight = self.geometry().height() #filters self.vialNo = None self.behaviourName=None self.annotator=None self.erasingAnno = False self.addingAnno = False self.tempAnno = dict() self.inEditMode = False # setting values self.scene = QtGui.QGraphicsScene(self.gV) # self.scene.setSceneRect(QRectF(-50000, -20, 100000, 20)) self.gV.setScene(self.scene) self.gV.setHorizontalScrollBarPolicy(QtCore.Qt.ScrollBarAlwaysOff) self.gV.setVerticalScrollBarPolicy(QtCore.Qt.ScrollBarAlwaysOff) self.vialNo = vialNo self.behaviourName = behaviourName self.annotator = annotator if color == None: self.color = QtGui.QColor(0,255,0,150) else: self.color = color colI = QtGui.QColor(0,0,0,0) self.penA = QtGui.QPen(colI) self.brushA = QtGui.QBrush(self.color) self.penI = QtGui.QPen(colI) self.brushI = QtGui.QBrush(colI) self.addList = [] #{key: (string), range: slice} self.removeList = [] #{key: (string), range: slice} self.frameAmount = 101 ## odd number please self.confidenceList = [] self.tempRng = dict() self.lines = [] self.frames = [] self.annoViewRects = [] for i in range(self.frameAmount): self.lines += [(self.scene.addLine(i, 0, i, self.boxHeight, QtGui.QPen(QtGui.QColor(100,100,100))))] for i in range(self.frameAmount): self.frames += [AnnoViewItem(self, QtCore.QRectF(i, 0, 1, self.boxHeight))]#self, QRectF(i, 0, 1, self.boxHeight))] self.scene.addItem(self.frames[-1]) center = self.frameAmount / 2 + 1 self.gV.centerOn(self.frames[center]) self.setZoom(0)
def updatePixelColor(self): height = self.frameGeometry().height() width = self.frameGeometry().width() pixel_pos = QtCore.QPoint(self.__selector_x*9*width/10, self.__selector_y*8*height/9) self.selected_color = QtGui.QColor(self.gradient_image.pixel(pixel_pos))
#creating points to dimension. circlesXML = [] noPoints = 12 X = [ numpy.random.rand()*width*0.8 for i in range(noPoints) ] Y = [ numpy.random.rand()*height*0.8 for i in range(noPoints) ] for i in range(noPoints): circlesXML.append( '<circle id="circ%03i" cx ="%f" cy ="%f" r ="6" />' % (i,X[i],Y[i]) ) XML = '''<svg id="Ortho_0_1" width="%i" height="%i"> <g stroke-width="0.2" > %s </g> </svg>''' % (width, height, '\n'.join(circlesXML) ) viewObject = dummyViewObject( XML ) hoverPen = QtGui.QPen( QtGui.QColor(255,0,0) ) hoverPen.setWidth(3.0) selectGraphicsItems = generateSelectionGraphicsItems( [viewObject], dimensioningRect.selectDimensioningPoint , doCircles=True, maskPen= QtGui.QPen( QtGui.QColor(0,0,0) ) , maskBrush=QtGui.QBrush( QtGui.QColor(0,0,255) ), maskHoverPen= hoverPen ) graphicsScene.addItem(dimensioningRect) for g in selectGraphicsItems: graphicsScene.addItem(g) view = QtGui.QGraphicsView(graphicsScene) #view.scale(2, 2) view.show()
#!/usr/local/bin/python2.7 # encoding: utf-8 ''' Created on 2017.11.17 @author: Serious Sam ''' import logging from PySide import QtCore, QtGui from barbarian.utils import config from . import model status_colors = { "Check": QtGui.QColor(255, 255, 90, 255), "Approve": QtGui.QColor(90, 255, 90, 255), "FinalApprove": QtGui.QColor(90, 255, 90, 255), "Retake": QtGui.QColor(255, 90, 90, 255) } fonts = { "h4": QtGui.QFont(u"Century Gothic", 11, QtGui.QFont.Normal), "h5": QtGui.QFont(u"微软雅黑", 10, 800) } stage_icons = { "Modeling": QtGui.QPixmap(config.getPath(config.kIcon, "css/stage_mdl.png")), "Mod": QtGui.QPixmap(config.getPath(config.kIcon, "css/stage_mdl.png")), "Texturing": QtGui.QPixmap(config.getPath(config.kIcon, "css/stage_txt.png")),
def getHoverPen(self): ret = QtGui.QPen() ret.setColor(QtGui.QColor(0, 255, 255, 255)) return ret
def paint(self, painter, option, index): height = self.height_label if index.data( model.TASK_ITEM_TYPE ) == model.TASK_LABEL_TYPE else self.height_data indent = self.indent_offset if index.data( model.TASK_ITEM_TYPE ) == model.TASK_LABEL_TYPE else self.indent_offset * 2 item_rect = option.rect.adjusted(indent + 1, 1, -1, 0) frame_rect = option.rect.adjusted(indent, 0, 0, 0) painter.save() painter.setPen(QtGui.QPen(QtGui.QColor(0, 0, 0, 255))) painter.drawRect(frame_rect) if option.state & QtGui.QStyle.State_Selected: g_selected = QtGui.QLinearGradient(0, item_rect.y(), 0, item_rect.y() + height) g_selected.setColorAt(0.0, QtGui.QColor(50, 30, 100, 255)) g_selected.setColorAt(self.thickness / height, QtGui.QColor(90, 40, 140, 255)) g_selected.setColorAt(1.0, QtGui.QColor(100, 50, 150, 255)) g_selected.setSpread(QtGui.QGradient.ReflectSpread) painter.fillRect(item_rect, g_selected) elif option.state & QtGui.QStyle.State_MouseOver: g_hover = QtGui.QLinearGradient(0, item_rect.y(), 0, item_rect.y() + height) g_hover.setColorAt(0.0, QtGui.QColor(200, 100, 255, 255)) g_hover.setColorAt(self.thickness / height, QtGui.QColor(150, 50, 200, 255)) g_hover.setColorAt(1.0 - self.thickness / height, QtGui.QColor(130, 0, 180, 255)) g_hover.setColorAt(1.0, QtGui.QColor(80, 0, 80, 255)) painter.fillRect(item_rect, g_hover) if index.data(model.TASK_ITEM_TYPE) == model.TASK_LABEL_TYPE: branch_rect = item_rect.adjusted(1, 6, -1, -6) branch_rect.setWidth(16) branch_rect.setHeight(16) label_rect = item_rect.adjusted(-self.indent_offset, 0, 0, 0) if option.state & QtGui.QStyle.State_Open: branch_icon = config.getPath(config.kIcon, "css/branch-open.png") else: branch_icon = config.getPath(config.kIcon, "css/branch-closed.png") painter.drawPixmap(branch_rect, branch_icon) painter.setPen(QtGui.QPen(QtGui.QColor(200, 200, 200, 255))) painter.setFont(fonts["h5"]) painter.drawText(label_rect, QtCore.Qt.AlignVCenter, index.data()) painter.restore() return status_rect = QtCore.QRectF(item_rect).adjusted( 0, self.margin, -self.margin, -self.margin - 1) status_rect.setWidth(15) status_color = status_colors.get(index.data(model.TASK_STATUS), QtGui.QColor(255, 255, 255, 255)) status_shade = QtGui.QLinearGradient( 0, status_rect.y(), 0, status_rect.y() + status_rect.height()) status_shade.setColorAt(0.0, QtGui.QColor(0, 0, 0, 255)) status_shade.setColorAt(8.0 / status_rect.height(), QtGui.QColor(255, 255, 255, 50)) status_shade.setColorAt(1.0 - 5.0 / status_rect.height(), QtGui.QColor(0, 0, 0, 120)) status_shade.setColorAt(1.0, QtGui.QColor(0, 0, 0, 180)) stage_rect = QtCore.QRect( item_rect.adjusted(16, self.margin, -self.margin, -self.margin)) stage_rect.setWidth(48) stage_rect.setHeight(48) painter.fillRect(status_rect, status_color) painter.fillRect(status_rect, status_shade) painter.setPen(QtGui.QPen(QtGui.QColor(0, 0, 0, 255))) painter.drawRect(status_rect) painter.drawPixmap( stage_rect, stage_icons.get(index.data(model.TASK_STAGE), config.getPath(config.kIcon, "css/stage_null.png"))) painter.restore()
def setupUi(self, MainWindow): MainWindow.setObjectName("MainWindow") MainWindow.resize(668, 427) self.centralwidget = QtGui.QWidget(MainWindow) self.centralwidget.setObjectName("centralwidget") self.verticalLayout_3 = QtGui.QVBoxLayout(self.centralwidget) self.verticalLayout_3.setObjectName("verticalLayout_3") self.horizontalLayout_3 = QtGui.QHBoxLayout() self.horizontalLayout_3.setObjectName("horizontalLayout_3") self.groupBox = QtGui.QGroupBox(self.centralwidget) self.groupBox.setObjectName("groupBox") self.horizontalLayout = QtGui.QHBoxLayout(self.groupBox) self.horizontalLayout.setObjectName("horizontalLayout") self.startButton = QtGui.QPushButton(self.groupBox) icon = QtGui.QIcon() icon.addPixmap(QtGui.QPixmap("../../../record.png"), QtGui.QIcon.Normal, QtGui.QIcon.Off) self.startButton.setIcon(icon) self.startButton.setObjectName("startButton") self.horizontalLayout.addWidget(self.startButton) self.stopButton = QtGui.QPushButton(self.groupBox) self.stopButton.setEnabled(False) icon1 = QtGui.QIcon() icon1.addPixmap(QtGui.QPixmap("../../../stop2.png"), QtGui.QIcon.Normal, QtGui.QIcon.Off) self.stopButton.setIcon(icon1) self.stopButton.setObjectName("stopButton") self.horizontalLayout.addWidget(self.stopButton) self.horizontalLayout_3.addWidget(self.groupBox) self.groupBox_2 = QtGui.QGroupBox(self.centralwidget) self.groupBox_2.setObjectName("groupBox_2") self.horizontalLayout_2 = QtGui.QHBoxLayout(self.groupBox_2) self.horizontalLayout_2.setObjectName("horizontalLayout_2") self.locationEdit = QtGui.QLineEdit(self.groupBox_2) self.locationEdit.setMinimumSize(QtCore.QSize(361, 0)) self.locationEdit.setObjectName("locationEdit") self.horizontalLayout_2.addWidget(self.locationEdit) self.browseButton = QtGui.QPushButton(self.groupBox_2) self.browseButton.setObjectName("browseButton") self.horizontalLayout_2.addWidget(self.browseButton) self.horizontalLayout_3.addWidget(self.groupBox_2) self.verticalLayout_3.addLayout(self.horizontalLayout_3) self.horizontalLayout_4 = QtGui.QHBoxLayout() self.horizontalLayout_4.setObjectName("horizontalLayout_4") self.groupBox_3 = QtGui.QGroupBox(self.centralwidget) palette = QtGui.QPalette() brush = QtGui.QBrush(QtGui.QColor(0, 0, 0)) brush.setStyle(QtCore.Qt.SolidPattern) palette.setBrush(QtGui.QPalette.Active, QtGui.QPalette.WindowText, brush) brush = QtGui.QBrush(QtGui.QColor(168, 194, 255)) brush.setStyle(QtCore.Qt.SolidPattern) palette.setBrush(QtGui.QPalette.Active, QtGui.QPalette.Button, brush) brush = QtGui.QBrush(QtGui.QColor(255, 255, 255)) brush.setStyle(QtCore.Qt.SolidPattern) palette.setBrush(QtGui.QPalette.Active, QtGui.QPalette.Light, brush) brush = QtGui.QBrush(QtGui.QColor(211, 224, 255)) brush.setStyle(QtCore.Qt.SolidPattern) palette.setBrush(QtGui.QPalette.Active, QtGui.QPalette.Midlight, brush) brush = QtGui.QBrush(QtGui.QColor(84, 97, 127)) brush.setStyle(QtCore.Qt.SolidPattern) palette.setBrush(QtGui.QPalette.Active, QtGui.QPalette.Dark, brush) brush = QtGui.QBrush(QtGui.QColor(112, 129, 170)) brush.setStyle(QtCore.Qt.SolidPattern) palette.setBrush(QtGui.QPalette.Active, QtGui.QPalette.Mid, brush) brush = QtGui.QBrush(QtGui.QColor(0, 0, 0)) brush.setStyle(QtCore.Qt.SolidPattern) palette.setBrush(QtGui.QPalette.Active, QtGui.QPalette.Text, brush) brush = QtGui.QBrush(QtGui.QColor(255, 255, 255)) brush.setStyle(QtCore.Qt.SolidPattern) palette.setBrush(QtGui.QPalette.Active, QtGui.QPalette.BrightText, brush) brush = QtGui.QBrush(QtGui.QColor(0, 0, 0)) brush.setStyle(QtCore.Qt.SolidPattern) palette.setBrush(QtGui.QPalette.Active, QtGui.QPalette.ButtonText, brush) brush = QtGui.QBrush(QtGui.QColor(255, 255, 255)) brush.setStyle(QtCore.Qt.SolidPattern) palette.setBrush(QtGui.QPalette.Active, QtGui.QPalette.Base, brush) brush = QtGui.QBrush(QtGui.QColor(168, 194, 255)) brush.setStyle(QtCore.Qt.SolidPattern) palette.setBrush(QtGui.QPalette.Active, QtGui.QPalette.Window, brush) brush = QtGui.QBrush(QtGui.QColor(0, 0, 0)) brush.setStyle(QtCore.Qt.SolidPattern) palette.setBrush(QtGui.QPalette.Active, QtGui.QPalette.Shadow, brush) brush = QtGui.QBrush(QtGui.QColor(211, 224, 255)) brush.setStyle(QtCore.Qt.SolidPattern) palette.setBrush(QtGui.QPalette.Active, QtGui.QPalette.AlternateBase, brush) brush = QtGui.QBrush(QtGui.QColor(255, 255, 220)) brush.setStyle(QtCore.Qt.SolidPattern) palette.setBrush(QtGui.QPalette.Active, QtGui.QPalette.ToolTipBase, brush) brush = QtGui.QBrush(QtGui.QColor(0, 0, 0)) brush.setStyle(QtCore.Qt.SolidPattern) palette.setBrush(QtGui.QPalette.Active, QtGui.QPalette.ToolTipText, brush) brush = QtGui.QBrush(QtGui.QColor(0, 0, 0)) brush.setStyle(QtCore.Qt.SolidPattern) palette.setBrush(QtGui.QPalette.Inactive, QtGui.QPalette.WindowText, brush) brush = QtGui.QBrush(QtGui.QColor(168, 194, 255)) brush.setStyle(QtCore.Qt.SolidPattern) palette.setBrush(QtGui.QPalette.Inactive, QtGui.QPalette.Button, brush) brush = QtGui.QBrush(QtGui.QColor(255, 255, 255)) brush.setStyle(QtCore.Qt.SolidPattern) palette.setBrush(QtGui.QPalette.Inactive, QtGui.QPalette.Light, brush) brush = QtGui.QBrush(QtGui.QColor(211, 224, 255)) brush.setStyle(QtCore.Qt.SolidPattern) palette.setBrush(QtGui.QPalette.Inactive, QtGui.QPalette.Midlight, brush) brush = QtGui.QBrush(QtGui.QColor(84, 97, 127)) brush.setStyle(QtCore.Qt.SolidPattern) palette.setBrush(QtGui.QPalette.Inactive, QtGui.QPalette.Dark, brush) brush = QtGui.QBrush(QtGui.QColor(112, 129, 170)) brush.setStyle(QtCore.Qt.SolidPattern) palette.setBrush(QtGui.QPalette.Inactive, QtGui.QPalette.Mid, brush) brush = QtGui.QBrush(QtGui.QColor(0, 0, 0)) brush.setStyle(QtCore.Qt.SolidPattern) palette.setBrush(QtGui.QPalette.Inactive, QtGui.QPalette.Text, brush) brush = QtGui.QBrush(QtGui.QColor(255, 255, 255)) brush.setStyle(QtCore.Qt.SolidPattern) palette.setBrush(QtGui.QPalette.Inactive, QtGui.QPalette.BrightText, brush) brush = QtGui.QBrush(QtGui.QColor(0, 0, 0)) brush.setStyle(QtCore.Qt.SolidPattern) palette.setBrush(QtGui.QPalette.Inactive, QtGui.QPalette.ButtonText, brush) brush = QtGui.QBrush(QtGui.QColor(255, 255, 255)) brush.setStyle(QtCore.Qt.SolidPattern) palette.setBrush(QtGui.QPalette.Inactive, QtGui.QPalette.Base, brush) brush = QtGui.QBrush(QtGui.QColor(168, 194, 255)) brush.setStyle(QtCore.Qt.SolidPattern) palette.setBrush(QtGui.QPalette.Inactive, QtGui.QPalette.Window, brush) brush = QtGui.QBrush(QtGui.QColor(0, 0, 0)) brush.setStyle(QtCore.Qt.SolidPattern) palette.setBrush(QtGui.QPalette.Inactive, QtGui.QPalette.Shadow, brush) brush = QtGui.QBrush(QtGui.QColor(211, 224, 255)) brush.setStyle(QtCore.Qt.SolidPattern) palette.setBrush(QtGui.QPalette.Inactive, QtGui.QPalette.AlternateBase, brush) brush = QtGui.QBrush(QtGui.QColor(255, 255, 220)) brush.setStyle(QtCore.Qt.SolidPattern) palette.setBrush(QtGui.QPalette.Inactive, QtGui.QPalette.ToolTipBase, brush) brush = QtGui.QBrush(QtGui.QColor(0, 0, 0)) brush.setStyle(QtCore.Qt.SolidPattern) palette.setBrush(QtGui.QPalette.Inactive, QtGui.QPalette.ToolTipText, brush) brush = QtGui.QBrush(QtGui.QColor(84, 97, 127)) brush.setStyle(QtCore.Qt.SolidPattern) palette.setBrush(QtGui.QPalette.Disabled, QtGui.QPalette.WindowText, brush) brush = QtGui.QBrush(QtGui.QColor(168, 194, 255)) brush.setStyle(QtCore.Qt.SolidPattern) palette.setBrush(QtGui.QPalette.Disabled, QtGui.QPalette.Button, brush) brush = QtGui.QBrush(QtGui.QColor(255, 255, 255)) brush.setStyle(QtCore.Qt.SolidPattern) palette.setBrush(QtGui.QPalette.Disabled, QtGui.QPalette.Light, brush) brush = QtGui.QBrush(QtGui.QColor(211, 224, 255)) brush.setStyle(QtCore.Qt.SolidPattern) palette.setBrush(QtGui.QPalette.Disabled, QtGui.QPalette.Midlight, brush) brush = QtGui.QBrush(QtGui.QColor(84, 97, 127)) brush.setStyle(QtCore.Qt.SolidPattern) palette.setBrush(QtGui.QPalette.Disabled, QtGui.QPalette.Dark, brush) brush = QtGui.QBrush(QtGui.QColor(112, 129, 170)) brush.setStyle(QtCore.Qt.SolidPattern) palette.setBrush(QtGui.QPalette.Disabled, QtGui.QPalette.Mid, brush) brush = QtGui.QBrush(QtGui.QColor(84, 97, 127)) brush.setStyle(QtCore.Qt.SolidPattern) palette.setBrush(QtGui.QPalette.Disabled, QtGui.QPalette.Text, brush) brush = QtGui.QBrush(QtGui.QColor(255, 255, 255)) brush.setStyle(QtCore.Qt.SolidPattern) palette.setBrush(QtGui.QPalette.Disabled, QtGui.QPalette.BrightText, brush) brush = QtGui.QBrush(QtGui.QColor(84, 97, 127)) brush.setStyle(QtCore.Qt.SolidPattern) palette.setBrush(QtGui.QPalette.Disabled, QtGui.QPalette.ButtonText, brush) brush = QtGui.QBrush(QtGui.QColor(168, 194, 255)) brush.setStyle(QtCore.Qt.SolidPattern) palette.setBrush(QtGui.QPalette.Disabled, QtGui.QPalette.Base, brush) brush = QtGui.QBrush(QtGui.QColor(168, 194, 255)) brush.setStyle(QtCore.Qt.SolidPattern) palette.setBrush(QtGui.QPalette.Disabled, QtGui.QPalette.Window, brush) brush = QtGui.QBrush(QtGui.QColor(0, 0, 0)) brush.setStyle(QtCore.Qt.SolidPattern) palette.setBrush(QtGui.QPalette.Disabled, QtGui.QPalette.Shadow, brush) brush = QtGui.QBrush(QtGui.QColor(168, 194, 255)) brush.setStyle(QtCore.Qt.SolidPattern) palette.setBrush(QtGui.QPalette.Disabled, QtGui.QPalette.AlternateBase, brush) brush = QtGui.QBrush(QtGui.QColor(255, 255, 220)) brush.setStyle(QtCore.Qt.SolidPattern) palette.setBrush(QtGui.QPalette.Disabled, QtGui.QPalette.ToolTipBase, brush) brush = QtGui.QBrush(QtGui.QColor(0, 0, 0)) brush.setStyle(QtCore.Qt.SolidPattern) palette.setBrush(QtGui.QPalette.Disabled, QtGui.QPalette.ToolTipText, brush) self.groupBox_3.setPalette(palette) self.groupBox_3.setObjectName("groupBox_3") self.verticalLayout_2 = QtGui.QVBoxLayout(self.groupBox_3) self.verticalLayout_2.setObjectName("verticalLayout_2") self.streamList = QtGui.QListWidget(self.groupBox_3) self.streamList.setSelectionMode( QtGui.QAbstractItemView.SingleSelection) self.streamList.setSelectionBehavior( QtGui.QAbstractItemView.SelectItems) self.streamList.setObjectName("streamList") self.verticalLayout_2.addWidget(self.streamList) self.refreshButton = QtGui.QPushButton(self.groupBox_3) self.refreshButton.setObjectName("refreshButton") self.verticalLayout_2.addWidget(self.refreshButton) self.horizontalLayout_4.addWidget(self.groupBox_3) self.groupBox_4 = QtGui.QGroupBox(self.centralwidget) palette = QtGui.QPalette() brush = QtGui.QBrush(QtGui.QColor(0, 0, 0)) brush.setStyle(QtCore.Qt.SolidPattern) palette.setBrush(QtGui.QPalette.Active, QtGui.QPalette.WindowText, brush) brush = QtGui.QBrush(QtGui.QColor(168, 194, 255)) brush.setStyle(QtCore.Qt.SolidPattern) palette.setBrush(QtGui.QPalette.Active, QtGui.QPalette.Button, brush) brush = QtGui.QBrush(QtGui.QColor(255, 255, 255)) brush.setStyle(QtCore.Qt.SolidPattern) palette.setBrush(QtGui.QPalette.Active, QtGui.QPalette.Light, brush) brush = QtGui.QBrush(QtGui.QColor(211, 224, 255)) brush.setStyle(QtCore.Qt.SolidPattern) palette.setBrush(QtGui.QPalette.Active, QtGui.QPalette.Midlight, brush) brush = QtGui.QBrush(QtGui.QColor(84, 97, 127)) brush.setStyle(QtCore.Qt.SolidPattern) palette.setBrush(QtGui.QPalette.Active, QtGui.QPalette.Dark, brush) brush = QtGui.QBrush(QtGui.QColor(112, 129, 170)) brush.setStyle(QtCore.Qt.SolidPattern) palette.setBrush(QtGui.QPalette.Active, QtGui.QPalette.Mid, brush) brush = QtGui.QBrush(QtGui.QColor(0, 0, 0)) brush.setStyle(QtCore.Qt.SolidPattern) palette.setBrush(QtGui.QPalette.Active, QtGui.QPalette.Text, brush) brush = QtGui.QBrush(QtGui.QColor(255, 255, 255)) brush.setStyle(QtCore.Qt.SolidPattern) palette.setBrush(QtGui.QPalette.Active, QtGui.QPalette.BrightText, brush) brush = QtGui.QBrush(QtGui.QColor(0, 0, 0)) brush.setStyle(QtCore.Qt.SolidPattern) palette.setBrush(QtGui.QPalette.Active, QtGui.QPalette.ButtonText, brush) brush = QtGui.QBrush(QtGui.QColor(255, 255, 255)) brush.setStyle(QtCore.Qt.SolidPattern) palette.setBrush(QtGui.QPalette.Active, QtGui.QPalette.Base, brush) brush = QtGui.QBrush(QtGui.QColor(168, 194, 255)) brush.setStyle(QtCore.Qt.SolidPattern) palette.setBrush(QtGui.QPalette.Active, QtGui.QPalette.Window, brush) brush = QtGui.QBrush(QtGui.QColor(0, 0, 0)) brush.setStyle(QtCore.Qt.SolidPattern) palette.setBrush(QtGui.QPalette.Active, QtGui.QPalette.Shadow, brush) brush = QtGui.QBrush(QtGui.QColor(211, 224, 255)) brush.setStyle(QtCore.Qt.SolidPattern) palette.setBrush(QtGui.QPalette.Active, QtGui.QPalette.AlternateBase, brush) brush = QtGui.QBrush(QtGui.QColor(255, 255, 220)) brush.setStyle(QtCore.Qt.SolidPattern) palette.setBrush(QtGui.QPalette.Active, QtGui.QPalette.ToolTipBase, brush) brush = QtGui.QBrush(QtGui.QColor(0, 0, 0)) brush.setStyle(QtCore.Qt.SolidPattern) palette.setBrush(QtGui.QPalette.Active, QtGui.QPalette.ToolTipText, brush) brush = QtGui.QBrush(QtGui.QColor(0, 0, 0)) brush.setStyle(QtCore.Qt.SolidPattern) palette.setBrush(QtGui.QPalette.Inactive, QtGui.QPalette.WindowText, brush) brush = QtGui.QBrush(QtGui.QColor(168, 194, 255)) brush.setStyle(QtCore.Qt.SolidPattern) palette.setBrush(QtGui.QPalette.Inactive, QtGui.QPalette.Button, brush) brush = QtGui.QBrush(QtGui.QColor(255, 255, 255)) brush.setStyle(QtCore.Qt.SolidPattern) palette.setBrush(QtGui.QPalette.Inactive, QtGui.QPalette.Light, brush) brush = QtGui.QBrush(QtGui.QColor(211, 224, 255)) brush.setStyle(QtCore.Qt.SolidPattern) palette.setBrush(QtGui.QPalette.Inactive, QtGui.QPalette.Midlight, brush) brush = QtGui.QBrush(QtGui.QColor(84, 97, 127)) brush.setStyle(QtCore.Qt.SolidPattern) palette.setBrush(QtGui.QPalette.Inactive, QtGui.QPalette.Dark, brush) brush = QtGui.QBrush(QtGui.QColor(112, 129, 170)) brush.setStyle(QtCore.Qt.SolidPattern) palette.setBrush(QtGui.QPalette.Inactive, QtGui.QPalette.Mid, brush) brush = QtGui.QBrush(QtGui.QColor(0, 0, 0)) brush.setStyle(QtCore.Qt.SolidPattern) palette.setBrush(QtGui.QPalette.Inactive, QtGui.QPalette.Text, brush) brush = QtGui.QBrush(QtGui.QColor(255, 255, 255)) brush.setStyle(QtCore.Qt.SolidPattern) palette.setBrush(QtGui.QPalette.Inactive, QtGui.QPalette.BrightText, brush) brush = QtGui.QBrush(QtGui.QColor(0, 0, 0)) brush.setStyle(QtCore.Qt.SolidPattern) palette.setBrush(QtGui.QPalette.Inactive, QtGui.QPalette.ButtonText, brush) brush = QtGui.QBrush(QtGui.QColor(255, 255, 255)) brush.setStyle(QtCore.Qt.SolidPattern) palette.setBrush(QtGui.QPalette.Inactive, QtGui.QPalette.Base, brush) brush = QtGui.QBrush(QtGui.QColor(168, 194, 255)) brush.setStyle(QtCore.Qt.SolidPattern) palette.setBrush(QtGui.QPalette.Inactive, QtGui.QPalette.Window, brush) brush = QtGui.QBrush(QtGui.QColor(0, 0, 0)) brush.setStyle(QtCore.Qt.SolidPattern) palette.setBrush(QtGui.QPalette.Inactive, QtGui.QPalette.Shadow, brush) brush = QtGui.QBrush(QtGui.QColor(211, 224, 255)) brush.setStyle(QtCore.Qt.SolidPattern) palette.setBrush(QtGui.QPalette.Inactive, QtGui.QPalette.AlternateBase, brush) brush = QtGui.QBrush(QtGui.QColor(255, 255, 220)) brush.setStyle(QtCore.Qt.SolidPattern) palette.setBrush(QtGui.QPalette.Inactive, QtGui.QPalette.ToolTipBase, brush) brush = QtGui.QBrush(QtGui.QColor(0, 0, 0)) brush.setStyle(QtCore.Qt.SolidPattern) palette.setBrush(QtGui.QPalette.Inactive, QtGui.QPalette.ToolTipText, brush) brush = QtGui.QBrush(QtGui.QColor(84, 97, 127)) brush.setStyle(QtCore.Qt.SolidPattern) palette.setBrush(QtGui.QPalette.Disabled, QtGui.QPalette.WindowText, brush) brush = QtGui.QBrush(QtGui.QColor(168, 194, 255)) brush.setStyle(QtCore.Qt.SolidPattern) palette.setBrush(QtGui.QPalette.Disabled, QtGui.QPalette.Button, brush) brush = QtGui.QBrush(QtGui.QColor(255, 255, 255)) brush.setStyle(QtCore.Qt.SolidPattern) palette.setBrush(QtGui.QPalette.Disabled, QtGui.QPalette.Light, brush) brush = QtGui.QBrush(QtGui.QColor(211, 224, 255)) brush.setStyle(QtCore.Qt.SolidPattern) palette.setBrush(QtGui.QPalette.Disabled, QtGui.QPalette.Midlight, brush) brush = QtGui.QBrush(QtGui.QColor(84, 97, 127)) brush.setStyle(QtCore.Qt.SolidPattern) palette.setBrush(QtGui.QPalette.Disabled, QtGui.QPalette.Dark, brush) brush = QtGui.QBrush(QtGui.QColor(112, 129, 170)) brush.setStyle(QtCore.Qt.SolidPattern) palette.setBrush(QtGui.QPalette.Disabled, QtGui.QPalette.Mid, brush) brush = QtGui.QBrush(QtGui.QColor(84, 97, 127)) brush.setStyle(QtCore.Qt.SolidPattern) palette.setBrush(QtGui.QPalette.Disabled, QtGui.QPalette.Text, brush) brush = QtGui.QBrush(QtGui.QColor(255, 255, 255)) brush.setStyle(QtCore.Qt.SolidPattern) palette.setBrush(QtGui.QPalette.Disabled, QtGui.QPalette.BrightText, brush) brush = QtGui.QBrush(QtGui.QColor(84, 97, 127)) brush.setStyle(QtCore.Qt.SolidPattern) palette.setBrush(QtGui.QPalette.Disabled, QtGui.QPalette.ButtonText, brush) brush = QtGui.QBrush(QtGui.QColor(168, 194, 255)) brush.setStyle(QtCore.Qt.SolidPattern) palette.setBrush(QtGui.QPalette.Disabled, QtGui.QPalette.Base, brush) brush = QtGui.QBrush(QtGui.QColor(168, 194, 255)) brush.setStyle(QtCore.Qt.SolidPattern) palette.setBrush(QtGui.QPalette.Disabled, QtGui.QPalette.Window, brush) brush = QtGui.QBrush(QtGui.QColor(0, 0, 0)) brush.setStyle(QtCore.Qt.SolidPattern) palette.setBrush(QtGui.QPalette.Disabled, QtGui.QPalette.Shadow, brush) brush = QtGui.QBrush(QtGui.QColor(168, 194, 255)) brush.setStyle(QtCore.Qt.SolidPattern) palette.setBrush(QtGui.QPalette.Disabled, QtGui.QPalette.AlternateBase, brush) brush = QtGui.QBrush(QtGui.QColor(255, 255, 220)) brush.setStyle(QtCore.Qt.SolidPattern) palette.setBrush(QtGui.QPalette.Disabled, QtGui.QPalette.ToolTipBase, brush) brush = QtGui.QBrush(QtGui.QColor(0, 0, 0)) brush.setStyle(QtCore.Qt.SolidPattern) palette.setBrush(QtGui.QPalette.Disabled, QtGui.QPalette.ToolTipText, brush) self.groupBox_4.setPalette(palette) self.groupBox_4.setObjectName("groupBox_4") self.verticalLayout = QtGui.QVBoxLayout(self.groupBox_4) self.verticalLayout.setObjectName("verticalLayout") self.formLayout = QtGui.QFormLayout() self.formLayout.setFieldGrowthPolicy( QtGui.QFormLayout.AllNonFixedFieldsGrow) self.formLayout.setObjectName("formLayout") self.label = QtGui.QLabel(self.groupBox_4) self.label.setObjectName("label") self.formLayout.setWidget(0, QtGui.QFormLayout.LabelRole, self.label) self.experimentNumberSpin = QtGui.QSpinBox(self.groupBox_4) self.experimentNumberSpin.setMaximumSize(QtCore.QSize(50, 16777215)) self.experimentNumberSpin.setMaximum(9999) self.experimentNumberSpin.setProperty("value", 1) self.experimentNumberSpin.setObjectName("experimentNumberSpin") self.formLayout.setWidget(0, QtGui.QFormLayout.FieldRole, self.experimentNumberSpin) self.verticalLayout.addLayout(self.formLayout) self.label_2 = QtGui.QLabel(self.groupBox_4) self.label_2.setObjectName("label_2") self.verticalLayout.addWidget(self.label_2) self.blockList = QtGui.QListWidget(self.groupBox_4) self.blockList.setObjectName("blockList") self.verticalLayout.addWidget(self.blockList) self.enableScriptedActionsCheck = QtGui.QCheckBox(self.groupBox_4) self.enableScriptedActionsCheck.setObjectName( "enableScriptedActionsCheck") self.verticalLayout.addWidget(self.enableScriptedActionsCheck) self.horizontalLayout_4.addWidget(self.groupBox_4) self.verticalLayout_3.addLayout(self.horizontalLayout_4) MainWindow.setCentralWidget(self.centralwidget) self.menubar = QtGui.QMenuBar(MainWindow) self.menubar.setGeometry(QtCore.QRect(0, 0, 668, 21)) self.menubar.setObjectName("menubar") self.menuFile = QtGui.QMenu(self.menubar) self.menuFile.setObjectName("menuFile") self.menuHelp = QtGui.QMenu(self.menubar) self.menuHelp.setObjectName("menuHelp") MainWindow.setMenuBar(self.menubar) self.statusbar = QtGui.QStatusBar(MainWindow) self.statusbar.setObjectName("statusbar") MainWindow.setStatusBar(self.statusbar) self.actionLoadConfig = QtGui.QAction(MainWindow) self.actionLoadConfig.setObjectName("actionLoadConfig") self.actionQuit = QtGui.QAction(MainWindow) self.actionQuit.setObjectName("actionQuit") self.actionAbout = QtGui.QAction(MainWindow) self.actionAbout.setObjectName("actionAbout") self.actionComing_Soon = QtGui.QAction(MainWindow) self.actionComing_Soon.setObjectName("actionComing_Soon") self.menuFile.addAction(self.actionLoadConfig) self.menuFile.addAction(self.actionQuit) self.menuHelp.addAction(self.actionComing_Soon) self.menubar.addAction(self.menuFile.menuAction()) self.menubar.addAction(self.menuHelp.menuAction()) self.retranslateUi(MainWindow) QtCore.QMetaObject.connectSlotsByName(MainWindow)
def paint(self, painter, option, index): item_rect = option.rect.adjusted(1, 1, -1, 0) frame_rect = option.rect.adjusted(0, 0, -1, 0) name_rect = option.rect.adjusted(self.margin, self.margin, -self.margin, 0) name_rect.setHeight(20) type_rect = option.rect.adjusted(self.margin, self.margin + 20 + self.margin, -self.margin, -self.margin) if index.data(model.scene_stat) == "generating": painter.fillRect(item_rect, QtGui.QColor(255, 180, 100, 255)) elif index.data(model.scene_stat) == "done": painter.fillRect(item_rect, QtGui.QColor(100, 255, 100, 255)) elif index.data(model.scene_stat) == "failed": painter.fillRect(item_rect, QtGui.QColor(255, 100, 100, 255)) else: painter.fillRect(item_rect, QtGui.QColor(240, 240, 240, 255)) if option.state & QtGui.QStyle.State_Selected: g_selected = QtGui.QLinearGradient( 0, item_rect.y(), 0, item_rect.y() + item_rect.height()) g_selected.setColorAt(0.0, QtGui.QColor(100, 100, 100, 200)) g_selected.setColorAt(1.0 / item_rect.height(), QtGui.QColor(100, 100, 100, 30)) g_selected.setColorAt(1.0 - 1.0 / item_rect.height(), QtGui.QColor(100, 100, 100, 20)) g_selected.setColorAt(1.0, QtGui.QColor(255, 255, 255, 0)) g_selected.setSpread(QtGui.QGradient.ReflectSpread) painter.fillRect(item_rect, g_selected) elif option.state & QtGui.QStyle.State_MouseOver: g_hover = QtGui.QLinearGradient(0, item_rect.y(), 0, item_rect.y() + item_rect.height()) g_hover.setColorAt(0.0, QtGui.QColor(255, 255, 255, 200)) g_hover.setColorAt(1.0 / item_rect.height(), QtGui.QColor(255, 255, 255, 50)) g_hover.setColorAt(1.0 - 1.0 / item_rect.height(), QtGui.QColor(255, 255, 255, 0)) g_hover.setColorAt(1.0, QtGui.QColor(100, 100, 100, 200)) painter.fillRect(item_rect, g_hover) painter.save() painter.setPen(QtGui.QPen(QtGui.QColor(100, 100, 100, 255))) painter.drawRect(frame_rect) painter.setPen(QtGui.QPen(QtGui.QColor(0, 0, 0, 255))) painter.setFont(QtGui.QFont(u"微软雅黑", 11, QtGui.QFont.Normal)) painter.drawText(name_rect, QtCore.Qt.AlignBottom, index.data(model.scene_name)) status_map = { "wait": u"就绪", "generating": u"正在生成...", "done": u"已完成", "failed": u"失败" } painter.setFont(QtGui.QFont(u"微软雅黑", 10, QtGui.QFont.Normal)) painter.setPen(QtGui.QPen(QtGui.QColor(100, 100, 100, 255))) painter.drawText(type_rect, QtCore.Qt.AlignBottom, status_map.get(index.data(model.scene_stat), u"")) painter.restore()
class BaseLayout(object): buttonSpacing = 1 buttonMargins = (0, 0, 0, 0) runEditHeight = 60 errorColour = QtGui.QColor(255, 160, 160) # pink warnColour = QtGui.QColor(255, 255, 160) # yellow activePassColour = QtGui.QColor(255, 255, 208) # light yellow semiActivePassColour = QtGui.QColor( 255, 240, 215 ) # light peach (actually this is used for collisions which are also active passes) slotColours = { 'default': QtGui.QColor(0, 0, 0, 32), # gray, semi-transparent 'input': QtGui.QColor(255, 255, 0, 32), # yellow, semi-transparent 'output': QtGui.QColor(0, 170, 0, 32), # green, semi-transparent 'inAndOut': QtGui.QColor(100, 160, 0, 32), # yellow-green, semi-transparent 'failed': QtGui.QColor(0, 0, 0, 32), # gray, semi-transparent 'exclude': QtGui.QColor(255, 160, 0, 60), # orange, semi-transparent } posdotColour = QtGui.QColor(0, 160, 0, 192) # green posdotShiftColour = QtGui.QColor(0, 0, 192, 192) # blue initHSplitWidth = 300 initWinSize = (1000, 700) noMenuIcons = False
newItems = parentItem.fetchAmount() self.beginInsertRows(parent, curItems, curItems + newItems - 1) parentItem.fetchMore() self.endInsertRows() app = QtGui.QApplication.instance() if not app: app = QtGui.QApplication([]) # Tree Example: # Tree View -> Data Proxy -> Filter Proxy -> Tree Model tree = FilteredTree() tree.push(ExampleDataTreeModel(["Tree Header {0}".format(i) for i in range(ExampleDataTreeModel.TotalColumns)])) tree.push(TreeColumnFilterProxyModel()) tree.proxy.setFilterKeyColumn(-1) tree.push(ColumnFilterDataProxyModel()) tree.proxy.setFilterData(QtCore.Qt.BackgroundRole, QtGui.QBrush(QtGui.QColor(224,91,49))) #orange tree.proxy.setFilterData(QtCore.Qt.ForegroundRole, QtGui.QBrush( QtGui.QColor(0,0,0) )) #not orange tree.proxy.setFilterKeyColumn(-1) tree.label = "Example Tree" tree.immediate = False tree.show() # List Example: # ListTree View -> Filter Proxy -> Filter Model list = FilteredList() list.push(ExampleDataListModel(["List Header"])) list.push(ColumnFilterProxyModel()) list.label = "Example List" list.reloadable = True list.show()