mirror of
https://github.com/Textualize/textual.git
synced 2025-10-17 02:38:12 +03:00
fix for simple app case
This commit is contained in:
4
Makefile
4
Makefile
@@ -6,3 +6,7 @@ format:
|
||||
black src
|
||||
format-check:
|
||||
black --check src
|
||||
docs-serve:
|
||||
mkdocs serve
|
||||
docs-build:
|
||||
mkdocs build
|
||||
|
||||
@@ -16,7 +16,3 @@ class Clock(Widget):
|
||||
class ClockApp(App):
|
||||
def compose(self):
|
||||
yield Clock()
|
||||
|
||||
|
||||
app = ClockApp()
|
||||
app.run()
|
||||
|
||||
@@ -7,6 +7,7 @@ import io
|
||||
import os
|
||||
import platform
|
||||
import sys
|
||||
import string
|
||||
import warnings
|
||||
from contextlib import redirect_stdout
|
||||
from pathlib import PurePath
|
||||
@@ -108,6 +109,10 @@ class App(Generic[ReturnType], DOMNode):
|
||||
"""The base class for Textual Applications"""
|
||||
|
||||
CSS = """
|
||||
$WIDGET {
|
||||
background: $surface;
|
||||
color: $text-surface;
|
||||
}
|
||||
"""
|
||||
|
||||
CSS_PATH: str | None = None
|
||||
@@ -721,8 +726,11 @@ class App(Generic[ReturnType], DOMNode):
|
||||
if self.css_path is not None:
|
||||
self.stylesheet.read(self.css_path)
|
||||
if self.CSS is not None:
|
||||
css_code = string.Template(self.CSS).safe_substitute(
|
||||
{"WIDGET": self.css_type}
|
||||
)
|
||||
self.stylesheet.add_source(
|
||||
self.CSS, path=f"<{self.__class__.__name__}>"
|
||||
css_code, path=f"<{self.__class__.__name__}>"
|
||||
)
|
||||
except Exception as error:
|
||||
self.on_exception(error)
|
||||
@@ -875,6 +883,8 @@ class App(Generic[ReturnType], DOMNode):
|
||||
|
||||
def refresh(self, *, repaint: bool = True, layout: bool = False) -> None:
|
||||
self.screen.refresh(repaint=repaint, layout=layout)
|
||||
self.check_idle()
|
||||
# self.screen._refresh_layout()
|
||||
|
||||
def _paint(self):
|
||||
"""Perform a "paint" (draw the screen)."""
|
||||
@@ -1062,10 +1072,12 @@ class App(Generic[ReturnType], DOMNode):
|
||||
async def handle_update(self, message: messages.Update) -> None:
|
||||
message.stop()
|
||||
self._paint()
|
||||
print("UPDATE PAINT")
|
||||
|
||||
async def handle_layout(self, message: messages.Layout) -> None:
|
||||
message.stop()
|
||||
self._paint()
|
||||
print("LAYOUT PAINT")
|
||||
|
||||
async def on_key(self, event: events.Key) -> None:
|
||||
if event.key == "tab":
|
||||
|
||||
@@ -194,8 +194,6 @@ 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):
|
||||
@@ -203,28 +201,20 @@ 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:
|
||||
|
||||
@@ -268,6 +268,7 @@ class MessagePump:
|
||||
self.app.on_exception(error)
|
||||
break
|
||||
finally:
|
||||
self._message_queue.task_done()
|
||||
if self._message_queue.empty():
|
||||
if not self._closed:
|
||||
event = events.Idle(self)
|
||||
|
||||
@@ -30,9 +30,7 @@ class Screen(Widget):
|
||||
"""A widget for the root of the app."""
|
||||
|
||||
CSS = """
|
||||
Screen {
|
||||
background: $surface;
|
||||
color: $text-surface;
|
||||
$WIDGET {
|
||||
layout: vertical;
|
||||
overflow-y: auto;
|
||||
}
|
||||
@@ -114,20 +112,19 @@ class Screen(Widget):
|
||||
def on_idle(self, event: events.Idle) -> None:
|
||||
# Check for any widgets marked as 'dirty' (needs a repaint)
|
||||
event.prevent_default()
|
||||
|
||||
if self._layout_required:
|
||||
self._refresh_layout()
|
||||
self._layout_required = False
|
||||
self._dirty_widgets.clear()
|
||||
elif self._dirty_widgets:
|
||||
elif self._dirty_widgets or self._dirty_regions:
|
||||
self.update_timer.resume()
|
||||
|
||||
def _on_update(self) -> None:
|
||||
"""Called by the _update_timer."""
|
||||
# Render widgets together
|
||||
|
||||
if self._dirty_widgets:
|
||||
if self._dirty_widgets or self._dirty_regions:
|
||||
self._compositor.update_widgets(self._dirty_widgets)
|
||||
self._compositor.add_dirty_regions(self._dirty_regions)
|
||||
self.app._display(self._compositor.render())
|
||||
self._dirty_widgets.clear()
|
||||
self.update_timer.pause()
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
from __future__ import annotations
|
||||
|
||||
from fractions import Fraction
|
||||
import string
|
||||
from typing import (
|
||||
Any,
|
||||
Awaitable,
|
||||
@@ -23,7 +24,6 @@ from . import errors
|
||||
from . import events
|
||||
from ._animator import BoundAnimator
|
||||
from ._border import Border
|
||||
from ._profile import timer
|
||||
from .box_model import BoxModel, get_box_model
|
||||
from ._context import active_app
|
||||
from ._types import Lines
|
||||
@@ -35,7 +35,6 @@ from .message import Message
|
||||
from . import messages
|
||||
from ._layout import Layout
|
||||
from .reactive import Reactive, watch
|
||||
from .renderables.blank import Blank
|
||||
from .renderables.opacity import Opacity
|
||||
from .renderables.tint import Tint
|
||||
|
||||
@@ -178,9 +177,10 @@ class Widget(DOMNode):
|
||||
Args:
|
||||
app (App): App instance.
|
||||
"""
|
||||
css_code = string.Template(self.CSS).safe_substitute({"WIDGET": self.css_type})
|
||||
# Parser the Widget's CSS
|
||||
self.app.stylesheet.add_source(
|
||||
self.CSS, f"{__file__}:<{self.__class__.__name__}>"
|
||||
css_code, f"{__file__}:<{self.__class__.__name__}>"
|
||||
)
|
||||
|
||||
def get_box_model(
|
||||
|
||||
@@ -17,7 +17,7 @@ class Button(Widget, can_focus=True):
|
||||
|
||||
CSS = """
|
||||
|
||||
Button {
|
||||
$WIDGET {
|
||||
width: auto;
|
||||
height: 3;
|
||||
background: $primary;
|
||||
@@ -29,13 +29,13 @@ class Button(Widget, can_focus=True):
|
||||
text-style: bold;
|
||||
}
|
||||
|
||||
Button:hover {
|
||||
$WIDGET:hover {
|
||||
background:$primary-darken-2;
|
||||
color: $text-primary-darken-2;
|
||||
border: tall $primary-lighten-1;
|
||||
}
|
||||
|
||||
App.-show-focus Button:focus {
|
||||
App.-show-focus $WIDGET:focus {
|
||||
tint: $accent 20%;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user