Skip to content
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

Switch to Asphalt v5.0 #78

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft
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
13 changes: 5 additions & 8 deletions plugins/cell/txl_cell/components.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
from functools import partial
from importlib.metadata import entry_points

from asphalt.core import Component, Context
from asphalt.core import Component, add_resource, request_resource
from pycrdt import Doc, Map, MapEvent, Text
from rich.text import Text as RichText
from textual.containers import Container
Expand Down Expand Up @@ -291,17 +291,14 @@ def __init__(self, show_execution_count: bool = True, show_border: bool = True):
self.show_execution_count = show_execution_count
self.show_border = show_border

async def start(
self,
ctx: Context,
) -> None:
contents = await ctx.request_resource(Contents)
widgets = await ctx.request_resource(Widgets)
async def start(self) -> None:
contents = await request_resource(Contents)
widgets = await request_resource(Widgets)
cell_factory = partial(
_Cell,
contents=contents,
widgets=widgets,
show_execution_count=self.show_execution_count,
show_border=self.show_border,
)
ctx.add_resource(cell_factory, types=CellFactory)
await add_resource(cell_factory, types=CellFactory)
19 changes: 8 additions & 11 deletions plugins/console/txl_console/components.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
from importlib.metadata import entry_points
from typing import Any

from asphalt.core import Component, Context
from asphalt.core import Component, add_resource_factory, request_resource
from pycrdt import ArrayEvent, Doc
from textual.containers import VerticalScroll
from textual.events import Event
Expand Down Expand Up @@ -126,19 +126,16 @@ def current_cell(self):


class ConsoleComponent(Component):
async def start(
self,
ctx: Context,
) -> None:
main_area = await ctx.request_resource(MainArea)
kernels = await ctx.request_resource(Kernels)
kernelspecs = await ctx.request_resource(Kernelspecs)
cell_factory = await ctx.request_resource(CellFactory)
launcher = await ctx.request_resource(Launcher)
async def start(self) -> None:
main_area = await request_resource(MainArea)
kernels = await request_resource(Kernels)
kernelspecs = await request_resource(Kernelspecs)
cell_factory = await request_resource(CellFactory)
launcher = await request_resource(Launcher)

_kernelspecs = await kernelspecs.get()

console_factory = partial(_Console, kernels, _kernelspecs, cell_factory, main_area)

launcher.register("console", console_factory)
ctx.add_resource_factory(console_factory, types=Console)
await add_resource_factory(console_factory, types=Console)
15 changes: 6 additions & 9 deletions plugins/editors/txl_editors/components.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
from pathlib import Path
from typing import Callable, Dict, List

from asphalt.core import Component, Context
from asphalt.core import Component, add_resource, request_resource
from textual.containers import Container

from txl.base import Editor, Editors, FileOpenEvent, Footer, Header, MainArea
Expand Down Expand Up @@ -57,12 +57,9 @@ async def on_open(self, event: FileOpenEvent) -> None:


class EditorsComponent(Component):
async def start(
self,
ctx: Context,
) -> None:
header = await ctx.request_resource(Header)
footer = await ctx.request_resource(Footer)
main_area = await ctx.request_resource(MainArea)
async def start(self) -> None:
header = await request_resource(Header)
footer = await request_resource(Footer)
main_area = await request_resource(MainArea)
editors = _Editors(header, footer, main_area)
ctx.add_resource(editors, types=Editors)
await add_resource(editors, types=Editors)
19 changes: 8 additions & 11 deletions plugins/file_browser/txl_file_browser/components.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,14 @@
from dataclasses import dataclass
from typing import ClassVar

from asphalt.core import Component, Context
from asphalt.core import Component, add_resource, request_resource
from rich.style import Style
from rich.text import Text, TextType
from textual._types import MessageTarget
from textual.message import Message
from textual.widgets._tree import TOGGLE_STYLE, Tree, TreeNode

from txl.base import Contents, FileBrowser
from txl.base import Contents, FileBrowser, FileOpenEvent


