remove boilerplate

This commit is contained in:
Will McGugan
2021-08-13 21:11:26 +01:00
parent ed477c5682
commit 43016e2b9d
6 changed files with 21 additions and 18 deletions

View File

@@ -54,7 +54,7 @@ class FigletText:
class Numbers(Widget):
"""The digital display of the calculator."""
value: Reactive[str] = Reactive("0")
value = Reactive("0")
def render(self) -> RenderableType:
"""Build a Rich renderable to render the calculator display."""
@@ -84,10 +84,10 @@ class Calculator(GridView):
"=": YELLOW,
}
display: Reactive[str] = Reactive("0")
show_ac: Reactive[bool] = Reactive(True)
display = Reactive("0")
show_ac = Reactive(True)
async def watch_display(self, value: str) -> None:
def watch_display(self, value: str) -> None:
"""Called when self.display is modified."""
# self.numbers is a widget that displays the calculator result
# Setting the attribute value changes the display
@@ -99,13 +99,13 @@ class Calculator(GridView):
# Condition to show AC button over C
return self.value in ("", "0") and self.display == "0"
async def watch_show_ac(self, show_ac: bool) -> None:
def watch_show_ac(self, show_ac: bool) -> None:
"""When the show_ac attribute change we need to update the buttons."""
# Show AC and hide C or vice versa
self.c.visible = not show_ac
self.ac.visible = show_ac
async def on_mount(self, event: events.Mount) -> None:
def on_mount(self) -> None:
"""Event when widget is first mounted (added to a parent view)."""
# Attributes to store the current calculation
@@ -153,7 +153,7 @@ class Calculator(GridView):
*self.buttons.values(), clear=self.ac, numbers=self.numbers, zero=self.zero
)
async def message_button_pressed(self, message: ButtonPressed) -> None:
def message_button_pressed(self, message: ButtonPressed) -> None:
"""A message sent by the button widget"""
assert isinstance(message.sender, Button)

View File

@@ -5,7 +5,6 @@ from rich.console import RenderableType
from rich.syntax import Syntax
from rich.traceback import Traceback
from textual import events
from textual.app import App
from textual.widgets import Header, Footer, FileClick, ScrollView, DirectoryTree
@@ -13,7 +12,7 @@ from textual.widgets import Header, Footer, FileClick, ScrollView, DirectoryTree
class MyApp(App):
"""An example of a very simple Textual App"""
async def on_load(self, event: events.Load) -> None:
async def on_load(self) -> None:
"""Sent before going in to application mode."""
# Bind our basic keys
@@ -28,7 +27,7 @@ class MyApp(App):
os.path.join(os.path.basename(__file__), "../../")
)
async def on_mount(self, event: events.Mount) -> None:
async def on_mount(self) -> None:
"""Call after terminal goes in to application mode"""
# Create our widgets

View File

@@ -4,7 +4,7 @@ from textual.widgets import Placeholder
class GridTest(App):
async def on_mount(self, event: events.Mount) -> None:
async def on_mount(self) -> None:
"""Make a simple grid arrangement."""
grid = await self.view.dock_grid(edge="left", size=70, name="left")