Skip to content

Commit

Permalink
Update Textual v0.63 (#91)
Browse files Browse the repository at this point in the history
  • Loading branch information
davidbrochart authored May 26, 2024
1 parent 10d9e93 commit 5bab40e
Show file tree
Hide file tree
Showing 6 changed files with 34 additions and 15 deletions.
21 changes: 16 additions & 5 deletions plugins/cell/txl_cell/components.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
from asphalt.core import Component, Context
from pycrdt import Doc, Map, MapEvent, Text
from rich.text import Text as RichText
from textual.app import ComposeResult
from textual.containers import Container
from textual.widgets import Static

Expand Down Expand Up @@ -68,7 +69,7 @@ def __init__(
self.show_execution_count = show_execution_count
self.show_border = show_border
self.outputs = []
self.update()
self.update(mount=False)
self.ycell.observe_deep(self.on_change)
self.styles.height = "auto"
self.cell_change_events = asyncio.Queue()
Expand Down Expand Up @@ -174,7 +175,14 @@ def get_execution_count(self, value):
execution_count = " " if value is None else str(value).removesuffix(".0")
return f"[green]In [[#66ff00]{execution_count}[/#66ff00]]:[/green]"

def update(self):
def compose(self) -> ComposeResult:
if self.show_execution_count:
yield self.execution_count
yield self.source
for output in self.outputs:
yield output

def update(self, mount: bool = True):
cell = json.loads(str(self.ycell))
if self.show_execution_count:
execution_state = self.ycell.get("execution_state")
Expand All @@ -187,7 +195,8 @@ def update(self):
self.get_execution_count("*")
)
self.execution_count = Static(execution_count)
self.mount(self.execution_count)
if mount:
self.mount(self.execution_count)
cell_type = cell["cell_type"]
if cell_type == "markdown":
language = "markdown"
Expand All @@ -200,12 +209,14 @@ def update(self):
language=language,
show_border=self.show_border,
)
self.mount(self.source)
if mount:
self.mount(self.source)

for output in cell.get("outputs", []):
output_widget = self.get_output_widget(output)
if output_widget is not None:
self.mount(output_widget)
if mount:
self.mount(output_widget)
self.outputs.append(output_widget)

def get_output_widget(self, output):
Expand Down
2 changes: 1 addition & 1 deletion plugins/jpterm/txl_jpterm/components.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,14 +26,14 @@ def __init__(self, header, footer, main_area, file_browser, editors, launcher, *
self.file_browser = file_browser
self.editors = editors
self.launcher = launcher
self.main_area.show(self.launcher, "Launcher", mount=False)
super().__init__(*args, **kwargs)

def watch_show_browser(self, show_browser: bool) -> None:
self.set_class(show_browser, "-show-browser")

def compose(self) -> ComposeResult:
yield self.header
self.main_area.show(self.launcher, "Launcher")
yield Container(
self.file_browser,
self.main_area,
Expand Down
6 changes: 3 additions & 3 deletions plugins/jpterm/txl_jpterm/footer.py
Original file line number Diff line number Diff line change
Expand Up @@ -103,9 +103,9 @@ def make_key_text(self) -> Text:
key_style = self.get_component_rich_style("footer--key")

bindings = [
binding
for (_namespace, binding) in self.app.namespace_bindings.values()
if binding.show
active_binding.binding
for active_binding in self.app.active_bindings.values()
if active_binding.binding.show
]

action_to_bindings = defaultdict(list)
Expand Down
12 changes: 9 additions & 3 deletions plugins/jpterm/txl_jpterm/main_area.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
from typing import Optional

from textual.app import ComposeResult
from textual.widget import Widget
from textual.widgets import Tab, Tabs

Expand All @@ -19,25 +20,30 @@ def __init__(self):
self.widget_to_tab = {}
self.title = 0

def show(self, widget: Widget, title: Optional[str] = None):
def show(self, widget: Widget, title: Optional[str] = None, mount: bool = True):
if widget not in self.mounted:
if title is None:
title = self.title
self.title += 1
tab = Tab(str(title))
if self.tabs is None:
self.tabs = Tabs(tab)
self.mount(self.tabs)
else:
self.tabs.add_tab(tab)
self.tabs.active = tab.id
self.widget_to_tab[widget] = (tab, False)
self.mounted.append(widget)
self.mount(widget)
if mount:
self.mount(widget)
else:
tab, dirty = self.widget_to_tab[widget]
self.tabs.active = tab.id

def compose(self) -> ComposeResult:
yield self.tabs
for widget in self.mounted:
yield widget

def get_label(self) -> str:
tab = self.tabs.active_tab
return tab.label_text
Expand Down
6 changes: 4 additions & 2 deletions plugins/notebook_editor/txl_notebook_editor/components.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
import anyio
from asphalt.core import Component, Context
from httpx import AsyncClient
from textual.app import RenderResult
from textual.app import ComposeResult, RenderResult
from textual.containers import VerticalScroll
from textual.events import Event
from textual.keys import Keys
Expand Down Expand Up @@ -86,7 +86,9 @@ def __init__(
self.nb_change_target = asyncio.Queue()
self.nb_change_events = asyncio.Queue()
self.top_bar = TopBar()
self.mount(self.top_bar)

def compose(self) -> ComposeResult:
yield self.top_bar

async def watch_busy(self, event):
self.top_bar.busy = event.busy
Expand Down
2 changes: 1 addition & 1 deletion txl/pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ classifiers = [
]
dependencies = [
"asphalt >=4.12.0,<5",
"textual[syntax] >=0.53.1,<0.54.0",
"textual[syntax] >=0.63.4,<0.64.0",
]
dynamic = ["version"]

Expand Down

0 comments on commit 5bab40e

Please sign in to comment.