diff --git a/harmonyqml/backend/model/list_item.py b/harmonyqml/backend/model/list_item.py index 166dd228..fd25e4e8 100644 --- a/harmonyqml/backend/model/list_item.py +++ b/harmonyqml/backend/model/list_item.py @@ -1,3 +1,7 @@ +# Copyright 2019 miruka +# This file is part of harmonyqml, licensed under GPLv3. + +import textwrap from typing import Any, Dict, List, Mapping, Set, Tuple, Union from PyQt5.QtCore import QObject, pyqtProperty, pyqtSignal, pyqtSlot @@ -150,13 +154,26 @@ class ListItem(QObject, metaclass=_ListItemMeta): def __repr__(self) -> str: + from .list_model import ListModel + multiline = any(( + isinstance(v, ListModel) for _, v in self._props.values() + )) + prop_strings = ( - "\033[%dm%s\033[0m=%r" % ( + "\033[{0}m{1}{2}={2}{3}\033[0m".format( 1 if p == self.mainKey else 0, # 1 = term bold p, + " " if multiline else "", getattr(self, p) ) for p in list(self._props.keys()) + self._direct_props ) + + if any((isinstance(v, ListModel) for _, v in self._props.values())): + return "%s(\n%s\n)" % ( + type(self).__name__, + textwrap.indent(",\n".join(prop_strings), prefix=" " * 4) + ) + return "%s(%s)" % (type(self).__name__, ", ".join(prop_strings)) diff --git a/harmonyqml/backend/model/list_model.py b/harmonyqml/backend/model/list_model.py index 53e6caed..ab489ac5 100644 --- a/harmonyqml/backend/model/list_model.py +++ b/harmonyqml/backend/model/list_model.py @@ -1,4 +1,5 @@ import logging +import textwrap from typing import ( Any, Callable, Dict, Iterable, List, Mapping, MutableSequence, Optional, Sequence, Set, Tuple, Union @@ -40,7 +41,16 @@ class ListModel(QAbstractListModel): def __repr__(self) -> str: - return "%s(%r)" % (type(self).__name__, self._data) + if not self._data: + return "%s()" % type(self).__name__ + + return "%s(\n%s\n)" % ( + type(self).__name__, + textwrap.indent( + ",\n".join((repr(item) for item in self._data)), + prefix = " " * 4, + ) + ) def __contains__(self, index: Index) -> bool: diff --git a/harmonyqml/backend/model/sort_filter_proxy.py b/harmonyqml/backend/model/sort_filter_proxy.py index e0526b5a..7737c37e 100644 --- a/harmonyqml/backend/model/sort_filter_proxy.py +++ b/harmonyqml/backend/model/sort_filter_proxy.py @@ -52,8 +52,13 @@ class SortFilterProxy(QSortFilterProxyModel): def __repr__(self) -> str: - return "%s(sortByRole=%r, sourceModel=%r)" % ( - type(self).__name__, self.sortByRole, self.sourceModel(), + return "%s(sortByRole=%r, sourceModel=%s)" % ( + type(self).__name__, + self.sortByRole, + "<%s at %s>" % ( + type(self.sourceModel()).__name__, + hex(id(self.sourceModel())), + ) )