display seed, add input validation

This commit is contained in:
Felix Pankratz 2024-05-09 16:13:53 +02:00
parent 1181e75ea0
commit a90adbb165
2 changed files with 17 additions and 4 deletions

View File

@ -5,6 +5,7 @@ from textual.widgets import Header, Footer, Input, Label, Static, Button
from textual.message import Message from textual.message import Message
from textual.color import Color from textual.color import Color
from textual.containers import Horizontal from textual.containers import Horizontal
from textual.validation import Number
from asyncio import sleep from asyncio import sleep
@ -69,12 +70,17 @@ class BingoApp(App):
class BingoDisplay(Static): class BingoDisplay(Static):
def compose(self) -> ComposeResult: def compose(self) -> ComposeResult:
"""Create child widgets for the app.""" """Create child widgets for the app."""
yield BingoBoard() self.board = BingoBoard()
yield self.board
input_field = Input( input_field = Input(
str(self.board.seed),
type='integer', type='integer',
placeholder='UNIX timestamp', placeholder='UNIX timestamp',
max_length=10, max_length=10,
classes='seed_input' classes='seed_input',
validators=[
Number(minimum=1000000000, maximum = int(datetime.now().timestamp()))
]
) )
input_field.border_title = 'Seed' input_field.border_title = 'Seed'
yield Horizontal( yield Horizontal(

View File

@ -15,11 +15,11 @@ BingoDisplay {
} }
.seed_input { .seed_input {
width: 50%; width: 70%;
border-title-align: left; border-title-align: left;
} }
.roll_btn { .roll_btn {
width: 50%; width: 30%;
} }
.box { .box {
@ -28,3 +28,10 @@ BingoDisplay {
text-align: center; text-align: center;
content-align: center middle; content-align: center middle;
} }
Input.-valid {
border: tall $success 60%;
}
Input.-valid:focus {
border: tall $success;
}