remove footer, add input method
This commit is contained in:
parent
3cded45cfd
commit
725b30256d
17
bingo.py
17
bingo.py
@ -58,13 +58,10 @@ class BingoApp(App):
|
|||||||
"""A Textual app to run a Bingo board."""
|
"""A Textual app to run a Bingo board."""
|
||||||
CSS_PATH = "bingo.tcss"
|
CSS_PATH = "bingo.tcss"
|
||||||
|
|
||||||
BINDINGS = [("d", "toggle_dark", "Toggle dark mode")]
|
|
||||||
|
|
||||||
def compose(self) -> ComposeResult:
|
def compose(self) -> ComposeResult:
|
||||||
"""Create child widgets for the app."""
|
"""Create child widgets for the app."""
|
||||||
yield Header()
|
yield Header()
|
||||||
yield BingoDisplay()
|
yield BingoDisplay()
|
||||||
yield Footer()
|
|
||||||
|
|
||||||
def action_toggle_dark(self) -> None:
|
def action_toggle_dark(self) -> None:
|
||||||
"""An action to toggle dark mode."""
|
"""An action to toggle dark mode."""
|
||||||
@ -88,7 +85,7 @@ class BingoDisplay(Static):
|
|||||||
self.input_field.border_title = 'Seed'
|
self.input_field.border_title = 'Seed'
|
||||||
yield Horizontal(
|
yield Horizontal(
|
||||||
self.input_field,
|
self.input_field,
|
||||||
Button('re-roll', classes='roll_btn'),
|
Button.error(':game_die: re-roll', classes='roll_btn'),
|
||||||
classes='bottom_line'
|
classes='bottom_line'
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -98,6 +95,10 @@ class BingoDisplay(Static):
|
|||||||
self.board.roll_board(int(datetime.now().timestamp()))
|
self.board.roll_board(int(datetime.now().timestamp()))
|
||||||
self.input_field.value = str(self.board.seed)
|
self.input_field.value = str(self.board.seed)
|
||||||
|
|
||||||
|
def on_input_submitted(self, event: Input.Submitted) -> None:
|
||||||
|
if event.validation_result:
|
||||||
|
self.board.roll_board(int(event.value))
|
||||||
|
|
||||||
class BingoBoard(Widget):
|
class BingoBoard(Widget):
|
||||||
|
|
||||||
fields = reactive([], recompose = True)
|
fields = reactive([], recompose = True)
|
||||||
@ -132,19 +133,15 @@ class BingoBoard(Widget):
|
|||||||
'geduscht',
|
'geduscht',
|
||||||
'Gulasch gegessen'
|
'Gulasch gegessen'
|
||||||
]
|
]
|
||||||
|
self.default_fields = self.fields
|
||||||
self.roll_board(int(datetime.now().timestamp()))
|
self.roll_board(int(datetime.now().timestamp()))
|
||||||
|
|
||||||
def roll_board(self, seed):
|
def roll_board(self, seed):
|
||||||
print('rolling board.')
|
|
||||||
self.seed = seed
|
self.seed = seed
|
||||||
random.seed(seed)
|
random.seed(seed)
|
||||||
self.fields = random.sample(self.fields, len(self.fields))
|
self.fields = random.sample(self.default_fields, len(self.fields))
|
||||||
print('board after shuf:')
|
|
||||||
print(self.fields)
|
|
||||||
|
|
||||||
def watch_fields(self, new_state) -> None:
|
def watch_fields(self, new_state) -> None:
|
||||||
print('watch_fields: called')
|
|
||||||
self.fieldstate = [False for _ in range(25)]
|
self.fieldstate = [False for _ in range(25)]
|
||||||
for idx, field in enumerate(self.query(BingoField)):
|
for idx, field in enumerate(self.query(BingoField)):
|
||||||
field.text = new_state[idx]
|
field.text = new_state[idx]
|
||||||
|
Loading…
Reference in New Issue
Block a user