mount fix

This commit is contained in:
Will McGugan
2021-07-18 21:27:34 +01:00
parent 6ccadcb47f
commit d9fb516298
5 changed files with 13 additions and 16 deletions

View File

@@ -29,8 +29,8 @@ class SmoothApp(App):
self.bar.layout_offset_x = -40 self.bar.layout_offset_x = -40
await self.view.dock(footer, edge="bottom") await self.view.dock(footer, edge="bottom")
await self.view.dock(self.bar, edge="left", size=40, z=1)
await self.view.dock(Placeholder(), Placeholder(), edge="top") await self.view.dock(Placeholder(), Placeholder(), edge="top")
await self.view.dock(self.bar, edge="left", size=40, z=1)
SmoothApp.run() SmoothApp.run()

View File

@@ -59,7 +59,7 @@ class MessagePump:
return self._parent and not self._parent._closed and not self._parent._closing return self._parent and not self._parent._closed and not self._parent._closing
def log(self, *args) -> None: def log(self, *args) -> None:
return self.app.log(args) return self.app.log(*args)
def set_parent(self, parent: MessagePump) -> None: def set_parent(self, parent: MessagePump) -> None:
self._parent = parent self._parent = parent

View File

@@ -100,7 +100,7 @@ class View(Widget):
self.require_repaint() self.require_repaint()
async def refresh_layout(self) -> None: async def refresh_layout(self) -> None:
await self.layout.mount_all(self)
if not self.size or not self.is_root_view: if not self.size or not self.is_root_view:
return return
@@ -108,10 +108,6 @@ class View(Widget):
hidden, shown, resized = self.layout.reflow(width, height) hidden, shown, resized = self.layout.reflow(width, height)
self.app.refresh() self.app.refresh()
for widget in self.layout.get_widgets():
if not self.is_mounted(widget):
await self.mount(widget)
for widget in hidden: for widget in hidden:
widget.post_message_no_wait(events.Hide(self)) widget.post_message_no_wait(events.Hide(self))
for widget in shown: for widget in shown:

View File

@@ -53,7 +53,7 @@ class DockView(View):
) -> GridLayout: ) -> GridLayout:
grid = GridLayout(gap=gap, gutter=gutter, align=align) grid = GridLayout(gap=gap, gutter=gutter, align=align)
view = View(layout=grid) view = View(layout=grid, name=name)
dock = Dock(edge, (view,), z) dock = Dock(edge, (view,), z)
assert isinstance(self.layout, DockLayout) assert isinstance(self.layout, DockLayout)
self.layout.docks.append(dock) self.layout.docks.append(dock)
@@ -64,4 +64,5 @@ class DockView(View):
await self.mount(view) await self.mount(view)
else: else:
await self.mount(**{name: view}) await self.mount(**{name: view})
await self.refresh_layout()
return grid return grid

View File

@@ -24,6 +24,14 @@ class Footer(Widget):
"""If highlight key changes we need to regenerate the text.""" """If highlight key changes we need to regenerate the text."""
self._key_text = None self._key_text = None
async def on_mouse_move(self, event: events.MouseMove) -> None:
"""Store any key we are moving over."""
self.highlight_key = event.style.meta.get("key")
async def on_leave(self, event: events.Leave) -> None:
"""Clear any highlight when the mouse leave the widget"""
self.highlight_key = None
def __rich_repr__(self) -> rich.repr.RichReprResult: def __rich_repr__(self) -> rich.repr.RichReprResult:
yield "keys", self.keys yield "keys", self.keys
@@ -55,11 +63,3 @@ class Footer(Widget):
if self._key_text is None: if self._key_text is None:
self._key_text = self.make_key_text() self._key_text = self.make_key_text()
return self._key_text return self._key_text
async def on_mouse_move(self, event: events.MouseMove) -> None:
"""Store any key we are moving over."""
self.highlight_key = event.style.meta.get("key")
async def on_leave(self, event: events.MouseMove) -> None:
"""Clear any highlight when the mouse leave the widget"""
self.highlight_key = None