From a90adbb16549955e156c7733b13aecf16ebc1615 Mon Sep 17 00:00:00 2001 From: Felix Pankratz Date: Thu, 9 May 2024 16:13:53 +0200 Subject: [PATCH] display seed, add input validation --- bingo.py | 10 ++++++++-- bingo.tcss | 11 +++++++++-- 2 files changed, 17 insertions(+), 4 deletions(-) diff --git a/bingo.py b/bingo.py index e3bd527..f13418d 100644 --- a/bingo.py +++ b/bingo.py @@ -5,6 +5,7 @@ from textual.widgets import Header, Footer, Input, Label, Static, Button from textual.message import Message from textual.color import Color from textual.containers import Horizontal +from textual.validation import Number from asyncio import sleep @@ -69,12 +70,17 @@ class BingoApp(App): class BingoDisplay(Static): def compose(self) -> ComposeResult: """Create child widgets for the app.""" - yield BingoBoard() + self.board = BingoBoard() + yield self.board input_field = Input( + str(self.board.seed), type='integer', placeholder='UNIX timestamp', max_length=10, - classes='seed_input' + classes='seed_input', + validators=[ + Number(minimum=1000000000, maximum = int(datetime.now().timestamp())) + ] ) input_field.border_title = 'Seed' yield Horizontal( diff --git a/bingo.tcss b/bingo.tcss index 43a57f2..5161d28 100644 --- a/bingo.tcss +++ b/bingo.tcss @@ -15,11 +15,11 @@ BingoDisplay { } .seed_input { - width: 50%; + width: 70%; border-title-align: left; } .roll_btn { - width: 50%; + width: 30%; } .box { @@ -28,3 +28,10 @@ BingoDisplay { text-align: center; content-align: center middle; } + +Input.-valid { + border: tall $success 60%; +} +Input.-valid:focus { + border: tall $success; +}