commit 9d07ffe535a1b6a36c17aea3ccc3d2b9b65eda5a Author: Marius Alwan Meyer <22202402+sporqist@users.noreply.github.com> Date: Thu Sep 28 00:00:24 2023 +0000 initial commit diff --git a/requirements.txt b/requirements.txt new file mode 100644 index 0000000..e69de29 diff --git a/style.tcss b/style.tcss new file mode 100644 index 0000000..48f86b4 --- /dev/null +++ b/style.tcss @@ -0,0 +1,15 @@ +#vertical-layout { + layout: vertical; + background: darkmagenta; + height: 20%; +} + +#horizontal-layout { + layout: horizontal; + background: darkcyan; + height: 20%; +} + +#user-input { + width: 20%; +} \ No newline at end of file diff --git a/timetracker.py b/timetracker.py new file mode 100755 index 0000000..b457f51 --- /dev/null +++ b/timetracker.py @@ -0,0 +1,76 @@ +#!/usr/bin/env python3 + +from dataclasses import dataclass, fields +from textual.app import App, ComposeResult +from textual.widgets import Label, Input, DataTable, ListView, ListItem +from textual.containers import Container + +from datetime import datetime, timedelta + +@dataclass +class Task: + user: str + project: int + contact: str + date: datetime + duration: float + activity: str + note: str + comment: str + + +# Sample data +data = [ + Task(user="mam", project="1100", contact="", date=datetime.now(), + duration=timedelta(minutes=35), activity="Service", + note="Test 1", comment=""), + Task(user="mam", project="1100", contact="", date=datetime.now(), + duration=timedelta(minutes=84), activity="Service", + note="Test 2", comment=""), + Task(user="mam", project="1100", contact="", date=datetime.now(), + duration=timedelta(minutes=2), activity="Service", + note="Test 3", comment=""), +] + + +class DataTableWidget(DataTable): + def __init__(self, data, **kwargs): + super().__init__(**kwargs) + self.data = data + + async def on_select(self, row, col): + self.update_cell(row, col, "5") + self.refresh() + pass + +class LayersExample(App): + CSS_PATH = "style.tcss" + + def compose(self) -> ComposeResult: + yield Container( + DataTable(), + ) + yield Container( + Input(placeholder="user", + id="user_input"), + ListView( + ListItem(Label("1")), + ListItem(Label("2")), + ListItem(Label("3")), + ), + id="horizontal-layout" + ) + + async def on_mount(self): + table = self.query_one(DataTable) + table.zebra_stripes = True + + table.add_columns(*[field.name for field in fields(Task)]) + table.add_rows([[task.user, task.project, task.contact, + task.date.strftime("%Y-%m-%d"), str(task.duration), + task.activity, task.note, task.comment + ] for task in data]) + +if __name__ == "__main__": + app = LayersExample() + app.run()