Skip to content

FrameInfoModel

Base classes

Name Children Inherits
ListMixin
prettyqt.itemmodels.listmixin
Mixin for flat models which are backed by a python list (`self.items`).
AbstractTableModel
prettyqt.core.abstracttablemodel
Abstract model that can be subclassed to create table models.

โ‹” Inheritance diagram

graph TD
  297850248["itemmodels.FrameInfoModel"]
  2612381175["itemmodels.ListMixin"]
  2751680898["builtins.object"]
  656210031["core.AbstractTableModel"]
  4092674192["core.AbstractTableModelMixin"]
  3882849576["core.AbstractItemModelMixin"]
  3227531497["core.ObjectMixin"]
  232985924["QtCore.QAbstractTableModel"]
  1898060022["QtCore.QAbstractItemModel"]
  3984060476["QtCore.QObject"]
  37984305["Shiboken.Object"]
  2612381175 --> 297850248
  2751680898 --> 2612381175
  656210031 --> 297850248
  4092674192 --> 656210031
  3882849576 --> 4092674192
  3227531497 --> 3882849576
  2751680898 --> 3227531497
  2751680898 --> 3882849576
  2751680898 --> 4092674192
  232985924 --> 656210031
  1898060022 --> 232985924
  3984060476 --> 1898060022
  37984305 --> 3984060476
  2751680898 --> 37984305

๐Ÿ›ˆ DocStrings

Bases: ListMixin, AbstractTableModel

Model to display a list of inspect.Frameinfos / inspect.Tracebacks.

Source code in prettyqt/itemmodels/frameinfomodel.py
class FrameInfoModel(itemmodels.ListMixin, core.AbstractTableModel):
    """Model to display a list of inspect.Frameinfos / inspect.Tracebacks."""

    HEADER: ClassVar = [
        "Filename",
        "Line number",
        "Function",
        "Code context",
        "Index",
        "Positions",
    ]
    SUPPORTS = Sequence[inspect.FrameInfo | inspect.Traceback]

    @classmethod
    def supports(cls, instance) -> bool:
        match instance:
            case (inspect.FrameInfo(), *_) | (inspect.Traceback(), *_):
                return True
            case _:
                return False

    def columnCount(self, parent=None) -> int:
        return len(self.HEADER)

    def headerData(
        self,
        section: int,
        orientation: constants.Orientation,
        role: constants.ItemDataRole = constants.DISPLAY_ROLE,
    ) -> str | None:
        match orientation, role:
            case constants.HORIZONTAL, constants.DISPLAY_ROLE:
                return self.HEADER[section]
            case constants.VERTICAL, constants.DISPLAY_ROLE:
                return str(section)
        return None

    def data(  # noqa: PLR0911
        self,
        index: core.ModelIndex,
        role: constants.ItemDataRole = constants.DISPLAY_ROLE,
    ):
        if not index.isValid():
            return None
        field = self.items[index.row()]
        match role, index.column():
            case constants.DISPLAY_ROLE, 0:
                return field.filename
            case constants.DISPLAY_ROLE, 1:
                return str(field.lineno)
            case constants.DISPLAY_ROLE, 2:
                return field.function
            case constants.DISPLAY_ROLE, 3:
                # show leading whitespace as dots
                lines = []
                for line in field.code_context or []:
                    stripped = line.lstrip(" ")
                    lines.append(
                        "ยท" * (len(line) - len(stripped)) + stripped.rstrip("\n")
                    )
                return "\n".join(lines)
            case constants.FONT_ROLE, 3:
                return SOURCE_FONT
            case constants.DISPLAY_ROLE, 4:
                return "" if field.index is None else str(field.index)
            case constants.DISPLAY_ROLE, 5:
                if (p := field.positions) is None:
                    return ""
                return f"{p.lineno} - {p.end_lineno}, {p.col_offset} {p.end_col_offset}"
            case constants.USER_ROLE, _:
                return field
            case constants.ALIGNMENT_ROLE, _:
                return constants.ALIGN_CENTER_LEFT
        return None

:fa-brands-github: Show source on GitHub