madgui.widget.log module

This module defines the parts involved in redirecting all logging events to a window.

Classes

LogRecord(time, domain, text)

RecordInfoBar(edit[, time_format, show_time])

Widget that shows log domain and time next to the log widget text.

LogWindow(*args)

Simple log window based on QPlainTextEdit using ExtraSelection to

RecordHandler(log_window)

Handler class that is needed for forwarding logging log events to LogWindow.

class madgui.widget.log.LogRecord(time, domain, text)

Bases: tuple

Attributes

domain

Alias for field number 1

text

Alias for field number 2

time

Alias for field number 0

property domain

Alias for field number 1

property text

Alias for field number 2

property time

Alias for field number 0

class madgui.widget.log.LogWindow(*args)[source]

Bases: PyQt5.QtWidgets.QFrame

Simple log window based on QPlainTextEdit using ExtraSelection to highlight input/output sections with different backgrounds, see: http://doc.qt.io/qt-5/qtwidgets-widgets-codeeditor-example.html

Methods

append(record)

Add a LogRecord.

append_from_binary_stream(domain, text[, …])

Append a log record from a binary utf-8 text stream.

enable(domain, enable)

Turn on/off log records with the given domain.

enable_logging(enable)

Turn on/off display of logging log events.

enabled(domain)

Return if the given domain is configured to be displayed.

excepthook(*args, **kwargs)

Exception handler that prints exceptions and appends a log record instead of exiting.

has_entries(domain)

Return if any log records with the given domain have been emitted.

highlight(domain, color)

Configure log records with the given domain to be colorized in the given color.

rebuild_log()

Clear and reinsert all configured log records into the text control.

set_loglevel(loglevel)

Set minimum log level of displayed log events.

setup_logging(level, fmt)

Redirect exceptions and logging to this widget.

Attributes

maxlen

Maximum number of displayed log records.

append(record)[source]

Add a LogRecord. This can be called by users!

append_from_binary_stream(domain, text, encoding='utf-8')[source]

Append a log record from a binary utf-8 text stream.

enable(domain: str, enable: bool)[source]

Turn on/off log records with the given domain.

enable_logging(enable: bool)[source]

Turn on/off display of logging log events.

enabled(domain: str)bool[source]

Return if the given domain is configured to be displayed.

excepthook(*args, **kwargs)[source]

Exception handler that prints exceptions and appends a log record instead of exiting.

has_entries(domain: str)bool[source]

Return if any log records with the given domain have been emitted.

highlight(domain: str, color: PyQt5.QtGui.QColor)[source]

Configure log records with the given domain to be colorized in the given color.

property maxlen

Maximum number of displayed log records. Default is 0 which means infinite.

rebuild_log()[source]

Clear and reinsert all configured log records into the text control.

This is used internally if the configuration has changed such that previously invisible log entries become visible or vice versa.

set_loglevel(loglevel: str)[source]

Set minimum log level of displayed log events.

setup_logging(level: str = 'INFO', fmt: str = '%(message)s')[source]

Redirect exceptions and logging to this widget.

class madgui.widget.log.RecordHandler(log_window: madgui.widget.log.LogWindow)[source]

Bases: logging.Handler

Handler class that is needed for forwarding logging log events to LogWindow.

This class is instanciated by LogWindow.setup_logging() and there should be no need to instanciate it anywhere else.

Methods

emit(record)

Override logging.Handler.emit() to append to LogWindow.

emit(record)[source]

Override logging.Handler.emit() to append to LogWindow.

class madgui.widget.log.RecordInfoBar(edit, time_format='%H:%M:%S', show_time=True)[source]

Bases: madgui.widget.edit.LineNumberBar

Widget that shows log domain and time next to the log widget text.

This class is taylored toward the behaviour of LogWindow and should not be instanciated from elsewhere.

Methods

add_record(record)

Called by LogWindow when it adds a visible record.

calc_width(count)

Calculate the required widget width in pixels.

clear()

Called by LogWindow before rebuilding the list of displayed records.

draw_block(painter, rect, block, first)

Draw the info corresponding to a given block (text line) of the text document.

enable_timestamps(enable)

Turn on display of times, recalculate geometry, and redraw.

set_timeformat(format)

Set a time display format for use with time.strftime(), recalculate geometry, and redraw.

add_record(record: madgui.widget.log.LogRecord)[source]

Called by LogWindow when it adds a visible record.

calc_width(count: int = 0)int[source]

Calculate the required widget width in pixels.

Parameters

count (int) – ignored here

This overrides LineNumberBar.calc_width.

clear()[source]

Called by LogWindow before rebuilding the list of displayed records.

draw_block(painter, rect, block, first)[source]

Draw the info corresponding to a given block (text line) of the text document.

This overrides LineNumberBar.draw_block.

Parameters
  • painter (QPainter) – painter for the current widget

  • rect (QRect) – clipping rect for the text to be drawn

  • block (QTextBlock) – associated text block in the text edit

  • first (bool) – indicates the topmost visible block on screen

enable_timestamps(enable: bool)[source]

Turn on display of times, recalculate geometry, and redraw.

set_timeformat(format: str)[source]

Set a time display format for use with time.strftime(), recalculate geometry, and redraw.