|
|
|
#!/usr/bin/env python3
|
|
|
|
|
|
|
|
from textual.app import App, ComposeResult
|
|
|
|
from textual.widgets import Header, Input, Static, Button
|
|
|
|
from textual.containers import Horizontal
|
|
|
|
from textual.validation import Number
|
|
|
|
|
|
|
|
from datetime import datetime
|
|
|
|
|
|
|
|
from BingoBoard import BingoBoard
|
|
|
|
|
|
|
|
class BingoApp(App):
|
|
|
|
'''A Textual app to run a Bingo board.'''
|
|
|
|
CSS_PATH = "bingo.tcss"
|
|
|
|
|
|
|
|
def compose(self) -> ComposeResult:
|
|
|
|
'''Create child widgets for the app.'''
|
|
|
|
yield Header()
|
|
|
|
yield BingoDisplay()
|
|
|
|
|
|
|
|
def on_mount(self) -> None:
|
|
|
|
self.title = 'CCC Bingo'
|
|
|
|
self.sub_title = 'GPN22 Edition'
|
|
|
|
|
|
|
|
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.'''
|
|
|
|
self.board = BingoBoard()
|
|
|
|
yield self.board
|
|
|
|
self.input_field = Input(
|
|
|
|
str(self.board.seed),
|
|
|
|
type='integer',
|
|
|
|
placeholder='UNIX timestamp',
|
|
|
|
max_length=10,
|
|
|
|
classes='seed_input',
|
|
|
|
validators=[
|
|
|
|
Number(minimum=1000000000, maximum = 2000000000)
|
|
|
|
]
|
|
|
|
)
|
|
|
|
self.input_field.border_title = 'Seed'
|
|
|
|
yield Horizontal(
|
|
|
|
self.input_field,
|
|
|
|
Button.error(':game_die: re-roll', classes='roll_btn'),
|
|
|
|
classes='bottom_line'
|
|
|
|
)
|
|
|
|
|
|
|
|
def on_button_pressed(self, event: Button.Pressed) -> None:
|
|
|
|
'''Re-roll the board state with current time as seed'''
|
|
|
|
self.board.roll_board(int(datetime.now().timestamp()))
|
|
|
|
self.input_field.value = str(self.board.seed)
|
|
|
|
|
|
|
|
def on_input_submitted(self, event: Input.Submitted) -> None:
|
|
|
|
'''Re-roll the board state with the seed from the input'''
|
|
|
|
if event.validation_result.is_valid:
|
|
|
|
self.board.roll_board(int(event.value))
|
|
|
|
|
|
|
|
if __name__ == "__main__":
|
|
|
|
app = BingoApp()
|
|
|
|
app.run()
|