Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Create a basic TUI for sensor status and readings #94

Open
Tracked by #122
ezio-melotti opened this issue Mar 12, 2024 · 2 comments
Open
Tracked by #122

Create a basic TUI for sensor status and readings #94

ezio-melotti opened this issue Mar 12, 2024 · 2 comments
Assignees
Labels
enhancement New feature or request

Comments

@ezio-melotti
Copy link
Collaborator

This should:

  • indicate if the sensors are online/offline (based on the last time we received data)
  • display the readings of each sensor in constantly updating table
    It will be useful to look at the data while logged through SSH.
@ezio-melotti ezio-melotti added the enhancement New feature or request label Mar 12, 2024
@ezio-melotti ezio-melotti self-assigned this Mar 12, 2024
@ezio-melotti
Copy link
Collaborator Author

See this script as an example:

The other day I also spent some time playing around with Textualize, and started putting together a proof of concept starting from this example in the Textualize guide.

Click to see the source:

This is an incomplete work in progress:

from asyncio import sleep
from random import randint

from textual import work
from textual.app import App, ComposeResult
from textual.widgets import Static, Label, DataTable

ON = '🟢'
OFF = '🔴'

ROWS = [
    ("lane", "swimmer", "country", "time"),
    ('🟢', "Joseph Schooling", "Singapore", 50.39),
    ('🔴', "Michael Phelps", "United States", 51.14),
    (5, "Chad le Clos", "South Africa", 51.14),
    (6, "László Cseh", "Hungary", 51.14),
    (3, "Li Zhuhao", "China", 51.26),
    (8, "Mehdy Metella", "France", 51.58),
    (7, "Tom Shields", "United States", 51.73),
    (1, "Aleksandr Sadovnikov", "Russia", 51.84),
    (10, "Darren Burns", "Scotland", 51.84),
]

class HostPane(Static):

    DEFAULT_CSS = """
    HostPane {
        border: solid lime;
    }
    .pane-title {
        width: 100%;
        border-bottom: solid lime;
        color: lightblue;
        text-align: center;
    }
    """

    def compose(self) -> ComposeResult:
        """Create child widgets for the app."""
        yield Label('Title', classes='pane-title')
        yield DataTable()

    def on_mount(self) -> None:
        pass

class DataApp(App):
    CSS = """
    Screen {
        layout: grid;
        grid-size: 2;
    }
    DataTable {
        height: 1fr;
    }
    """

    def compose(self) -> ComposeResult:
        yield HostPane()
        yield HostPane()
        yield HostPane()
        yield HostPane()

    def on_mount(self) -> None:
        for data_table in self.query(DataTable):
            data_table.loading = True
            self.load_data(data_table)

    @work
    async def load_data(self, data_table: DataTable) -> None:
        await sleep(randint(2, 10))
        data_table.add_columns(*ROWS[0])
        data_table.add_rows(ROWS[1:])
        data_table.loading = False


if __name__ == "__main__":
    app = DataApp()
    app.run()

@ezio-melotti
Copy link
Collaborator Author

It might be better to create a TUI for simoc-sam.py instead, with this being one of the available options.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

1 participant