From e027c560474840ee9c4814cb8c674515876807e9 Mon Sep 17 00:00:00 2001 From: miruka Date: Thu, 15 Aug 2019 09:57:58 -0400 Subject: [PATCH] Add/improve ModelStore and Model __str__ --- TODO.md | 6 ++---- src/python/app.py | 6 ++---- src/python/models/items.py | 3 ++- src/python/models/model.py | 8 +++++++- src/python/models/model_store.py | 7 +++++++ 5 files changed, 20 insertions(+), 10 deletions(-) diff --git a/TODO.md b/TODO.md index 6cdff124..57ca486d 100644 --- a/TODO.md +++ b/TODO.md @@ -1,6 +1,3 @@ -- Investigate? - - `QCoreApplication::setAttribute(Qt::AA_EnableHighDpiScaling)` - - Refactoring - Use [Animators](https://doc.qt.io/qt-5/qml-qtquick-animator.html) - Sendbox @@ -14,7 +11,6 @@ - When qml syntax highlighting supports ES6 string interpolation, use them - Fixes - - Terrible performance using `QT_QPA_PLATFORM=wayland-egl`, must use `xcb` - Reloading config files (cache) - Ignore @ when filtering members - Tiny invisible scrollbar @@ -31,6 +27,7 @@ - Keyboard flicking against top/bottom edge - Don't strip user spacing in html - [hr not working](https://bugreports.qt.io/browse/QTBUG-74342) + - Terrible performance using `QT_QPA_PLATFORM=wayland-egl`, must use `xcb` - UI - Popup: @@ -93,6 +90,7 @@ - preferredIconPack: accept multiple values - Find icon packs in user data dir - Correctly implement uiScale/fontScale + ctrl+-= keys + - See `QCoreApplication::setAttribute(Qt::AA_EnableHighDpiScaling)` - See [Text.fontSizeMode](https://doc.qt.io/qt-5/qml-qtquick-text.html#fontSizeMode-prop) - Way to round avatar corners to allow box radius - If avatar is set, name color from average color? diff --git a/src/python/app.py b/src/python/app.py index 2e203ba0..600a3e9d 100644 --- a/src/python/app.py +++ b/src/python/app.py @@ -89,10 +89,8 @@ class App: from .models.items import Account, Room, Member, Event, Device # noqa - import json - jd = lambda obj: print( # noqa - json.dumps(obj, indent=4, ensure_ascii=False), - ) + p = print # pdb's `p` doesn't print a class's __str__ # noqa + from pprintpp import pprint as pp # noqa log.info("\n=> Run `socat readline tcp:127.0.0.1:4444` in a terminal " "to connect to pdb.") diff --git a/src/python/models/items.py b/src/python/models/items.py index 56951c20..33c55f83 100644 --- a/src/python/models/items.py +++ b/src/python/models/items.py @@ -34,7 +34,8 @@ class Room(ModelItem): filter_string: str = "" typing_members: List[str] = field(default_factory=list) - last_event: Optional[Dict[str, Any]] = None # Event __dict__ + # Event __dict__ + last_event: Optional[Dict[str, Any]] = field(default=None, repr=False) def __lt__(self, other: "Room") -> bool: # Left rooms may still have an inviter_id, check left first. diff --git a/src/python/models/model.py b/src/python/models/model.py index a5970a6b..afc644bd 100644 --- a/src/python/models/model.py +++ b/src/python/models/model.py @@ -38,7 +38,9 @@ class Model(MutableMapping): def __str__(self) -> str: if isinstance(self.sync_id, tuple): - sid = (self.sync_id[0].__name__, *self.sync_id[1:]) # type: ignore + reprs = tuple(repr(s) for s in self.sync_id[1:]) + sid = ", ".join((self.sync_id[0].__name__, *reprs)) # type: ignore + sid = f"({sid})" else: sid = self.sync_id.__name__ # type: ignore @@ -111,3 +113,7 @@ class Model(MutableMapping): self.sortable = True return self.serialized() + + + def __lt__(self, other: "Model") -> bool: + return str(self.sync_id) < str(other.sync_id) diff --git a/src/python/models/model_store.py b/src/python/models/model_store.py index 2b884585..7e702a44 100644 --- a/src/python/models/model_store.py +++ b/src/python/models/model_store.py @@ -52,3 +52,10 @@ class ModelStore(MutableMapping): def __len__(self) -> int: return len(self.data) + + + def __str__(self) -> str: + return "%s(\n %s\n)" % ( + type(self).__name__, + "\n ".join(sorted(str(v) for v in self.values())), + )