def createDoubleRowLabelBox(self): logger.debug("--setupUI() two row header labels") vBox = QtGui.QVBoxLayout() vBox.setMargin(0) self.logName_label = QtGui.QLabel() self.logName_label.setText(self.log.name) hbox = self.createBoxWithCentredLabel(self.logName_label) self.logValLeft_label = QtGui.QLabel() self.logValLeft_label.setText(str(self.log.log_plot_left)) assert self.log.log_plot_left != None assert self.log.log_plot_left != "" units = LogDao.getUnits(self.log) logUnit_label = QtGui.QLabel() logUnit_label.setText(units) self.logValRight_label = QtGui.QLabel() self.logValRight_label.setText(str(self.log.log_plot_right)) assert self.log.log_plot_right != None assert self.log.log_plot_right != "" lowerRowLables = [] lowerRowLables.append(self.logValLeft_label) lowerRowLables.append(logUnit_label) lowerRowLables.append(self.logValRight_label) valHbox = self.createHBoxWithLabels(lowerRowLables) vBox.addLayout(hbox) vBox.addLayout(valHbox) return vBox
def createSingleRowLabelBox(self): logger.debug("--setupUI() single row label") self.logValLeft_label = QtGui.QLabel() self.logValLeft_label.setText(str(self.log.log_plot_left)) logValLeftWidth = self.logValLeft_label.fontMetrics().boundingRect( self.logValLeft_label.text()).width() #see http://stackoverflow.com/questions/8633433/qt-get-the-pixel-length-of-a-string-in-a-qlabel #add 10% padding as bounding rect may not give exact width paddedLeftWidth = int(logValLeftWidth + logValLeftWidth / self.VALUE_PADDING) self.logValLeft_label.setFixedWidth(paddedLeftWidth) assert self.log.log_plot_left != None assert self.log.log_plot_left != "" self.logName_label = QtGui.QLabel() units = LogDao.getUnits(self.log) assert units != None if units != None: labelText = self.log.name.strip() + " (" + units.strip() + ")" else: labelText = self.log.name.strip() self.logName_label.setText(labelText) logNameWidth = self.logName_label.fontMetrics().boundingRect( self.logName_label.text()).width() paddedNameWidth = int(logNameWidth + logNameWidth / self.NAME_PADDING) self.logValRight_label = QtGui.QLabel() self.logValRight_label.setText(str(self.log.log_plot_right)) logValRightWidth = self.logValRight_label.fontMetrics().boundingRect( self.logValRight_label.text()).width() paddedRightWidth = int(logValRightWidth + logValRightWidth / self.VALUE_PADDING) self.logValRight_label.setFixedWidth(paddedRightWidth) assert self.log.log_plot_right != None assert self.log.log_plot_right != "" fullLabelWidths = (paddedLeftWidth + paddedNameWidth + paddedRightWidth) labelList = [] #drop units if doesn't fit if self.track.geometry().width() < fullLabelWidths: self.logName_label.setText(self.log.name) logNameWidthNoUnit = self.logName_label.fontMetrics().boundingRect( self.logName_label.text()).width() paddedNameWidthNoUnit = int(logNameWidthNoUnit + logNameWidthNoUnit / 10) labelWidths = (paddedLeftWidth + paddedNameWidthNoUnit + paddedRightWidth) #drop l and R vals if still doesn't fit if self.track.geometry().width() < labelWidths: self.logName_label.setFixedWidth(paddedNameWidthNoUnit) labelList.append(self.logName_label) else: self.logName_label.setFixedWidth(paddedNameWidthNoUnit) labelList.append(self.logValLeft_label) labelList.append(self.logName_label) labelList.append(self.logValRight_label) else: self.logName_label.setFixedWidth(paddedNameWidth) labelList.append(self.logValLeft_label) labelList.append(self.logName_label) labelList.append(self.logValRight_label) hbox = self.createHBoxWithLabels(labelList, True) return hbox
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)