mirror of
https://github.com/Textualize/textual.git
synced 2025-10-17 02:38:12 +03:00
Merge pull request #958 from davep/toll-free
Review the use of the bell in various examples and documentation files
This commit is contained in:
@@ -5,7 +5,6 @@ from textual import events
|
|||||||
class ActionsApp(App):
|
class ActionsApp(App):
|
||||||
def action_set_background(self, color: str) -> None:
|
def action_set_background(self, color: str) -> None:
|
||||||
self.screen.styles.background = color
|
self.screen.styles.background = color
|
||||||
self.bell()
|
|
||||||
|
|
||||||
def on_key(self, event: events.Key) -> None:
|
def on_key(self, event: events.Key) -> None:
|
||||||
if event.key == "r":
|
if event.key == "r":
|
||||||
|
|||||||
@@ -5,7 +5,6 @@ from textual import events
|
|||||||
class ActionsApp(App):
|
class ActionsApp(App):
|
||||||
def action_set_background(self, color: str) -> None:
|
def action_set_background(self, color: str) -> None:
|
||||||
self.screen.styles.background = color
|
self.screen.styles.background = color
|
||||||
self.bell()
|
|
||||||
|
|
||||||
async def on_key(self, event: events.Key) -> None:
|
async def on_key(self, event: events.Key) -> None:
|
||||||
if event.key == "r":
|
if event.key == "r":
|
||||||
|
|||||||
@@ -15,7 +15,6 @@ class ActionsApp(App):
|
|||||||
|
|
||||||
def action_set_background(self, color: str) -> None:
|
def action_set_background(self, color: str) -> None:
|
||||||
self.screen.styles.background = color
|
self.screen.styles.background = color
|
||||||
self.bell()
|
|
||||||
|
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
|
|||||||
@@ -21,7 +21,6 @@ class ActionsApp(App):
|
|||||||
|
|
||||||
def action_set_background(self, color: str) -> None:
|
def action_set_background(self, color: str) -> None:
|
||||||
self.screen.styles.background = color
|
self.screen.styles.background = color
|
||||||
self.bell()
|
|
||||||
|
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
|
|||||||
@@ -28,7 +28,6 @@ class ActionsApp(App):
|
|||||||
|
|
||||||
def action_set_background(self, color: str) -> None:
|
def action_set_background(self, color: str) -> None:
|
||||||
self.screen.styles.background = color
|
self.screen.styles.background = color
|
||||||
self.bell()
|
|
||||||
|
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
|
|||||||
@@ -12,9 +12,6 @@ class InputApp(App):
|
|||||||
def on_key(self, event: events.Key) -> None:
|
def on_key(self, event: events.Key) -> None:
|
||||||
self.query_one(TextLog).write(event)
|
self.query_one(TextLog).write(event)
|
||||||
|
|
||||||
def key_space(self) -> None:
|
|
||||||
self.bell()
|
|
||||||
|
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
app = InputApp()
|
app = InputApp()
|
||||||
|
|||||||
@@ -1,9 +0,0 @@
|
|||||||
from textual.app import App
|
|
||||||
|
|
||||||
|
|
||||||
class ExampleApp(App):
|
|
||||||
pass
|
|
||||||
|
|
||||||
|
|
||||||
app = ExampleApp()
|
|
||||||
app.run()
|
|
||||||
@@ -1,29 +0,0 @@
|
|||||||
from textual.app import App
|
|
||||||
|
|
||||||
|
|
||||||
class ExampleApp(App):
|
|
||||||
|
|
||||||
COLORS = [
|
|
||||||
"white",
|
|
||||||
"maroon",
|
|
||||||
"red",
|
|
||||||
"purple",
|
|
||||||
"fuchsia",
|
|
||||||
"olive",
|
|
||||||
"yellow",
|
|
||||||
"navy",
|
|
||||||
"teal",
|
|
||||||
"aqua",
|
|
||||||
]
|
|
||||||
|
|
||||||
def on_mount(self):
|
|
||||||
self.styles.background = "darkblue"
|
|
||||||
|
|
||||||
def on_key(self, event):
|
|
||||||
if event.key.isdigit():
|
|
||||||
self.styles.background = self.COLORS[int(event.key)]
|
|
||||||
self.bell()
|
|
||||||
|
|
||||||
|
|
||||||
app = ExampleApp()
|
|
||||||
app.run()
|
|
||||||
@@ -27,7 +27,6 @@ class ButtonsApp(App[str]):
|
|||||||
)
|
)
|
||||||
|
|
||||||
def on_button_pressed(self, event: Button.Pressed) -> None:
|
def on_button_pressed(self, event: Button.Pressed) -> None:
|
||||||
self.app.bell()
|
|
||||||
self.exit(str(event.button))
|
self.exit(str(event.button))
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -12,7 +12,7 @@ Action methods are methods on your app or widgets prefixed with `action_`. Aside
|
|||||||
|
|
||||||
Let's write an app with a simple action.
|
Let's write an app with a simple action.
|
||||||
|
|
||||||
```python title="actions01.py" hl_lines="6-8 12"
|
```python title="actions01.py" hl_lines="6-7 11"
|
||||||
--8<-- "docs/examples/guide/actions/actions01.py"
|
--8<-- "docs/examples/guide/actions/actions01.py"
|
||||||
```
|
```
|
||||||
|
|
||||||
@@ -22,7 +22,7 @@ Although it is possible (and occasionally useful) to call action methods in this
|
|||||||
|
|
||||||
The following example replaces the immediate call with a call to [action()][textual.widgets.Widget.action] which parses an action string and dispatches it to the appropriate method.
|
The following example replaces the immediate call with a call to [action()][textual.widgets.Widget.action] which parses an action string and dispatches it to the appropriate method.
|
||||||
|
|
||||||
```python title="actions02.py" hl_lines="10-12"
|
```python title="actions02.py" hl_lines="9-11"
|
||||||
--8<-- "docs/examples/guide/actions/actions02.py"
|
--8<-- "docs/examples/guide/actions/actions02.py"
|
||||||
```
|
```
|
||||||
|
|
||||||
@@ -71,7 +71,7 @@ The following example mounts simple static text with embedded action links.
|
|||||||
```{.textual path="docs/examples/guide/actions/actions03.py"}
|
```{.textual path="docs/examples/guide/actions/actions03.py"}
|
||||||
```
|
```
|
||||||
|
|
||||||
When you click any of the links, Textual runs the `"set_background"` action to change the background to the given color and plays the terminal's bell.
|
When you click any of the links, Textual runs the `"set_background"` action to change the background to the given color.
|
||||||
|
|
||||||
## Bindings
|
## Bindings
|
||||||
|
|
||||||
|
|||||||
@@ -46,7 +46,7 @@ Textual offers a convenient way of handling specific keys. If you create a metho
|
|||||||
Let's add a key method to the example code.
|
Let's add a key method to the example code.
|
||||||
|
|
||||||
```python title="key02.py" hl_lines="15-16"
|
```python title="key02.py" hl_lines="15-16"
|
||||||
--8<-- "docs/examples/guide/input/key01.py"
|
--8<-- "docs/examples/guide/input/key02.py"
|
||||||
```
|
```
|
||||||
|
|
||||||
Note the addition of a `key_space` method which is called in response to the space key, and plays the terminal bell noise.
|
Note the addition of a `key_space` method which is called in response to the space key, and plays the terminal bell noise.
|
||||||
|
|||||||
@@ -10,7 +10,7 @@ when it has focus.
|
|||||||
## Example
|
## Example
|
||||||
|
|
||||||
The example below shows each button variant, and its disabled equivalent.
|
The example below shows each button variant, and its disabled equivalent.
|
||||||
Clicking any of the non-disabled buttons in the example app below will result in a ring of the terminal bell.
|
Clicking any of the non-disabled buttons in the example app below will result the app exiting and the details of the selected button being printed to the console.
|
||||||
|
|
||||||
=== "Output"
|
=== "Output"
|
||||||
|
|
||||||
|
|||||||
@@ -93,8 +93,6 @@ class CalculatorApp(App):
|
|||||||
button_id = event.button.id
|
button_id = event.button.id
|
||||||
assert button_id is not None
|
assert button_id is not None
|
||||||
|
|
||||||
self.bell() # Terminal bell
|
|
||||||
|
|
||||||
def do_math() -> None:
|
def do_math() -> None:
|
||||||
"""Does the math: LEFT OPERATOR RIGHT"""
|
"""Does the math: LEFT OPERATOR RIGHT"""
|
||||||
try:
|
try:
|
||||||
|
|||||||
@@ -56,7 +56,6 @@ class BorderApp(App):
|
|||||||
event.button.id,
|
event.button.id,
|
||||||
self.stylesheet._variables["secondary"],
|
self.stylesheet._variables["secondary"],
|
||||||
)
|
)
|
||||||
self.bell()
|
|
||||||
|
|
||||||
|
|
||||||
app = BorderApp()
|
app = BorderApp()
|
||||||
|
|||||||
Reference in New Issue
Block a user