Compare commits

..

No commits in common. "main" and "v0.2.7" have entirely different histories.
main ... v0.2.7

2 changed files with 14 additions and 17 deletions

View File

@ -1,6 +1,6 @@
[project]
name = "lottery-tui"
version = "1.0.1"
version = "0.2.7"
description = "A terminal user interface for lottery games."
authors = [{ name = "onyx-and-iris", email = "code@onyxandiris.online" }]
dependencies = ["textual>=8.0.0", "loguru>=0.7.3"]
@ -8,7 +8,7 @@ requires-python = ">=3.10"
readme = "README.md"
license = { text = "MIT" }
classifiers = [
"Development Status :: 5 - Production/Stable",
"Development Status :: 4 - Beta",
"Programming Language :: Python",
"Programming Language :: Python :: 3.10",
"Programming Language :: Python :: 3.11",

View File

@ -1,9 +1,6 @@
from typing import NoReturn
from rich.text import Text
from textual.app import App, ComposeResult
from textual.containers import Container
from textual.events import Key
from textual.types import SelectType
from textual.widgets import Button, Label, Select, Static
from .lottery import request_lottery_obj
@ -26,8 +23,6 @@ class LotteryTUI(App):
('Set For Life', 'setforlife'),
('Thunderball', 'thunderball'),
],
value='lotto',
allow_blank=False,
id='lottery-select',
),
Button('Draw', id='draw-button'),
@ -35,27 +30,29 @@ class LotteryTUI(App):
id='main-container',
)
def on_key(self, event: Key) -> NoReturn:
def on_key(self, event):
"""Handle key events."""
if event.key == 'q':
self.exit()
def on_button_pressed(self, event: Button.Pressed) -> None:
def on_button_pressed(self, event):
"""Handle button press events."""
if event.button.id == 'draw-button':
self._draw_button_handler()
def _draw_button_handler(self) -> None:
def _draw_button_handler(self):
"""Handle the draw button press."""
lottery_obj = request_lottery_obj(self._read_lottery_selection())
if self.query_one('#lottery-select').is_blank():
self._update_result_label(
Text('Please select a lottery before drawing.', style='bold #ff8c42')
)
return
lottery_obj = request_lottery_obj(self.query_one('#lottery-select').value)
result = lottery_obj.draw()
self._update_result_label(str(result))
def _read_lottery_selection(self) -> SelectType:
"""Read the selected lottery from the dropdown."""
return self.query_one('#lottery-select').value
def _update_result_label(self, message: str) -> None:
def _update_result_label(self, message: str):
"""Update the result label with a new message."""
self.query_one('#result-label').update(message)