docstrings and fixes

This commit is contained in:
Will McGugan
2022-05-24 09:30:10 +01:00
parent 0e2f4097e9
commit e6a9a37f80
4 changed files with 17 additions and 9 deletions

View File

@@ -10,19 +10,19 @@ Creating a TUI can be challenging. It may be easier to create a GUI or web appli
Textual seeks to lower the difficulty level of building a TUI by borrowing developments from the web world and to a lesser extent desktop applications. The goal is for it to be as easy to develop a TUI for your project as it would be to add a command line interface.XX Textual seeks to lower the difficulty level of building a TUI by borrowing developments from the web world and to a lesser extent desktop applications. The goal is for it to be as easy to develop a TUI for your project as it would be to add a command line interface.XX
=== "Python" === "simple.py"
```python ```python
--8<-- "docs/examples/simple.py" --8<-- "docs/examples/simple.py"
``` ```
=== "CSS" === "simple.css"
```python ```scss
--8<-- "docs/examples/simple.css" --8<-- "docs/examples/simple.css"
``` ```
=== "Terminal" === "Result"
```{.textual path="docs/examples/simple.py" columns="80" lines="24"} ```{.textual path="docs/examples/simple.py" columns="80" lines="24"}
``` ```

6
poetry.lock generated
View File

@@ -650,7 +650,7 @@ pyyaml = "*"
[[package]] [[package]]
name = "rich" name = "rich"
version = "12.4.3" version = "12.4.4"
description = "Render rich text, tables, progress bars, syntax highlighting, markdown and more to the terminal" description = "Render rich text, tables, progress bars, syntax highlighting, markdown and more to the terminal"
category = "main" category = "main"
optional = false optional = false
@@ -1360,8 +1360,8 @@ pyyaml-env-tag = [
{file = "pyyaml_env_tag-0.1.tar.gz", hash = "sha256:70092675bda14fdec33b31ba77e7543de9ddc88f2e5b99160396572d11525bdb"}, {file = "pyyaml_env_tag-0.1.tar.gz", hash = "sha256:70092675bda14fdec33b31ba77e7543de9ddc88f2e5b99160396572d11525bdb"},
] ]
rich = [ rich = [
{file = "rich-12.4.3-py3-none-any.whl", hash = "sha256:26ef784599a9ab905ade34ff28904e4fbe9bce16e02c33c78b0229551104c146"}, {file = "rich-12.4.4-py3-none-any.whl", hash = "sha256:d2bbd99c320a2532ac71ff6a3164867884357da3e3301f0240090c5d2fdac7ec"},
{file = "rich-12.4.3.tar.gz", hash = "sha256:e7550ca19aec51b216ae4c34bfce82e94a0c79bdbf95cafbf42f343d0fb3f45a"}, {file = "rich-12.4.4.tar.gz", hash = "sha256:4c586de507202505346f3e32d1363eb9ed6932f0c2f63184dea88983ff4971e2"},
] ]
six = [ six = [
{file = "six-1.16.0-py2.py3-none-any.whl", hash = "sha256:8abb2f1d86890a2dfb989f9a77cfcfd3e47c2a354b01111771326f8aa26e0254"}, {file = "six-1.16.0-py2.py3-none-any.whl", hash = "sha256:8abb2f1d86890a2dfb989f9a77cfcfd3e47c2a354b01111771326f8aa26e0254"},

View File

@@ -763,6 +763,11 @@ class App(Generic[ReturnType], DOMNode):
self._log_console = None self._log_console = None
async def _ready(self) -> None: async def _ready(self) -> None:
"""Called immediately prior to processing messages.
May be used as a hook for any operations that should run first.
"""
try: try:
screenshot_timer = float(os.environ.get("TEXTUAL_SCREENSHOT", "0")) screenshot_timer = float(os.environ.get("TEXTUAL_SCREENSHOT", "0"))
except ValueError: except ValueError:
@@ -772,8 +777,9 @@ class App(Generic[ReturnType], DOMNode):
return return
async def on_screenshot(): async def on_screenshot():
"""Used by docs plugin."""
svg = self.export_screenshot() svg = self.export_screenshot()
self._screenshot = svg self._screenshot = svg # type: ignore
await self.shutdown() await self.shutdown()
self.set_timer(screenshot_timer, on_screenshot) self.set_timer(screenshot_timer, on_screenshot)
@@ -880,7 +886,7 @@ class App(Generic[ReturnType], DOMNode):
Args: Args:
renderable (RenderableType): A Rich renderable. renderable (RenderableType): A Rich renderable.
""" """
if self._running and not self._closed: if self._running and not self._closed and not self.is_headless:
console = self.console console = self.console
if self._sync_available: if self._sync_available:
console.file.write("\x1bP=1s\x1b\\") console.file.write("\x1bP=1s\x1b\\")

View File

@@ -399,6 +399,8 @@ class Widget(DOMNode):
scrolled_x = scrolled_y = False scrolled_x = scrolled_y = False
if animate: if animate:
# TODO: configure animation speed # TODO: configure animation speed
if duration is None and speed is None:
speed = 50
if x is not None: if x is not None:
self.scroll_target_x = x self.scroll_target_x = x
if x != self.scroll_x: if x != self.scroll_x: