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

@ -1,6 +1,25 @@
Screen { BingoBoard {
layout: grid; layout: grid;
grid-size: 5 5; 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 { .box {

Loading…
Cancel
Save