mirror of
https://github.com/Textualize/textual.git
synced 2025-10-17 02:38:12 +03:00
docs update
This commit is contained in:
18
docs/examples/light_dark.py
Normal file
18
docs/examples/light_dark.py
Normal file
@@ -0,0 +1,18 @@
|
||||
from textual.app import App
|
||||
from textual.widgets import Button
|
||||
|
||||
|
||||
class ButtonApp(App):
|
||||
CSS = """
|
||||
Button {
|
||||
width: 100%;
|
||||
}
|
||||
"""
|
||||
|
||||
def compose(self):
|
||||
yield Button("Light", id="light")
|
||||
yield Button("Dark", id="dark")
|
||||
|
||||
def handle_pressed(self, event):
|
||||
self.dark = event.button.id == "dark"
|
||||
|
||||
BIN
docs/images/dom.excalidraw.png
Normal file
BIN
docs/images/dom.excalidraw.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 58 KiB |
BIN
docs/images/events.excalidraw.png
Normal file
BIN
docs/images/events.excalidraw.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 446 KiB |
BIN
docs/images/message_pump.excalidraw.png
Normal file
BIN
docs/images/message_pump.excalidraw.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 190 KiB |
@@ -675,6 +675,10 @@ class App(Generic[ReturnType], DOMNode):
|
||||
error (Exception): An exception instance.
|
||||
"""
|
||||
|
||||
if "tb" in self.features:
|
||||
self.fatal_error()
|
||||
return
|
||||
|
||||
if hasattr(error, "__rich__"):
|
||||
# Exception has a rich method, so we can defer to that for the rendering
|
||||
self.panic(error)
|
||||
@@ -736,8 +740,8 @@ class App(Generic[ReturnType], DOMNode):
|
||||
|
||||
driver = self._driver = self.driver_class(self.console, self)
|
||||
driver.start_application_mode()
|
||||
with redirect_stdout(StdoutRedirector(self.devtools, self._log_file)): # type: ignore
|
||||
try:
|
||||
try:
|
||||
with redirect_stdout(StdoutRedirector(self.devtools, self._log_file)): # type: ignore
|
||||
mount_event = events.Mount(sender=self)
|
||||
await self.dispatch_message(mount_event)
|
||||
|
||||
@@ -749,8 +753,8 @@ class App(Generic[ReturnType], DOMNode):
|
||||
await super().process_messages()
|
||||
await self.animator.stop()
|
||||
await self.close_all()
|
||||
finally:
|
||||
driver.stop_application_mode()
|
||||
finally:
|
||||
driver.stop_application_mode()
|
||||
except Exception as error:
|
||||
self.on_exception(error)
|
||||
finally:
|
||||
@@ -886,7 +890,7 @@ class App(Generic[ReturnType], DOMNode):
|
||||
stylesheet.set_variables(self.get_css_variables())
|
||||
stylesheet.reparse()
|
||||
stylesheet.update(self.app, animate=animate)
|
||||
self.refresh(layout=True)
|
||||
self.screen._refresh_layout(self.size, full=True)
|
||||
|
||||
def _display(self, renderable: RenderableType | None) -> None:
|
||||
"""Display a renderable within a sync.
|
||||
|
||||
@@ -160,10 +160,10 @@ class LinuxDriver(Driver):
|
||||
if not self.exit_event.is_set():
|
||||
signal.signal(signal.SIGWINCH, signal.SIG_DFL)
|
||||
self._disable_mouse_support()
|
||||
termios.tcflush(self.fileno, termios.TCIFLUSH)
|
||||
self.exit_event.set()
|
||||
if self._key_thread is not None:
|
||||
self._key_thread.join()
|
||||
termios.tcflush(self.fileno, termios.TCIFLUSH)
|
||||
except Exception as error:
|
||||
# TODO: log this
|
||||
pass
|
||||
@@ -194,6 +194,8 @@ class LinuxDriver(Driver):
|
||||
|
||||
fileno = self.fileno
|
||||
|
||||
print(1)
|
||||
|
||||
def more_data() -> bool:
|
||||
"""Check if there is more data to parse."""
|
||||
for key, events in selector.select(0.01):
|
||||
@@ -201,24 +203,32 @@ class LinuxDriver(Driver):
|
||||
return True
|
||||
return False
|
||||
|
||||
print(2)
|
||||
parser = XTermParser(self._target, more_data, self._debug)
|
||||
feed = parser.feed
|
||||
|
||||
utf8_decoder = getincrementaldecoder("utf-8")().decode
|
||||
decode = utf8_decoder
|
||||
read = os.read
|
||||
|
||||
print(3)
|
||||
EVENT_READ = selectors.EVENT_READ
|
||||
|
||||
try:
|
||||
print(4)
|
||||
while not self.exit_event.is_set():
|
||||
print(5)
|
||||
selector_events = selector.select(0.1)
|
||||
print(6)
|
||||
for _selector_key, mask in selector_events:
|
||||
print(7)
|
||||
if mask | EVENT_READ:
|
||||
print(8)
|
||||
unicode_data = decode(read(fileno, 1024))
|
||||
print(9)
|
||||
for event in feed(unicode_data):
|
||||
self.process_event(event)
|
||||
except Exception as error:
|
||||
print(10)
|
||||
log(error)
|
||||
finally:
|
||||
with timer("selector.close"):
|
||||
|
||||
@@ -31,6 +31,8 @@ class Screen(Widget):
|
||||
|
||||
CSS = """
|
||||
Screen {
|
||||
background: $surface;
|
||||
color: $text-surface;
|
||||
layout: vertical;
|
||||
overflow-y: auto;
|
||||
}
|
||||
|
||||
@@ -20,12 +20,12 @@ class Button(Widget, can_focus=True):
|
||||
Button {
|
||||
width: auto;
|
||||
height: 3;
|
||||
padding: 0 2;
|
||||
background: $primary;
|
||||
color: $text-primary;
|
||||
content-align: center middle;
|
||||
border: tall $primary-lighten-3;
|
||||
margin: 1 0;
|
||||
align: center middle;
|
||||
text-style: bold;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user