add inputs, refactor a bit

1-reproducible-board
Felix Pankratz 5 months ago
parent b8e0943b07
commit 1181e75ea0

@ -1,10 +1,10 @@
#!/usr/bin/env python3
from textual.app import App, ComposeResult
from textual.widgets import Header, Footer, Button, Label, Switch, Static
from textual.containers import ScrollableContainer
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 asyncio import sleep
@ -51,11 +51,40 @@ class BingoField(Static):
return str(self.text)
class BingoApp(App):
"""A Textual app to manage stopwatches."""
"""A Textual app to run a Bingo board."""
CSS_PATH = "bingo.tcss"
BINDINGS = [("d", "toggle_dark", "Toggle dark mode")]
def compose(self) -> ComposeResult:
"""Create child widgets for the app."""
yield Header()
yield BingoDisplay()
yield Footer()
def action_toggle_dark(self) -> None:
"""An action to toggle dark mode."""
self.dark = not self.dark
class BingoDisplay(Static):
def compose(self) -> ComposeResult:
"""Create child widgets for the app."""
yield BingoBoard()
input_field = Input(
type='integer',
placeholder='UNIX timestamp',
max_length=10,
classes='seed_input'
)
input_field.border_title = 'Seed'
yield Horizontal(
input_field,
Button('re-roll', classes='roll_btn'),
classes='bottom_line'
)
class BingoBoard(Static):
fieldstate = [False for _ in range(25)]
fields = [
@ -93,13 +122,9 @@ class BingoApp(App):
def compose(self) -> ComposeResult:
"""Create child widgets for the app."""
yield Header()
for _ in range(25):
yield BingoField(_, self.fields[_])
yield Footer()
async def on_bingo_field_selected(self, message: BingoField.Selected) -> None:
self.fieldstate[message.num] = message.selected
if self.is_bingo():
@ -143,10 +168,6 @@ class BingoApp(App):
])
return bingo
def action_toggle_dark(self) -> None:
"""An action to toggle dark mode."""
self.dark = not self.dark
if __name__ == "__main__":
app = BingoApp()
app.run()

@ -1,6 +1,25 @@
Screen {
BingoBoard {
layout: grid;
grid-size: 5 5;
height: 100%;
}
BingoDisplay {
layout: vertical;
height: 100%;
}
.bottom_line {
height: auto;
dock: bottom;
}
.seed_input {
width: 50%;
border-title-align: left;
}
.roll_btn {
width: 50%;
}
.box {

Loading…
Cancel
Save