@dataclass
Expand Down Expand Up @@ -144,22 +144,19 @@ async def on_tree_node_expanded(self, event: Tree.NodeSelected) -> None:
if not dir_entry.loaded:
await self.load_directory(event.node)
else:
self.open_file_signal.dispatch(dir_entry.path)
await self.open_file_signal.dispatch(dir_entry.path)

def on_tree_node_selected(self, event: Tree.NodeSelected) -> None:
async def on_tree_node_selected(self, event: Tree.NodeSelected) -> None:
event.stop()
dir_entry = event.node.data
if dir_entry is None:
return
if not dir_entry.is_dir:
self.open_file_signal.dispatch(dir_entry.path)
await self.open_file_signal.dispatch(FileOpenEvent(path=dir_entry.path))


class FileBrowserComponent(Component):
async def start(
self,
ctx: Context,
) -> None:
contents = await ctx.request_resource(Contents)
async def start(self) -> None:
contents = await request_resource(Contents)
file_browser = DirectoryTree(".", contents, id="browser-view")
ctx.add_resource(file_browser, types=FileBrowser)
await add_resource(file_browser, types=FileBrowser)
13 changes: 5 additions & 8 deletions plugins/image_viewer/txl_image_viewer/components.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import os
import tempfile

from asphalt.core import Component, Context
from asphalt.core import Component, add_resource, request_resource
from PIL import Image
from textual.widget import Widget
from textual_imageview.viewer import ImageViewer
Expand Down Expand Up @@ -57,18 +57,15 @@ def __init__(self, register: bool = True):
super().__init__()
self.register = register

async def start(
self,
ctx: Context,
) -> None:
contents = await ctx.request_resource(Contents)
async def start( self) -> None:
contents = await request_resource(Contents)

def image_viewer_factory():
return _ImageViewer(contents)

if self.register:
editors = await ctx.request_resource(Editors)
editors = await request_resource(Editors)
editors.register_editor_factory(image_viewer_factory, [".png", ".jpg", ".jpeg"])
else:
image_viewer = image_viewer_factory()
ctx.add_resource(image_viewer, types=Editor)
await add_resource(image_viewer, types=Editor)
30 changes: 17 additions & 13 deletions plugins/jpterm/txl_jpterm/components.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from asphalt.core import Component, Context
from asphalt.core import Component, add_resource, request_resource, start_background_task
from textual.app import App, ComposeResult
from textual.containers import Container
from textual.reactive import var
Expand Down Expand Up @@ -52,20 +52,24 @@ def __init__(self, driver_class=None):
super().__init__()
self.driver_class = driver_class

async def start(
self,
ctx: Context,
) -> None:
async def start(self) -> None:
header = _Header()
footer = _Footer()
main_area = _MainArea()
ctx.add_resource(header, types=Header)
ctx.add_resource(footer, types=Footer)
ctx.add_resource(main_area, types=MainArea)
file_browser = await ctx.request_resource(FileBrowser)
editors = await ctx.request_resource(Editors)
file_browser.open_file_signal.connect(editors.on_open)
launcher = await ctx.request_resource(Launcher)
await add_resource(header, types=Header)
await add_resource(footer, types=Footer)
await add_resource(main_area, types=MainArea)
file_browser = await request_resource(FileBrowser)
editors = await request_resource(Editors)

async def open_file():
async with file_browser.open_file_signal.stream_events() as stream:
async for event in stream:
await editors.on_open(event)

await start_background_task(open_file, name="File browser open file")

