Reformatting

This commit is contained in:
3wc 2023-10-27 16:40:25 +01:00
parent 36f324e5ba
commit b06cf1fc62

View File

@ -4,10 +4,10 @@ from textual.widgets import Header, Footer, DataTable, Input
from textual.containers import Horizontal, Vertical
from textual.coordinate import Coordinate
from textual.screen import Screen
from textual.reactive import reactive
from .db import DatabaseManager, Category, Activity
class ListScreen(Screen):
def __init__(self, db_manager):
self.db_manager = db_manager
@ -64,27 +64,33 @@ class ActivitiesScreen(ListScreen):
Binding(key="escape", action="cancelfilter", show=False),
]
def _refresh(self, filter_query=None):
self.table.clear()
# List activities with the count of facts
activities = Activity.list_activities(self.db_manager, filter_query)
self.table.add_rows([[
activity.category_id,
activity.category_name,
activity.id,
activity.name,
activity.facts_count,
] for activity in activities])
self.table.add_rows(
[
[
activity.category_id,
activity.category_name,
activity.id,
activity.name,
activity.facts_count,
]
for activity in activities
]
)
self.table.sort(*self.sort)
def on_mount(self) -> None:
self.table = self.query_one(DataTable)
self.table.cursor_type = "row"
self.columns = self.table.add_columns("category id","category","activity id","activity","entries")
self.columns = self.table.add_columns(
"category id", "category", "activity id", "activity", "entries"
)
self.sort = (self.columns[1], self.columns[3])
self._refresh()
@ -112,17 +118,18 @@ class ActivitiesScreen(ListScreen):
cell_coordinate,
f"[red]{cell_value}[/red]",
)
self.table.move_cursor(row=self.table.cursor_coordinate[0]+1)
self.table.move_cursor(row=self.table.cursor_coordinate[0] + 1)
def on_data_table_row_selected(self, event):
if getattr(self, "move_from_activity", None) is not None:
move_to_activity = Activity.get_by_id(self.db_manager, self.table.get_cell_at(
Coordinate(event.cursor_row, 2)
))
move_to_activity = Activity.get_by_id(
self.db_manager, self.table.get_cell_at(Coordinate(event.cursor_row, 2))
)
self.move_from_activity.move_facts(move_to_activity)
self._refresh()
del self.move_from_activity
class CategoriesScreen(ListScreen):
BINDINGS = [
("q", "quit", "Quit"),
@ -136,21 +143,27 @@ class CategoriesScreen(ListScreen):
def _refresh(self, filter_query=None):
self.table.clear()
categories = Category.list_categories(self.db_manager,
filter_query=filter_query)
categories = Category.list_categories(
self.db_manager, filter_query=filter_query
)
self.table.add_rows([[
category.id,
category.name,
category.activity_count,
] for category in categories])
self.table.add_rows(
[
[
category.id,
category.name,
category.activity_count,
]
for category in categories
]
)
self.table.sort(self.sort)
def on_mount(self) -> None:
self.table = self.query_one(DataTable)
self.table.cursor_type = "row"
self.columns = self.table.add_columns("category id","category","activities")
self.columns = self.table.add_columns("category id", "category", "activities")
self.sort = self.columns[1]
self._refresh()
@ -167,6 +180,7 @@ class CategoriesScreen(ListScreen):
# supply the row key to `remove_row` to delete the row.
self.table.remove_row(row_key)
# class KimaiScreen(Screen):
# def compose(self) -> ComposeResult:
# yield Placeholder("Help Screen")
@ -179,7 +193,7 @@ class CategoriesScreen(ListScreen):
class HamsterToolsApp(App):
CSS_PATH = 'app.tcss'
CSS_PATH = "app.tcss"
BINDINGS = [
("a", "switch_mode('activities')", "Activities"),
("c", "switch_mode('categories')", "Categories"),
@ -188,7 +202,7 @@ class HamsterToolsApp(App):
]
def __init__(self):
self.db_manager = DatabaseManager('hamster-testing.db')
self.db_manager = DatabaseManager("hamster-testing.db")
self.MODES = {
"categories": CategoriesScreen(self.db_manager),