Moving DevtoolsLog object to client.py

This commit is contained in:
Darren Burns
2022-04-12 15:18:37 +01:00
parent 6e058cda7c
commit c1b167f48a
4 changed files with 22 additions and 22 deletions

View File

@@ -31,8 +31,8 @@ from ._profile import timer
from .binding import Bindings, NoBinding
from .css.stylesheet import Stylesheet, StylesheetError
from .design import ColorSystem
from .devtools.client import DevtoolsClient, DevtoolsConnectionError
from .devtools.redirect_output import DevtoolsRedirector, DevtoolsLog
from .devtools.client import DevtoolsClient, DevtoolsConnectionError, DevtoolsLog
from .devtools.redirect_output import DevtoolsRedirector
from .dom import DOMNode
from .driver import Driver
from .file_monitor import FileMonitor

View File

@@ -3,24 +3,40 @@ from __future__ import annotations
import asyncio
import base64
import datetime
import inspect
import json
import pickle
from asyncio import Queue, Task, QueueFull
from io import StringIO
from typing import Type, Any
from typing import Type, Any, NamedTuple
import aiohttp
from aiohttp import ClientResponseError, ClientConnectorError, ClientWebSocketResponse
from rich.console import Console
from rich.segment import Segment
from textual.devtools.redirect_output import DevtoolsLog
DEFAULT_PORT = 8081
WEBSOCKET_CONNECT_TIMEOUT = 3
LOG_QUEUE_MAXSIZE = 512
class DevtoolsLog(NamedTuple):
"""A devtools log message.
Attributes:
objects_or_string (tuple[Any, ...]): Corresponds to the data that will
ultimately be passed to Console.print in order to generate the log
Segments.
caller (inspect.FrameInfo): Information about where this log message was
created. In other words, where did the user call `print` or `App.log`
from. Used to display line number and file name in the devtools window.
"""
objects_or_string: tuple[Any, ...] | str
caller: inspect.FrameInfo | None = None
class DevtoolsConsole(Console):
def __init__(self, *args, **kwargs) -> None:
super().__init__(*args, **kwargs)

View File

@@ -1,28 +1,13 @@
from __future__ import annotations
import inspect
from typing import NamedTuple, Any, TYPE_CHECKING
from typing import TYPE_CHECKING
from textual.devtools.client import DevtoolsLog
if TYPE_CHECKING:
from textual.devtools.client import DevtoolsClient
class DevtoolsLog(NamedTuple):
"""A devtools log message.
Attributes:
objects_or_string (tuple[Any, ...]): Corresponds to the data that will
ultimately be passed to Console.print in order to generate the log
Segments.
caller (inspect.FrameInfo): Information about where this log message was
created. In other words, where did the user call `print` or `App.log`
from. Used to display line number and file name in the devtools window.
"""
objects_or_string: tuple[Any, ...] | str
caller: inspect.FrameInfo | None = None
class DevtoolsRedirector:
"""
A file-like object which redirects anything written to it to the devtools instance

View File

@@ -18,7 +18,6 @@ from . import messages
if TYPE_CHECKING:
from .app import App
from .screen import Screen
class NoParent(Exception):