2023-11-03 00:13:54 +00:00
|
|
|
from textual.app import App
|
2023-10-29 23:12:39 +00:00
|
|
|
|
2023-11-03 00:13:54 +00:00
|
|
|
from .db import db
|
2023-11-17 22:54:25 +00:00
|
|
|
from .kimaiapi import KimaiAPI
|
2023-10-29 21:49:26 +00:00
|
|
|
|
2023-11-03 21:52:08 +00:00
|
|
|
from .screens.hamster import HamsterScreen
|
|
|
|
from .screens.kimai import KimaiScreen
|
2023-10-27 21:00:03 +00:00
|
|
|
|
|
|
|
|
2023-10-27 01:26:15 +00:00
|
|
|
class HamsterToolsApp(App):
|
2023-10-27 15:40:25 +00:00
|
|
|
CSS_PATH = "app.tcss"
|
2023-11-17 22:54:25 +00:00
|
|
|
|
2023-10-27 01:26:15 +00:00
|
|
|
BINDINGS = [
|
2023-11-03 21:52:08 +00:00
|
|
|
("h", "switch_mode('hamster')", "Hamster"),
|
2023-10-27 21:00:03 +00:00
|
|
|
("k", "switch_mode('kimai')", "Kimai"),
|
2023-10-27 01:26:15 +00:00
|
|
|
("q", "quit", "Quit"),
|
|
|
|
]
|
2023-10-27 03:04:30 +00:00
|
|
|
|
2023-11-17 22:54:25 +00:00
|
|
|
api_ = None
|
|
|
|
|
|
|
|
@property
|
|
|
|
def api(self) -> KimaiAPI:
|
|
|
|
if self.api_ is None:
|
|
|
|
self.api_ = KimaiAPI()
|
|
|
|
return self.api_
|
|
|
|
|
2023-10-27 03:04:30 +00:00
|
|
|
def __init__(self):
|
2023-10-27 01:26:15 +00:00
|
|
|
self.MODES = {
|
2023-11-03 21:52:08 +00:00
|
|
|
"hamster": HamsterScreen(),
|
|
|
|
"kimai": KimaiScreen(),
|
2023-10-27 01:26:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
super().__init__()
|
|
|
|
|
|
|
|
def on_mount(self) -> None:
|
2023-11-03 21:52:08 +00:00
|
|
|
self.switch_mode("hamster")
|
2023-10-27 01:26:15 +00:00
|
|
|
|
|
|
|
def action_quit(self) -> None:
|
2023-10-27 23:42:30 +00:00
|
|
|
db.close()
|
2023-10-29 22:28:01 +00:00
|
|
|
self.exit()
|