initial commit
This commit is contained in:
commit
9d07ffe535
0
requirements.txt
Normal file
0
requirements.txt
Normal file
15
style.tcss
Normal file
15
style.tcss
Normal file
@ -0,0 +1,15 @@
|
||||
#vertical-layout {
|
||||
layout: vertical;
|
||||
background: darkmagenta;
|
||||
height: 20%;
|
||||
}
|
||||
|
||||
#horizontal-layout {
|
||||
layout: horizontal;
|
||||
background: darkcyan;
|
||||
height: 20%;
|
||||
}
|
||||
|
||||
#user-input {
|
||||
width: 20%;
|
||||
}
|
76
timetracker.py
Executable file
76
timetracker.py
Executable file
@ -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()
|
Loading…
Reference in New Issue
Block a user