def drawDisplay(self, painter, option, rect, text): """ Overloads the drawDisplay method to render HTML if the rich text \ information is set to true. :param painter | <QtGui.QPainter> option | <QtGui.QStyleOptionItem> rect | <QtCore.QRect> text | <str> """ if self.showRichText(): # create the document doc = QtGui.QTextDocument() doc.setTextWidth(float(rect.width())) doc.setHtml(text) # draw the contents painter.translate(rect.x(), rect.y()) doc.drawContents( painter, QtCore.QRectF(0, 0, float(rect.width()), float(rect.height()))) painter.translate(-rect.x(), -rect.y()) else: if type(text).__name__ not in ('str', 'unicode', 'QString'): text = nativestring(text) metrics = QtGui.QFontMetrics(option.font) text = metrics.elidedText( text, QtCore.Qt.TextElideMode(option.textElideMode), rect.width()) painter.setFont(option.font) painter.drawText(rect, int(option.displayAlignment), text)
def __init__(self, parent): super(XLoggerWidget, self).__init__(parent) # set standard properties self.setReadOnly(True) self.setLineWrapMode(XLoggerWidget.NoWrap) # define custom properties self._clearOnClose = True self._handler = XLoggerWidgetHandler(self) self._currentMode = 'standard' self._blankCache = '' self._mutex = QtCore.QMutex() self._loggers = set() self._configurable = True self._destroyed = False # define the popup button for congfiguration self._configButton = XPopupButton(self) self._configButton.setIcon( QtGui.QIcon(resources.find('img/config.png'))) self._configButton.setShadowed(True) popup = self._configButton.popupWidget() popup.setShowTitleBar(False) popup.setResizable(False) bbox = popup.buttonBox() bbox.clear() bbox.addButton(QtGui.QDialogButtonBox.Ok) # set to a monospace font font = QtGui.QFont('Courier New') font.setPointSize(9) self.setFont(font) metrics = QtGui.QFontMetrics(font) self.setTabStopWidth(4 * metrics.width(' ')) self.setAcceptRichText(False) # determine whether or not to use the light or dark configuration palette = self.palette() base = palette.color(palette.Base) avg = (base.red() + base.green() + base.blue()) / 3.0 if avg < 160: colorSet = XLoggerColorSet.darkScheme() else: colorSet = XLoggerColorSet.lightScheme() self._colorSet = colorSet palette.setColor(palette.Text, colorSet.color('Standard')) palette.setColor(palette.Base, colorSet.color('Background')) self.setPalette(palette) # create the logger tree widget controls = XLoggerControls(self) self._configButton.setCentralWidget(controls) self._configButton.setDefaultAnchor(popup.Anchor.TopRight) # create connections self._handler.dispatch().messageLogged.connect(self.log) self.destroyed.connect(self.markDestroyed)