mirror of
https://github.com/onyx-and-iris/lottery-tui.git
synced 2026-02-26 11:09:11 +00:00
Compare commits
3 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| cfba2303e6 | |||
| a2ab27fa5b | |||
| 5d6836a603 |
@ -1,6 +1,6 @@
|
|||||||
[project]
|
[project]
|
||||||
name = "lottery-tui"
|
name = "lottery-tui"
|
||||||
version = "0.2.7"
|
version = "1.0.1"
|
||||||
description = "A terminal user interface for lottery games."
|
description = "A terminal user interface for lottery games."
|
||||||
authors = [{ name = "onyx-and-iris", email = "code@onyxandiris.online" }]
|
authors = [{ name = "onyx-and-iris", email = "code@onyxandiris.online" }]
|
||||||
dependencies = ["textual>=8.0.0", "loguru>=0.7.3"]
|
dependencies = ["textual>=8.0.0", "loguru>=0.7.3"]
|
||||||
@ -8,7 +8,7 @@ requires-python = ">=3.10"
|
|||||||
readme = "README.md"
|
readme = "README.md"
|
||||||
license = { text = "MIT" }
|
license = { text = "MIT" }
|
||||||
classifiers = [
|
classifiers = [
|
||||||
"Development Status :: 4 - Beta",
|
"Development Status :: 5 - Production/Stable",
|
||||||
"Programming Language :: Python",
|
"Programming Language :: Python",
|
||||||
"Programming Language :: Python :: 3.10",
|
"Programming Language :: Python :: 3.10",
|
||||||
"Programming Language :: Python :: 3.11",
|
"Programming Language :: Python :: 3.11",
|
||||||
|
|||||||
@ -1,6 +1,9 @@
|
|||||||
from rich.text import Text
|
from typing import NoReturn
|
||||||
|
|
||||||
from textual.app import App, ComposeResult
|
from textual.app import App, ComposeResult
|
||||||
from textual.containers import Container
|
from textual.containers import Container
|
||||||
|
from textual.events import Key
|
||||||
|
from textual.types import SelectType
|
||||||
from textual.widgets import Button, Label, Select, Static
|
from textual.widgets import Button, Label, Select, Static
|
||||||
|
|
||||||
from .lottery import request_lottery_obj
|
from .lottery import request_lottery_obj
|
||||||
@ -23,6 +26,8 @@ class LotteryTUI(App):
|
|||||||
('Set For Life', 'setforlife'),
|
('Set For Life', 'setforlife'),
|
||||||
('Thunderball', 'thunderball'),
|
('Thunderball', 'thunderball'),
|
||||||
],
|
],
|
||||||
|
value='lotto',
|
||||||
|
allow_blank=False,
|
||||||
id='lottery-select',
|
id='lottery-select',
|
||||||
),
|
),
|
||||||
Button('Draw', id='draw-button'),
|
Button('Draw', id='draw-button'),
|
||||||
@ -30,29 +35,27 @@ class LotteryTUI(App):
|
|||||||
id='main-container',
|
id='main-container',
|
||||||
)
|
)
|
||||||
|
|
||||||
def on_key(self, event):
|
def on_key(self, event: Key) -> NoReturn:
|
||||||
"""Handle key events."""
|
"""Handle key events."""
|
||||||
if event.key == 'q':
|
if event.key == 'q':
|
||||||
self.exit()
|
self.exit()
|
||||||
|
|
||||||
def on_button_pressed(self, event):
|
def on_button_pressed(self, event: Button.Pressed) -> None:
|
||||||
"""Handle button press events."""
|
"""Handle button press events."""
|
||||||
if event.button.id == 'draw-button':
|
if event.button.id == 'draw-button':
|
||||||
self._draw_button_handler()
|
self._draw_button_handler()
|
||||||
|
|
||||||
def _draw_button_handler(self):
|
def _draw_button_handler(self) -> None:
|
||||||
"""Handle the draw button press."""
|
"""Handle the draw button press."""
|
||||||
if self.query_one('#lottery-select').is_blank():
|
lottery_obj = request_lottery_obj(self._read_lottery_selection())
|
||||||
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()
|
result = lottery_obj.draw()
|
||||||
self._update_result_label(str(result))
|
self._update_result_label(str(result))
|
||||||
|
|
||||||
def _update_result_label(self, message: str):
|
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:
|
||||||
"""Update the result label with a new message."""
|
"""Update the result label with a new message."""
|
||||||
self.query_one('#result-label').update(message)
|
self.query_one('#result-label').update(message)
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user