77 lines
2.1 KiB
Python
Executable File
77 lines
2.1 KiB
Python
Executable File
#!/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()
|