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