def setupUI(self): vbox = QtGui.QVBoxLayout() vbox.setMargin(0) logName_label = QtGui.QLabel() logName_label.setAlignment(QtCore.Qt.AlignLeft | QtCore.Qt.AlignTop) logName_label.setText( self.domainTrackData.getTypeDisplayUnitReferenceTitle()) #logNameWidth = logName_label.geometry().width() #logNameLabelHeight = logName_label.geometry().height() vbox.addWidget(logName_label) vbox.addStretch(1) self.setLayout(vbox) #self.setFixedWidth(self.widget_width) #set colours pal = QtGui.QPalette() role = QtGui.QPalette.Background backgroundQColor = ImageUtils.rgbToQColor( self.wellPlotData.label_background_rgb) #self.setStyleSheet("QFrame { background-color: %s }" % "Red") role = QtGui.QPalette.Foreground foregroundQColor = ImageUtils.rgbToQColor( self.wellPlotData.label_foreground_rgb) pal.setColor(role, foregroundQColor) self.setPalette(pal)
def saveDataState(self, wellPlotData, wellPlotStyleWidget): if wellPlotStyleWidget.plotTitleOnCheckBox.isChecked(): wellPlotData.title_on = True else: wellPlotData.title_on = False wellPlotData.title = wellPlotStyleWidget.plotTitleLineEdit.text() r, g, b, a = QColor(wellPlotStyleWidget.trackBackgroundColorPushButton. color()).getRgb() rgbString = ImageUtils.rgbToString(r, g, b) wellPlotData.plot_background_rgb = rgbString wellPlotData.plot_background_alpha = wellPlotStyleWidget.trackBackgroundOpacitySpinBox.value( ) r, g, b, a = QColor(wellPlotStyleWidget.labelBackgroundColorPushButton. color()).getRgb() rgbString = ImageUtils.rgbToString(r, g, b) wellPlotData.label_background_rgb = rgbString wellPlotData.label_background_alpha = wellPlotStyleWidget.labelBackgroundOpacitySpinBox.value( ) r, g, b, a = QColor(wellPlotStyleWidget.labelForegroundColorPushButton. color()).getRgb() rgbString = ImageUtils.rgbToString(r, g, b) wellPlotData.label_foreground_rgb = rgbString wellPlotData.label_foreground_alpha = wellPlotStyleWidget.labelForegroundOpacitySpinBox.value( ) if wellPlotStyleWidget.singleRowLabelsCheckBox.isChecked(): wellPlotData.single_row_header_labels = True else: wellPlotData.single_row_header_labels = False
def createPlotHeader(self, track, wellPlotData): logger.debug(">>createPlotHeader() ") assert track != None assert wellPlotData != None logTrackData = track.data(Qt.UserRole) titleFrame = QFrame() vLayout = QVBoxLayout() vbox = QWidget() label_bg_rgb = self.wellPlotData.label_background_rgb label_bg_alpha = self.wellPlotData.label_background_alpha label_fg_rgb = self.wellPlotData.label_foreground_rgb label_fg_alpha = self.wellPlotData.label_foreground_alpha (fr, fg, fb, falpha) = ImageUtils.rbgaTointValues(label_fg_rgb, label_fg_alpha) (br, bg, bb, balpha) = ImageUtils.rbgaTointValues(label_bg_rgb, label_bg_alpha) #in case logs=0, as we reference .geometry() headerWidget = QWidget() if len(logTrackData.getLogs()) > 0: layout = QVBoxLayout() for log in logTrackData.getLogs(): headerWidget = LogHeaderLabel(log, track, wellPlotData) layout.addWidget(headerWidget) topSpacer = QtGui.QWidget() topSpacer.setSizePolicy(QtGui.QSizePolicy.Minimum, QtGui.QSizePolicy.Expanding) layout.addWidget(topSpacer) vbox.setLayout(layout) vLayout.addWidget(vbox) titleFrame.setLayout(vLayout) titleFrame.setFrameStyle(QtGui.QFrame.StyledPanel | QtGui.QFrame.Raised) trackGeom = track.geometry() titleFrame.setMinimumWidth(trackGeom.width()) titleFrame.setGeometry(trackGeom.x(), trackGeom.y(), trackGeom.width(), headerWidget.geometry().height()) logger.debug( "--createPlotHeader() trackGeom.width(): {0} headerWidget.geometry().height(): {1}" .format(trackGeom.width(), headerWidget.geometry().height())) logger.debug( "--createPlotHeader() titleFrame.width(): {0} titleFrame.geometry().height(): {1}" .format(titleFrame.width(), titleFrame.geometry().height())) return titleFrame
def paintEvent(self, event): MARGIN_PIXELS = 4 painter = QPainter() (r, g, b, alpha) = ImageUtils.rbgaTointValues(self.log.rgb, self.log.alpha) lineColour = QColor(r, g, b, alpha) assert lineColour != None assert self.log.line_style != None lineStyle = WidgetUtils.getQtPenStyle(self.log.line_style) assert lineStyle != None assert self.log.line_width != None lineWidth = NumberUtils.floatToIntDefault(self.log.line_width, 1) pen = QPen(lineColour, lineWidth, lineStyle) painter.begin(self) painter.setPen(pen) labelMargin = self.logName_label.margin() yLevel = self.logName_label.rect().bottomLeft().y() xStart = labelMargin xStop = self.track.geometry().width() - labelMargin #line is relative to widget not screen painter.drawLine(xStart, yLevel, xStop, yLevel) painter.end()
def paintEvent( self, event ) : MARGIN_PIXELS = 4 painter = QPainter() (r, g, b, alpha) = ImageUtils.rbgaTointValues(self.log.rgb, self.log.alpha) lineColour = QColor(r, g, b, alpha) assert lineColour != None assert self.log.line_style != None lineStyle = WidgetUtils.getQtPenStyle(self.log.line_style) assert lineStyle != None assert self.log.line_width != None lineWidth = NumberUtils.floatToIntDefault(self.log.line_width, 1) pen = QPen(lineColour, lineWidth, lineStyle) painter.begin(self) painter.setPen(pen) yLevel = self.logName_label.rect().bottomLeft().y() xStart = self.xpix[0] xStop = self.xpix[1] #horizontal line #logger.debug("--paintEvent() r: {0}, g: {1}, b: {2}, a: {3}, name{4}".format(r, g, b, alpha, self.log.name)) #logger.debug("--paintEvent() xStart: {0}, yLevel: {1}, xStop: {2}, yLevel: {3}".format(xStart, yLevel, xStop, yLevel)) painter.drawLine( xStart, yLevel, xStop, yLevel ) painter.end()
def getHeaderBox(self, width): logger.debug(">>getHeaderBox() width: "+str(width)) headingText_widget = QtGui.QWidget() horizontalLayout = QtGui.QHBoxLayout() horizontalLayout.setMargin(0) ''' logValLeft_label = QtGui.QLabel() logValLeft_label.setText(str(labelProperties.leftLogLimit)) horizontalLayout.addWidget(logValLeft_label) spacerItem = QtGui.QSpacerItem(width/2, 10, QtGui.QSizePolicy.Expanding, QtGui.QSizePolicy.Minimum) horizontalLayout.addItem(spacerItem) logName_label = QtGui.QLabel() logName_label.setText(str(labelProperties.logName)) horizontalLayout.addWidget(logName_label) spacerItem1 = QtGui.QSpacerItem(width/2, 10, QtGui.QSizePolicy.Expanding, QtGui.QSizePolicy.Minimum) horizontalLayout.addItem(spacerItem1) logValRight_label = QtGui.QLabel() logValRight_label.setText(str(labelProperties.rightLogLimit)) horizontalLayout.addWidget(logValRight_label) ''' headingText_widget.setLayout(horizontalLayout) headingText_widget.setFixedWidth(width) #as using QColor should'nt need this try block, can remove if working OK try: pal=QtGui.QPalette() role = QtGui.QPalette.Background backgroundQColor = ImageUtils.rgbToQColor(self.logPlotData.label_background_rgb) #colour = QtGui.QColor(labelProperties.backgroundColour) pal.setColor(role, backgroundQColor) role = QtGui.QPalette.Foreground foregroundQColor = ImageUtils.rgbToQColor(self.logPlotData.label_foreground_rgb) pal.setColor(role, foregroundQColor) headingText_widget.setPalette(pal) except AttributeError as ex: logger.error(str(ex)) if AppSettings.isDebugMode: raise AttributeError return headingText_widget
def setupUI(self): if self.wellPlotData.single_row_header_labels: hbox = self.createSingleRowLabelBox() self.setLayout(hbox) else: vbox = self.createDoubleRowLabelBox() self.setLayout(vbox) self.setFixedWidth(self.track.geometry().width()) #set colours pal = QtGui.QPalette() role = QtGui.QPalette.Background backgroundQColor = ImageUtils.rgbToQColor( self.wellPlotData.label_background_rgb) pal.setColor(role, backgroundQColor) role = QtGui.QPalette.Foreground foregroundQColor = ImageUtils.rgbToQColor( self.wellPlotData.label_foreground_rgb) pal.setColor(role, foregroundQColor) self.setPalette(pal)
def createPlotHeader(self, subPlotData, xpix, logPlotData): logger.debug(">>createPlotHeader() ") vbox = QWidget() #logPlotPreferencesLogic = WellPlotPreferencesLogic() #logPlotDefaults = logPlotPreferencesLogic.getLogPlotPreferences() label_bg_rgb = self.logPlotData.label_background_rgb label_bg_alpha = self.logPlotData.label_background_alpha label_fg_rgb = self.logPlotData.label_foreground_rgb label_fg_alpha = self.logPlotData.label_foreground_alpha (fr, fg, fb, falpha) = ImageUtils.rbgaTointValues(label_fg_rgb, label_fg_alpha) (br, bg, bb, balpha) = ImageUtils.rbgaTointValues(label_bg_rgb, label_bg_alpha) ''' labelProps.label_fg_color = QColor(fr, fg, fb, falpha) labelProps.label_bg_color = QColor(br, bg, bb, balpha) labelProps.subPlotData = subPlotData labelProps.xpix = xpix labelProps.expandedLabel = logPlotDefaults.expanded_header_labels ''' if subPlotData != None and len(subPlotData.getLogs())>0: layout = QVBoxLayout() topSpacer = QtGui.QWidget() topSpacer.setSizePolicy(QtGui.QSizePolicy.Minimum, QtGui.QSizePolicy.Expanding) layout.addWidget(topSpacer) for log in subPlotData.getLogs(): canvasFig = self.mainPlot.figure #labelProps.canvas_width, labelProps.canvas_height = canvasFig.canvas.get_width_height() headerWidget = LogHeaderLabel(subPlotData, log, xpix, logPlotData) layout.addWidget(headerWidget) vbox.setLayout(layout) plot_width = xpix[1] - xpix[0] logger.debug("--createPlotHeader() xpix 1: "+str(xpix[1])+" xpix 0: "+str(xpix[0])+" plot_width "+str(plot_width)) vbox.setFixedWidth(plot_width) return vbox
def generatePlot(self, logTrackData, log, xData, yData): #pw = pg.PlotWidget(name='Plot1') ## giving the plots names allows us to link their axes together self.getAxis('left').setStyle(tickTextOffset=self.TICK_TEXT_OFFSET, showValues=True) self.getAxis('bottom').setStyle(showValues=False) #store data for header to retrieve self.setData(Qt.UserRole, logTrackData) #see http://stackoverflow.com/questions/5036700/how-can-you-dynamically-create-variables-in-python-via-a-while-loop self.show() firstLogId = logTrackData.getLogs()[0] log = logTrackData.getLogs()[0] #note PlotItem is coming from parent #hide the A button see https://groups.google.com/forum/#!topic/pyqtgraph/5cc0k6TG89k self.plotItem.hideButtons() self.plotItem.setRange(xRange=(log.log_plot_left, log.log_plot_right), padding=0, disableAutoRange=True) plt = self.plotItem.plot(y=yData, x=xData) #temp set alpga to semi tranparent rgbaColor = ImageUtils.rbgaToQColor(log.rgb, 100) plt.setPen(rgbaColor) self.invertY() pixelWidth = WellPlotUtils.convertmmToDPI(logTrackData.track_width) self.setFixedWidth(pixelWidth) self.setSizePolicy(QtGui.QSizePolicy.Maximum, QtGui.QSizePolicy.Expanding) #self.setLimits(yMin = 0, yMax=4000) #self.proxy = pg.SignalProxy(self.plotItem.scene().sigMouseMoved, rateLimit=60, slot=self.mouseMoveEvent) #self.plotItem.sigRangeChanged.connect(self.updateRegion) #region self._region = pg.LinearRegionItem( orientation=pg.LinearRegionItem.Horizontal) #The Z value decides the stacking order of sibling (neighboring) items. High Z = on top self._region.setZValue(10) self.setInitialRange() self.plotItem.addItem(self._region) #send signal to slots that range has been set #if if remove finished signal need to enable this instead #self.updateOnRegionChange() self.updateOnRegionChangeFinished() self.connectSlots()
def setupSubplots(self, logPlotData): assert len(logPlotData.sub_plots) > 1 assert len(logPlotData.depth_sub_plots) > 0 firstPlotDTO = ArrayUtils.getFirstItem(logPlotData.sub_plots) firstLog = ArrayUtils.getFirstItem(firstPlotDTO.getLogs()) #start at 2 as first plot already plotted for i, subPlotData in enumerate(logPlotData.sub_plots): #not best way to do this if i > 0: #(234) means "2x3 grid, 4th subplot". ax1 = self.figure.add_subplot(1, len(logPlotData.sub_plots), i + 1, sharey=self.axes) for log in subPlotData.getLogs(): mpl_rgba = ImageUtils.rgbaToMPLrgba(log.rgb, log.alpha) logger.debug("--setupSubplots() log.rgb:{0}".format( log.rgb)) ax1.plot(log.log_data, log.z_measure_data, color=mpl_rgba) ax1.set_xlim([log.log_plot_left, log.log_plot_right]) #ax1.set_xlabel(logList[v].name) ax1.get_xaxis().set_visible(False) ax1.get_yaxis().set_visible(False) ax1.xaxis.tick_top() xTicks = tic.MaxNLocator(2) ax1.xaxis.set_major_locator(xTicks) max = logPlotData.depth_sub_plots[0].depthAxisPlotMax min = logPlotData.depth_sub_plots[0].depthAxisPlotMin #need to set this otherwide axis is different to main depth axis ax1.set_ylim(max, min) #turn on grid if logPlotData.grid_on: ax1.xaxis.grid(True, 'minor') ax1.yaxis.grid(True, 'minor') ax1.xaxis.grid(True, 'major', linewidth=2) ax1.yaxis.grid(True, 'major', linewidth=2) #ax1.yaxis.grid(color= subPlotData.gridColor, linestyle= subPlotData.gridLineStyle) if logPlotData.display_depth_axes == False: #turn off y axis labels ax1.get_yaxis().set_visible(False)
def saveGridStyle(self, wellPlotData, trackStyleWidget): showGrid = False if trackStyleWidget.applyGridToAllCheckBox.isChecked(): if trackStyleWidget.gridDisplayedCheckBox.isChecked(): showGrid = True r, g, b, a = QColor( trackStyleWidget.gridColorPushButton.color()).getRgb() rgbStr = ImageUtils.rgbToString(r, g, b) gridOpacity = trackStyleWidget.gridOpacitySpinBox.value() gridLineStyle = trackStyleWidget.gridLineStyleComboBox.currentText( ) linearVerticalDivisions = trackStyleWidget.linearGridVerticalDivisionsSpinBox.value( ) logVerticalDivisions = trackStyleWidget.logarithmicGridVerticalDivisionsSpinBox.value( ) for track in wellPlotData.getLogTrackDatas(): if (track.plot_index != -1): track.grid_rgb = rgbStr track.grid_alpha = str(a) track.grid_line_style = gridLineStyle
def populatePlotTab(self): logger.debug(">>populatePlotTab()") titleOnCheckState = WidgetUtils.getQtCheckObject( self._wellPlotData.title_on) self.plotTitleOnCheckBox.setCheckState(titleOnCheckState) self.plotTitleOnCheckBox.stateChanged.connect(self.styleChanged) self.plotTitleLineEdit.setText(self._wellPlotData.title) self.plotTitleLineEdit.textChanged.connect(self.styleChanged) self.plotPrintDPILineEdit.setText(str(self._wellPlotData.dpi)) self.plotPrintDPILineEdit.textChanged.connect(self.styleChanged) intValidator = QtGui.QIntValidator() self.plotPrintDPILineEdit.setValidator(intValidator) #not enabled for this version self.plotTitleOnCheckBox.setEnabled(False) self.plotTitleLineEdit.setEnabled(False) self.plotPrintDPILineEdit.setEnabled(False) trackBackButtonQColor = ImageUtils.rbgToQColor( self._wellPlotData.plot_background_rgb) trackBackColorButton = QColorButton() trackBackColorButton.setColor(trackBackColorButton) self.trackBackgroundColorPushButton = trackBackColorButton self.trackBackgroundColorPushButton.clicked.connect(self.styleChanged) plotBackgroundAlpha = NumberUtils.stringToInt( self._wellPlotData.plot_background_alpha) self.trackBackgroundOpacitySpinBox.setValue(plotBackgroundAlpha) self.trackBackgroundOpacitySpinBox.valueChanged.connect( self.styleChanged) gridOnCheckState = WidgetUtils.getQtCheckObject( self._wellPlotData.grid_on) self.gridOnCheckBox.setCheckState(gridOnCheckState) self.gridOnCheckBox.stateChanged.connect(self.styleChanged) buttonQColor = ImageUtils.rbgToQColor(self._wellPlotData.grid_rgb) qColorButton = QColorButton() qColorButton.setColor(buttonQColor) self.gridColorPushButton = qColorButton self.gridColorPushButton.clicked.connect(self.styleChanged) gridAlpha = NumberUtils.stringToInt(self._wellPlotData.grid_alpha) self.gridOpacitySpinBox.setValue(gridAlpha) self.gridOpacitySpinBox.valueChanged.connect(self.styleChanged) index = self.gridStyleComboBox.findText( self._wellPlotData.grid_line_style, QtCore.Qt.MatchFixedString) if index >= 0: self.gridStyleComboBox.setCurrentIndex(index) self.gridStyleComboBox.currentIndexChanged.connect(self.styleChanged) self.gridVerticalDivSpinBox.setValue( self._wellPlotData.grid_vertical_divisions) self.gridVerticalDivSpinBox.valueChanged.connect(self.styleChanged) expandedCheckState = WidgetUtils.getQtCheckObject( self._wellPlotData.single_row_header_labels) self.labelsExpandedCheckBox.setCheckState(expandedCheckState) self.labelsExpandedCheckBox.stateChanged.connect(self.styleChanged) labelBackButtonQColor = ImageUtils.rbgToQColor( self._wellPlotData.label_background_rgb) labelBackColorButton = QColorButton() labelBackColorButton.setColor(labelBackButtonQColor) self.labelBackgroundColorPushButton = labelBackColorButton self.labelBackgroundColorPushButton.clicked.connect(self.styleChanged) labelBackgroundAlpha = NumberUtils.stringToInt( self._wellPlotData.label_background_alpha) self.labelBackgroundOpacitySpinBox.setValue(labelBackgroundAlpha) self.labelBackgroundOpacitySpinBox.valueChanged.connect( self.styleChanged) labelForegroundRGB = NumberUtils.stringToInt( self._wellPlotData.label_foreground_rgb) labelForeButtonQColor = ImageUtils.rbgToQColor(labelForegroundRGB) labelForeColorButton = QColorButton() labelForeColorButton.setColor(labelForeButtonQColor) self.labelForegroundColorPushButton = labelForeColorButton self.labelForegroundColorPushButton.clicked.connect(self.styleChanged) labelForegroundAlpha = NumberUtils.stringToInt( self._wellPlotData.label_foreground_alpha) self.labelForegroundOpacitySpinBox.setValue(labelForegroundAlpha) self.labelForegroundOpacitySpinBox.valueChanged.connect( self.styleChanged)
def populateCurveTable(self): logger.debug(">>populateCurveTable()") try: self.curveTableWidget.itemChanged.disconnect(self.styleChanged) except TypeError as ex: logger.debug(str(ex)) headers = LogPlotConstants.LOG_PLOT_CURVE_STYLE_HEADERS numberOfColumns = len(headers) self.curveTableWidget.clear() self.curveTableWidget.setSortingEnabled(False) logCount = 0 countIds = [] for plot in self._wellPlotData.getLogTrackDatas(): for log in plot.getLogs(): #only want unique curve attributes if log.id not in countIds: logCount += 1 countIds.append(log.id) self.curveTableWidget.setRowCount(logCount) self.curveTableWidget.setColumnCount(numberOfColumns) self.curveTableWidget.setHorizontalHeaderLabels(headers) #only want unique curve attributes ids = [] for i, plot in enumerate(self._wellPlotData.getLogTrackDatas()): j = 0 for log in plot.getLogs(): if log.id not in ids: #add one so starts at 1 not zero? nameLineEdit = QtGui.QLineEdit(log.name) typeLineEdit = QtGui.QLineEdit(log.log_type_name) logType = LogType.getLogType(log.log_type_name) unit = logType.getUnit() unitsLineEdit = QtGui.QLineEdit(unit.getName()) trackLineEdit = QtGui.QLineEdit(str(plot.plot_index)) leftScaleLineEdit = QtGui.QLineEdit(str(log.log_plot_left)) rightScaleLineEdit = QtGui.QLineEdit( str(log.log_plot_right)) logarithmicCheckBox = QtGui.QTableWidgetItem() logarithmicCheckBox.setFlags(QtCore.Qt.ItemIsUserCheckable | QtCore.Qt.ItemIsEnabled) logarithmicCheckBox.setCheckState(log.is_logarithmic) logarithmicCheckBox.setData(Qt.UserRole, str(log.id)) buttonQColor = ImageUtils.rbgToQColor(log.rgb) #logger.debug("--populateCurveTable() "+log.rgb+" converted rgb: "+str(buttonQColor.getRgb())) qColorButton = QColorButton() qColorButton.setColor(buttonQColor) qColorButton.setData(Qt.UserRole, str(log.id)) opacityLineEdit = QtGui.QLineEdit(log.alpha) widthLineEdit = QtGui.QLineEdit(str(log.line_width)) styleLineEdit = QtGui.QLineEdit(log.line_style) pointSizeLineEdit = QtGui.QLineEdit(str(log.point_size)) pointStyleLineEdit = QtGui.QLineEdit(log.point_style) pointsOn = QtGui.QTableWidgetItem() pointsOn.setFlags(QtCore.Qt.ItemIsUserCheckable | QtCore.Qt.ItemIsEnabled) pointsOn.setCheckState(log.log_plot_points_on) pointsOn.setData(Qt.UserRole, str(log.id)) twItem0 = QtGui.QTableWidgetItem(nameLineEdit.text()) twItem0.setData(Qt.UserRole, str(log.id)) twItem1 = QtGui.QTableWidgetItem(typeLineEdit.text()) twItem1.setData(Qt.UserRole, str(log.id)) twItem2 = QtGui.QTableWidgetItem(unitsLineEdit.text()) twItem2.setData(Qt.UserRole, str(log.id)) twItem3 = QtGui.QTableWidgetItem(trackLineEdit.text()) twItem3.setData(Qt.UserRole, str(log.id)) twItem4 = QtGui.QTableWidgetItem(leftScaleLineEdit.text()) twItem4.setData(Qt.UserRole, str(log.id)) twItem5 = QtGui.QTableWidgetItem(rightScaleLineEdit.text()) twItem5.setData(Qt.UserRole, str(log.id)) twItem8 = QtGui.QTableWidgetItem(opacityLineEdit.text()) twItem8.setData(Qt.UserRole, str(log.id)) twItem9 = QtGui.QTableWidgetItem(widthLineEdit.text()) twItem9.setData(Qt.UserRole, str(log.id)) twItem10 = QtGui.QTableWidgetItem(styleLineEdit.text()) twItem10.setData(Qt.UserRole, str(log.id)) twItem11 = QtGui.QTableWidgetItem(pointSizeLineEdit.text()) twItem11.setData(Qt.UserRole, str(log.id)) twItem12 = QtGui.QTableWidgetItem( pointStyleLineEdit.text()) twItem12.setData(Qt.UserRole, str(log.id)) #row, column self.curveTableWidget.setItem(j + i, 0, twItem0) self.curveTableWidget.setItem(j + i, 1, twItem1) self.curveTableWidget.setItem(j + i, 2, twItem2) self.curveTableWidget.setItem(j + i, 3, twItem3) self.curveTableWidget.setItem(j + i, 4, twItem4) self.curveTableWidget.setItem(j + i, 5, twItem5) self.curveTableWidget.setItem(j + i, 6, logarithmicCheckBox) self.curveTableWidget.setCellWidget(j + i, 7, qColorButton) self.curveTableWidget.setItem(j + i, 8, twItem8) self.curveTableWidget.setItem(j + i, 9, twItem9) self.curveTableWidget.setItem(j + i, 10, twItem10) self.curveTableWidget.setItem(j + i, 11, twItem11) self.curveTableWidget.setItem(j + i, 12, twItem12) self.curveTableWidget.setItem(j + i, 13, pointsOn) #logger.debug("--populateCurveTable() j: "+str(j)+" i: "+str(i)) ids.append(log.id) j += 1 self.curveTableWidget.itemChanged.connect(self.curveStyleChanged)
def generatePlot(self, logTrackData, wellPlotData): #pw = pg.PlotWidget(name='Plot1') ## giving the plots names allows us to link their axes together self.getAxis('left').setStyle(showValues=False) self.getAxis('bottom').setStyle(showValues=False) #store data for header to retrieve self.setData(Qt.UserRole, logTrackData) #see http://stackoverflow.com/questions/5036700/how-can-you-dynamically-create-variables-in-python-via-a-while-loop self.show() #Reset the dict to empty self.plotItemDict = {} axisDict = {} i = 0 firstLogId = logTrackData.getLogs()[0] for log in logTrackData.getLogs(): if i == 0: self.yData = log.z_measure_data self.plotItemDict[log.id] = self.plotItem #hide the A button see https://groups.google.com/forum/#!topic/pyqtgraph/5cc0k6TG89k self.plotItemDict[log.id].hideButtons() self.plotItemDict[log.id].setRange(xRange=(log.log_plot_left, log.log_plot_right), padding=0, disableAutoRange=True) plt = self.plotItemDict[log.id].plot(y=log.z_measure_data, x=log.log_data) rgbaColor = ImageUtils.rbgaToQColor(log.rgb, log.alpha) plt.setPen(rgbaColor) elif i == 1: self.plotItemDict[log.id] = pg.ViewBox() self.plotItemDict[log.id].setRange(xRange=(log.log_plot_left, log.log_plot_right), padding=0, disableAutoRange=True) self.plotItemDict[firstLogId].scene().addItem( self.plotItemDict[log.id]) self.plotItemDict[firstLogId].getAxis('left').linkToView( self.plotItemDict[log.id]) self.plotItemDict[log.id].setXLink( self.plotItemDict[firstLogId]) plotCurveItem = pg.PlotCurveItem() plotCurveItem.setData(y=log.z_measure_data, x=log.log_data) rgbaColor = ImageUtils.rbgaToQColor(log.rgb, log.alpha) plotCurveItem.setPen(rgbaColor) self.plotItemDict[log.id].addItem(plotCurveItem) else: self.plotItemDict[log.id] = pg.ViewBox() self.plotItemDict[log.id].setRange(xRange=(log.log_plot_left, log.log_plot_right), padding=0, disableAutoRange=True) axisDict[i] = pg.AxisItem('top') self.plotItemDict[firstLogId].layout.addItem(axisDict[i]) self.plotItemDict[firstLogId].scene().addItem( self.plotItemDict[log.id]) axisDict[i].linkToView(self.plotItemDict[log.id]) self.plotItemDict[log.id].setYLink( self.plotItemDict[firstLogId]) plotCurveItem = pg.PlotCurveItem() plotCurveItem.setData(y=log.z_measure_data, x=log.log_data) rgbaColor = ImageUtils.rbgaToQColor(log.rgb, log.alpha) plotCurveItem.setPen(rgbaColor) self.plotItemDict[log.id].addItem(plotCurveItem) i += 1 self.invertY() pixelWidth = WellPlotUtils.convertmmToDPI(logTrackData.track_width) self.setFixedWidth(pixelWidth) self.setSizePolicy(QtGui.QSizePolicy.Maximum, QtGui.QSizePolicy.Expanding)
def setupFirstPlot(self, logPlotData): logger.debug(">>setupFirstPlot") assert len(logPlotData.sub_plots) > 0 #1*n grid, 1st subplot #self.axes = self.figure.add_subplot(1, len(logList), 1, sharey = logPlotData.depthAxis) depthPlots = logPlotData.getZAxisDatas() firstDepthPlot = depthPlots[0] self.axes = self.figure.add_subplot(1, len(logPlotData.sub_plots), 1, sharey=firstDepthPlot.depthAxis) #self.axes.set_title(logPlotData.title) #self.axes.set_xlabel(logList[0].name) #self.axes.set_ylabel(logPlotData.yLabel) self.axes.xaxis.tick_top() #self.axes.xaxis.set_label_position('top') self.axes.get_xaxis().set_visible(False) self.axes.get_yaxis().set_visible(False) xTicks = tic.MaxNLocator(2) self.axes.xaxis.set_major_locator(xTicks) #test semi-transparent region #self.axes.axhspan(1500, 2000, facecolor='g', alpha=0.5) self.axes.invert_yaxis() subPlots = logPlotData.sub_plots firstPlotDTO = subPlots[0] logs = firstPlotDTO.getLogs() log = ArrayUtils.getFirstItem(logs) mpl_rgba = ImageUtils.rgbaToMPLrgba(log.rgb, log.alpha) logger.debug("--setupFirstPlot() log.rgb:{0}".format(log.rgb)) self.axes.plot(log.log_data, log.z_measure_data, color=mpl_rgba) self.axes.set_xlim([log.log_plot_left, log.log_plot_right]) assert len(logPlotData.depth_sub_plots) > 0 max = logPlotData.depth_sub_plots[0].depthAxisPlotMax min = logPlotData.depth_sub_plots[0].depthAxisPlotMin self.axes.set_ylim(max, min) if len(logs) > 1: for i, log in enumerate(logs, start=1): logger.debug("--setupFirstPlot() " + str(i) + " " + str(log.name)) par = self.axes.twiny() mpl_rgba = ImageUtils.rgbaToMPLrgba(log.rgb, log.alpha) p = par.plot(log.log_data, log.z_measure_data, color=(mpl_rgba)) par.set_xlim([log.log_plot_left, log.log_plot_right]) par.get_xaxis().set_visible(False) if logPlotData.display_depth_axes == False: self.axes.get_yaxis().set_visible(False) #else: #doesn't do anything #self.figure.tight_layout() #turn on grid if logPlotData.grid_on: self.axes.xaxis.grid(True, 'minor') self.axes.yaxis.grid(True, 'minor') self.axes.xaxis.grid(True, 'major', linewidth=2) self.axes.yaxis.grid(True, 'major', linewidth=2) self.axes.hold(logPlotData.hold) self.step = 1 # axis units self.scale = 1e3 # conversion betweeen scrolling units and axis units
def populateData(self): logger.debug(">>populateData()") titleOnCheckState = WidgetUtils.getQtCheckObject( self._wellPlotData.title_on) self.plotTitleOnCheckBox.setCheckState(titleOnCheckState) self.plotTitleOnCheckBox.stateChanged.connect(self.styleChanged) self.plotTitleLineEdit.setText(self._wellPlotData.title) self.plotTitleLineEdit.textChanged.connect(self.styleChanged) #not enabled for this version self.plotTitleOnCheckBox.setEnabled(False) self.plotTitleLineEdit.setEnabled(False) #track background button trackBackButtonQColor = ImageUtils.rgbToQColor( self._wellPlotData.plot_background_rgb) hBox1 = QHBoxLayout() self.trackBGColourBtnHolderWidget.setLayout(hBox1) self.trackBackgroundColorPushButton = QColorButton() self.trackBackgroundColorPushButton.setColor(trackBackButtonQColor) hBox1.addWidget(self.trackBackgroundColorPushButton) self.trackBackgroundColorPushButton.clicked.connect(self.styleChanged) plotBackgroundAlpha = NumberUtils.stringToInt( self._wellPlotData.plot_background_alpha) self.trackBackgroundOpacitySpinBox.setValue(plotBackgroundAlpha) self.trackBackgroundOpacitySpinBox.valueChanged.connect( self.styleChanged) singleRowCheckState = WidgetUtils.getQtCheckObject( self._wellPlotData.single_row_header_labels) self.singleRowLabelsCheckBox.setCheckState(singleRowCheckState) self.singleRowLabelsCheckBox.stateChanged.connect(self.styleChanged) #header label background button labelBackButtonQColor = ImageUtils.rgbToQColor( self._wellPlotData.label_background_rgb) hBox2 = QHBoxLayout() self.headerLabelBGColourBtnHolderWidget.setLayout(hBox2) self.labelBackgroundColorPushButton = QColorButton() self.labelBackgroundColorPushButton.setColor(labelBackButtonQColor) hBox2.addWidget(self.labelBackgroundColorPushButton) self.labelBackgroundColorPushButton.clicked.connect(self.styleChanged) labelBackgroundAlpha = NumberUtils.stringToInt( self._wellPlotData.label_background_alpha) self.labelBackgroundOpacitySpinBox.setValue(labelBackgroundAlpha) self.labelBackgroundOpacitySpinBox.valueChanged.connect( self.styleChanged) #label foreground button #labelForegroundRGB = NumberUtils.stringToInt(self._wellPlotData.label_foreground_rgb) labelForeButtonQColor = ImageUtils.rgbToQColor( self._wellPlotData.label_foreground_rgb) hBox3 = QHBoxLayout() self.headerLabelTextColourBtnHolderWidget.setLayout(hBox3) self.labelForegroundColorPushButton = QColorButton() self.labelForegroundColorPushButton.setColor(labelForeButtonQColor) hBox3.addWidget(self.labelForegroundColorPushButton) self.labelForegroundColorPushButton.clicked.connect(self.styleChanged) labelForegroundAlpha = NumberUtils.stringToInt( self._wellPlotData.label_foreground_alpha) self.labelForegroundOpacitySpinBox.setValue(labelForegroundAlpha) self.labelForegroundOpacitySpinBox.valueChanged.connect( self.styleChanged)
def saveDataState(self, wellPlotData, curveStyleWidget): '''called from apply/OK button, saves all data to log objects ''' #assert twItem.data != None #assert isinstance(twItem.data(Qt.UserRole), tuple) #assert isinstance(twItem.data(Qt.UserRole)[0], LogTrackData) #assert isinstance(twItem.data(Qt.UserRole)[1], Log) allRows = curveStyleWidget.curveTableWidget.rowCount() for row in range(0, allRows): twItemName = curveStyleWidget.curveTableWidget.item(row, 0) trackData = twItemName.data(Qt.UserRole)[0] tableLog = twItemName.data(Qt.UserRole)[1] for track in wellPlotData.getLogTrackDatas(): for log in track.getLogs(): if track.plot_index == trackData.plot_index: if log.id == tableLog.id: logger.debug( "track.plot_index :{0}, trackData.plot_index: {1}, log.id: {2}, tableLog.id: {3}, log.name: {4}" .format(track.plot_index, trackData.plot_index, log.id, tableLog.id, log.name)) twItemLeftScale = curveStyleWidget.curveTableWidget.item( row, 4) log.left_scale = NumberUtils.straightStringToFloat( twItemLeftScale.text()) twItemRightScale = curveStyleWidget.curveTableWidget.item( row, 5) log.right_scale = NumberUtils.straightStringToFloat( twItemRightScale.text()) twItemLogarithmic = curveStyleWidget.curveTableWidget.item( row, 6) log.logarithmic = WidgetUtils.getBoolFromQtCheck( twItemLogarithmic.checkState()) twItemCurveColour = curveStyleWidget.curveTableWidget.cellWidget( row, 7) r, g, b, a = QColor( twItemCurveColour.color()).getRgb() rgbStr = ImageUtils.rgbToString(r, g, b) log.rgb = rgbStr twItemOpacity = curveStyleWidget.curveTableWidget.item( row, 8) log.alpha = NumberUtils.straightStringToFloat( twItemOpacity.text()) twItemLineWidth = curveStyleWidget.curveTableWidget.item( row, 9) log.line_width = NumberUtils.straightStringToFloat( twItemLineWidth.text()) twItemLineStyle = curveStyleWidget.curveTableWidget.cellWidget( row, 10) log.line_style = twItemLineStyle.currentText() twItemPointSize = curveStyleWidget.curveTableWidget.item( row, 11) log.point_size = NumberUtils.straightStringToFloat( twItemPointSize.text()) twItemPointStyle = curveStyleWidget.curveTableWidget.cellWidget( row, 12) log.point_style = twItemPointStyle.currentText() twItemPointsOn = curveStyleWidget.curveTableWidget.item( row, 13) log.log_plot_points_on = WidgetUtils.getBoolFromQtCheck( twItemPointsOn.checkState())
def setupUI(self): PREFFERED_SPACER_HEIGHT = 6 if self.logPlotData.single_row_header_labels: logger.debug("--setupUI() expanded label") vBox = QtGui.QVBoxLayout() vBox.setMargin(0) hbox = QtGui.QHBoxLayout() hbox.setMargin(0) self.logName_label = QtGui.QLabel() self.logName_label.setText(self.log.name) logNameWidth = self.logName_label.geometry().width() if (self.widget_width - logNameWidth) >0: preferredSpace = (self.widget_width - logNameWidth)/2 else: preferredSpace = (self.widget_width)/2 labelLspacerItem = QtGui.QSpacerItem(preferredSpace, PREFFERED_SPACER_HEIGHT, QtGui.QSizePolicy.Expanding, QtGui.QSizePolicy.Minimum) hbox.addItem(labelLspacerItem) hbox.addWidget(self.logName_label) labelRspacerItem = QtGui.QSpacerItem(preferredSpace, PREFFERED_SPACER_HEIGHT, QtGui.QSizePolicy.Expanding, QtGui.QSizePolicy.Minimum) hbox.addItem(labelRspacerItem) valHbox = QtGui.QHBoxLayout() valHbox.setMargin(0) self.logValLeft_label = QtGui.QLabel() self.logValLeft_label.setText(str(self.log.log_plot_left)) units = self.getUnits(self.log) assert units != None self.logUnit_label = QtGui.QLabel() self.logUnit_label.setText(units) self.logValRight_label = QtGui.QLabel() self.logValRight_label.setText(str(self.log.log_plot_right)) logValLeftWidth = self.logValLeft_label.geometry().width() logValRightWidth = self.logValRight_label.geometry().width() logUnitWidth = self.logUnit_label.geometry().width() labelWidths = (logValLeftWidth + logValRightWidth + logUnitWidth) if (self.widget_width - labelWidths) >0: preferredSpace = (self.widget_width - labelWidths)/2 else: preferredSpace = (self.widget_width)/2 valueLSpacerItem = QtGui.QSpacerItem(preferredSpace, PREFFERED_SPACER_HEIGHT, QtGui.QSizePolicy.Expanding, QtGui.QSizePolicy.Minimum) valueRSpacerItem = QtGui.QSpacerItem(preferredSpace, PREFFERED_SPACER_HEIGHT, QtGui.QSizePolicy.Expanding, QtGui.QSizePolicy.Minimum) valHbox.addWidget(self.logValLeft_label) valHbox.addItem(valueLSpacerItem) valHbox.addWidget(self.logUnit_label) valHbox.addItem(labelRspacerItem) valHbox.addWidget(self.logValRight_label) vBox.addLayout(hbox) vBox.addLayout(valHbox) self.setLayout(vBox) else: logger.debug("--setupUI() compressed label") hbox = QtGui.QHBoxLayout() hbox.setMargin(0) self.logValLeft_label = QtGui.QLabel() self.logValLeft_label.setText(str(self.log.log_plot_left)) self.logName_label = QtGui.QLabel() units = LogDao.getUnits(self.log) if units != None: labelText = self.log.name + " (" + units +")" else: labelText = self.log.name self.logName_label.setText(labelText) self.logValRight_label = QtGui.QLabel() self.logValRight_label.setText(str(self.log.log_plot_right)) logValLeftWidth = self.logValLeft_label.geometry().width() logValRightWidth = self.logValRight_label.geometry().width() logNameWidth = self.logName_label.geometry().width() labelWidths = (logValLeftWidth + logValRightWidth + logNameWidth) if (self.widget_width - labelWidths) >0: preferredSpace = (self.widget_width - labelWidths)/2 else: preferredSpace = (self.widget_width)/2 labelLspacerItem = QtGui.QSpacerItem(preferredSpace, 10, QtGui.QSizePolicy.Expanding, QtGui.QSizePolicy.Minimum) labelRspacerItem = QtGui.QSpacerItem(preferredSpace, 10, QtGui.QSizePolicy.Expanding, QtGui.QSizePolicy.Minimum) hbox.addWidget(self.logValLeft_label) hbox.addItem(labelLspacerItem) hbox.addWidget(self.logName_label) hbox.addItem(labelRspacerItem) hbox.addWidget(self.logValRight_label) self.setLayout(hbox) self.setFixedWidth(self.widget_width) #set colours pal=QtGui.QPalette() role = QtGui.QPalette.Background backgroundQColor = ImageUtils.rgbToQColor(self.logPlotData.label_background_rgb) pal.setColor(role, backgroundQColor) role = QtGui.QPalette.Foreground foregroundQColor = ImageUtils.rgbToQColor(self.logPlotData.label_foreground_rgb) pal.setColor(role, foregroundQColor) self.setPalette(pal)