fix dictionary example going down

This commit is contained in:
Will McGugan
2023-02-18 17:57:48 +00:00
parent 16288bd145
commit b6272a3b59
2 changed files with 8 additions and 2 deletions

View File

@@ -11,7 +11,7 @@ from rich.markdown import Markdown
from textual.app import App, ComposeResult
from textual.containers import Content
from textual.widgets import Static, Input
from textual.widgets import Input, Static
class DictionaryApp(App):
@@ -41,7 +41,11 @@ class DictionaryApp(App):
"""Looks up a word."""
url = f"https://api.dictionaryapi.dev/api/v2/entries/en/{word}"
async with httpx.AsyncClient() as client:
results = (await client.get(url)).json()
response = await client.get(url)
if response.status_code % 100 != 2:
self.query_one("#results", Static).update(response.text)
return
results = response.json()
if word == self.query_one(Input).value:
markdown = self.make_word_markdown(results)

View File

@@ -248,6 +248,7 @@ class Compositor:
self._layers = None
self._layers_visible = None
self._visible_widgets = None
self._full_map = None
self.root = parent
self.size = size
@@ -860,6 +861,7 @@ class Compositor:
widget: Widget to update.
"""
self._full_map = None
regions: list[Region] = []
add_region = regions.append
get_widget = self.visible_widgets.__getitem__