launcher = await request_resource(Launcher)
jpterm = Jpterm(
header,
footer,
Expand All @@ -75,4 +79,4 @@ async def start(
launcher,
driver_class=self.driver_class,
)
ctx.add_resource(jpterm, types=App)
await add_resource(jpterm, types=App)
11 changes: 4 additions & 7 deletions plugins/launcher/txl_launcher/components.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from asphalt.core import Component, Context
from asphalt.core import Component, add_resource, request_resource
from textual.widget import Widget
from textual.widgets import Button

Expand Down Expand Up @@ -40,10 +40,7 @@ async def on_button_pressed(self, event: Button.Pressed) -> None:


class LauncherComponent(Component):
async def start(
self,
ctx: Context,
) -> None:
main_area = await ctx.request_resource(MainArea)
async def start(self) -> None:
main_area = await request_resource(MainArea)
launcher = _Launcher(main_area)
ctx.add_resource(launcher, types=Launcher)
await add_resource(launcher, types=Launcher)
9 changes: 3 additions & 6 deletions plugins/local_contents/txl_local_contents/components.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
from typing import List, Union

from anyio import Path
from asphalt.core import Component, Context
from asphalt.core import Component, add_resource
from pycrdt import Doc

from txl.base import Contents
Expand Down Expand Up @@ -50,9 +50,6 @@ async def save(


class LocalContentsComponent(Component):
async def start(
self,
ctx: Context,
) -> None:
async def start(self) -> None:
contents = LocalContents()
ctx.add_resource(contents, types=Contents)
await add_resource(contents, types=Contents)
16 changes: 5 additions & 11 deletions plugins/local_kernels/txl_local_kernels/components.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
from pathlib import Path
from typing import Any

from asphalt.core import Component, Context, context_teardown
from asphalt.core import Component, add_resource, context_teardown
from pycrdt import Map

from txl.base import Kernels, Kernelspecs
Expand Down Expand Up @@ -35,11 +35,8 @@ async def get(self) -> dict[str, Any]:

class LocalKernelsComponent(Component):
@context_teardown
async def start(
self,
ctx: Context,
) -> None:
ctx.add_resource(LocalKernels, types=Kernels)
async def start(self) -> None:
await add_resource(LocalKernels, types=Kernels)

yield

Expand All @@ -48,9 +45,6 @@ async def start(


class LocalKernelspecsComponent(Component):
async def start(
self,
ctx: Context,
) -> None:
async def start(self) -> None:
kernelspecs = LocalKernelspecs()
ctx.add_resource(kernelspecs, types=Kernelspecs)
await add_resource(kernelspecs, types=Kernelspecs)
15 changes: 6 additions & 9 deletions plugins/local_terminals/txl_local_terminals/components.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import os

from asphalt.core import Component, Context
from asphalt.core import Component, add_resource, request_resource

from txl.base import Header, Launcher, TerminalFactory, Terminals

Expand All @@ -11,16 +11,13 @@


class LocalTerminalsComponent(Component):
async def start(
self,
ctx: Context,
) -> None:
header = await ctx.request_resource(Header)
terminal = await ctx.request_resource(TerminalFactory)
launcher = await ctx.request_resource(Launcher)
async def start(self) -> None:
header = await request_resource(Header)
terminal = await request_resource(TerminalFactory)
launcher = await request_resource(Launcher)

def terminals_factory():
return LocalTerminals(header, terminal)

launcher.register("terminal", terminals_factory)
ctx.add_resource(terminals_factory, types=Terminals)
await add_resource(terminals_factory, types=Terminals)
13 changes: 5 additions & 8 deletions plugins/markdown_viewer/txl_markdown_viewer/components.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import asyncio

from asphalt.core import Component, Context
from asphalt.core import Component, add_resource, request_resource
from textual.containers import Container
from textual.widgets import MarkdownViewer as TextualMarkdownViewer

Expand Down Expand Up @@ -42,18 +42,15 @@ def __init__(self, register: bool = True):
super().__init__()
self.register = register

async def start(
self,
ctx: Context,
) -> None:
contents = await ctx.request_resource(Contents)
async def start(self) -> None:
contents = await request_resource(Contents)

def markdown_viewer_factory():
return MarkdownViewer(contents)

if self.register:
editors = await ctx.request_resource(Editors)
editors = await request_resource(Editors)
editors.register_editor_factory(markdown_viewer_factory, [".md"])
else:
markdown_viewer = markdown_viewer_factory()
ctx.add_resource(markdown_viewer, types=Editor)
await add_resource(markdown_viewer, types=Editor)
Loading
Loading