3-keyboard-control #4

Merged
panki merged 4 commits from 3-keyboard-control into master 2024-05-18 15:54:26 +02:00
Showing only changes of commit f01fae27d7 - Show all commits

View File

@ -2,6 +2,7 @@ from textual.reactive import reactive
from textual.widget import Widget from textual.widget import Widget
from textual.app import ComposeResult from textual.app import ComposeResult
from textual.message import Message from textual.message import Message
from textual import events
from datetime import datetime from datetime import datetime
import random import random
@ -75,6 +76,20 @@ class BingoBoard(Widget):
fields = self.query(BingoField) fields = self.query(BingoField)
fields[self.fieldnum_from_cursor()].set_highlighted(False) fields[self.fieldnum_from_cursor()].set_highlighted(False)
def on_key(self, event: events.Key) -> None:
fields = self.query(BingoField)
fields[self.fieldnum_from_cursor()].set_highlighted(False)
match event.key:
case 'up':
self.cursor_y -= 1 if self.cursor_y > 0 else 0
case 'down':
self.cursor_y += 1 if self.cursor_y < 4 else 0
case 'left':
self.cursor_x -= 1 if self.cursor_x > 0 else 0
case 'right':
self.cursor_x += 1 if self.cursor_x < 4 else 0
fields[self.fieldnum_from_cursor()].set_highlighted(True)
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