Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions src/toad/application_lifetime.py
Original file line number Diff line number Diff line change
Expand Up @@ -147,8 +147,17 @@ async def start(self) -> None:
ApplicationLifetime._startup_hook = ApplicationLifetime._startup_hook.notify(self)
await self.restore_workspace()
self.started()
self.prepare_view_settings()
self.settle_heap()

def prepare_view_settings(self) -> None:
"""The class setup every view's configuration needs, done once the first frame and
the restored tabs are up, before the heap settles (so it is frozen with them), and
not on the reader's first tap of a view."""
from toad.object_configuration import ObjectConfiguration

ObjectConfiguration.prepare_settings_type(self.app.saved_settings)

@staticmethod
def settle_heap() -> None:
"""What is alive once the workspace is back (modules, classes, declared families, the
Expand Down
17 changes: 15 additions & 2 deletions src/toad/object_configuration.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,8 +65,7 @@ def __init__(self, identity: TabIdentity, global_settings: SavedSettings,
scope = str(ScopeKey.of("view", identity.mode_name))
if ObjectStateRegistry.get_by_scope(scope) is not None:
raise ValueError(f"Settings already open for {identity}")
lazy_type = LazyDataclassFactory.make_lazy_simple(type(defaults.object_instance))
super().__init__(lazy_type(), scope_id=scope, parent_state=defaults)
super().__init__(self.lazy_settings_type(global_settings)(), scope_id=scope, parent_state=defaults)
if self.path.exists():
document = FieldCodec.decode(ObjectSettingsDocument, FieldCodec.parse(self.path.read_text("utf-8")))
if document.identity != identity:
Expand All @@ -81,6 +80,20 @@ def __init__(self, identity: TabIdentity, global_settings: SavedSettings,
self.on_resolved_changed(self.apply_changes)
self.on_state_changed(self.save_changes)

@staticmethod
def lazy_settings_type(global_settings: SavedSettings) -> type:
"""The settings tree as a view holds it, every field following the app's settings
until the view sets it: made once per settings class."""
return LazyDataclassFactory.make_lazy_simple(type(global_settings.state.object_instance))

@classmethod
def prepare_settings_type(cls, global_settings: SavedSettings) -> None:
"""Set up, once, what every view's configuration is built from: its lazy settings
class, each nested one, and their annotations, which the first instance validates
against. That is class setup (190 ms on a phone's speed), and unprepared it was
paid by the first view the reader opened."""
cls.lazy_settings_type(global_settings)()

def field(self, path: str) -> ObjectSettingField:
return ObjectSettingField(self, self.parameter_structure.path(path))

Expand Down
8 changes: 6 additions & 2 deletions src/toad/qt/history.py
Original file line number Diff line number Diff line change
Expand Up @@ -419,11 +419,15 @@ def paint(self, painter, option, index) -> None: # type: ignore[override]

@dataclass(frozen=True)
class PreparedOnFill(RowFormatting):
"""A row's formatting prepared only when a document is filled from it: a measurement that
answers from its cache never fills, so it never pays for the preparation."""
"""A row's formatting prepared only when a measurement needs it: one that answers from its
cache never resolves it, so it never pays for the preparation. What it resolves to may be
the row's pending stand-in, which the measurement estimates instead of laying out."""

prepare: Callable[[], RowFormatting]

def resolved(self) -> RowFormatting:
return self.prepare().resolved()

def fill(self, document: QTextDocument) -> None:
self.prepare().fill(document)

Expand Down
Loading
Loading