-
-
Notifications
You must be signed in to change notification settings - Fork 791
Revive textual backend #2822
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Revive textual backend #2822
Changes from 3 commits
302a4da
fe1137b
9426d85
0c572d9
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| The Textual backend is now compatible with versions of Textual after v0.63.3. | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -36,6 +36,24 @@ def __init__(self, interface): | |
| self.container = None | ||
| self.create() | ||
|
|
||
| self._pending_children: list[Widget] = list() | ||
|
||
|
|
||
| def install(self, parent): | ||
| """Add widget and any pending children to the native DOM for the app. | ||
|
|
||
| Textual does not allow widgets to be added to the DOM until their parent is | ||
| added. Therefore, when children are added to an unmounted widget, their | ||
| mounting is deferred until their parent is mounted. | ||
| """ | ||
| # Mount widget on to its parent | ||
| parent.native.mount(self.native) | ||
|
|
||
| # Mount any pending children as native children | ||
| for child in self._pending_children: | ||
| child.install(parent=self) | ||
|
|
||
| self._pending_children.clear() | ||
|
|
||
| def get_size(self) -> Size: | ||
| return Size(0, 0) | ||
|
|
||
|
|
@@ -74,7 +92,7 @@ def set_bounds(self, x, y, width, height): | |
|
|
||
| # Positions are more complicated. The (x,y) provided as an argument is | ||
| # in absolute coordinates. The `content_left` ad `content_right` values | ||
| # of the layout are relative coordianate. Textual doesn't allow specifying | ||
| # of the layout are relative coordinate. Textual doesn't allow specifying | ||
| # either absolute *or* relative - we can only specify margin values within | ||
| # a row/column box. This means we need to reverse engineer the margins from | ||
| # the computed layout. | ||
|
|
@@ -152,13 +170,21 @@ def set_background_color(self, color): | |
| ###################################################################### | ||
|
|
||
| def add_child(self, child): | ||
| self.native.mount(child.native) | ||
| # A child can only be added to a widget that is already mounted on the app. | ||
| # So, mounting the child is deferred if the parent is not mounted yet. | ||
| if self.native.is_attached: | ||
| self.native.mount(child.native) | ||
| else: | ||
| self._pending_children.append(child) | ||
|
|
||
| def insert_child(self, index, child): | ||
| pass | ||
|
|
||
| def remove_child(self, child): | ||
| self.native.remove(child.native) | ||
| try: | ||
| self._pending_children.remove(child) | ||
| except ValueError: | ||
| self.native.remove_children([child.native]) | ||
|
|
||
| def refresh(self): | ||
| intrinsic = self.interface.intrinsic | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.