Metadata-Version: 2.4
Name: trame-dataclass
Version: 1.5.3
Summary: Dataclass for trame UI binding
Author: Kitware Inc.
License: Apache Software License
License-File: LICENSE
Keywords: Application,Framework,Interactive,Python,Web
Classifier: Development Status :: 4 - Beta
Classifier: Environment :: Web Environment
Classifier: License :: OSI Approved :: Apache Software License
Classifier: Natural Language :: English
Classifier: Operating System :: OS Independent
Classifier: Programming Language :: Python :: 3 :: Only
Classifier: Topic :: Software Development :: Libraries :: Application Frameworks
Classifier: Topic :: Software Development :: Libraries :: Python Modules
Requires-Python: >=3.9
Requires-Dist: loguru
Requires-Dist: trame-client>=3.10
Provides-Extra: app
Requires-Dist: pywebview; extra == 'app'
Provides-Extra: dev
Requires-Dist: nox; extra == 'dev'
Requires-Dist: pre-commit; extra == 'dev'
Requires-Dist: pytest-asyncio; extra == 'dev'
Requires-Dist: pytest-cov>=3; extra == 'dev'
Requires-Dist: pytest>=6; extra == 'dev'
Requires-Dist: ruff; extra == 'dev'
Requires-Dist: trame; extra == 'dev'
Provides-Extra: jupyter
Requires-Dist: jupyterlab; extra == 'jupyter'
Description-Content-Type: text/x-rst

trame-dataclass
----------------------------------------

Dataclass for trame UI binding

License
----------------------------------------

This library is OpenSource and follow the Apache Software License

Installation
----------------------------------------

Install the application/library

.. code-block:: console

    pip install trame-dataclass

Usage example
----------------------------------------

.. code-block:: console

    from trame.app import TrameApp, StateDataModel
    from trame.ui.html import DivLayout
    from trame.widgets import html


    class SimpleStructure(StateDataModel):
        name: str = "John Doe"
        age: int = 1
        derived_value: int

        @watch("age")
        def _update_derived(self, age):
            self.derived_value = 80 - age


    class GettingStarted(TrameApp):
        def __init__(self, server=None):
            super().__init__(server)
            self._data = SimpleStructure(self.server)
            self._data.watch(["age"], self.print_age)
            self._build_ui()

        def print_age(self, age):
            print(f"{age=}")

        def _modify_data(self):
            self._data.age += 1

        def _build_ui(self):
            with DivLayout(self.server) as self.ui:
                html.Button("Server change", click=self._modify_data)
                html.Div("Getting started with StateDataModel")
                with self._data.Provider(name="user"):
                    html.Pre("{{ JSON.stringify(user, null, 2) }}")
                    html.Hr()
                    html.Div(
                        "Hello {{ user.name }} - derived value = {{ user.derived_value }}"
                    )
                    html.Hr()
                    html.Span("Your name:")
                    html.Input(type="text", v_model="user.name")
                    html.Hr()
                    html.Span("Your age:")
                    html.Input(
                        type="range", min=0, max=120, step=1, v_model_number="user.age"
                    )


    def main():
        app = GettingStarted()
        app.server.start()


    if __name__ == "__main__":
        main()


Development setup
----------------------------------------

We recommend using uv for setting up and managing a virtual environment for your development.

.. code-block:: console

    # Create venv and install all dependencies
    uv sync --all-extras --dev

    # Activate environment
    source .venv/bin/activate

    # Install commit analysis
    pre-commit install
    pre-commit install --hook-type commit-msg

    # Allow live code edit
    uv pip install -e .


Build and install the Vue components

.. code-block:: console

    cd vue-components
    npm i
    npm run build
    cd -

For running tests and checks, you can run ``nox``.

.. code-block:: console

    # run all
    nox

    # lint
    nox -s lint

    # tests
    nox -s tests

Professional Support
----------------------------------------

* `Training <https://www.kitware.com/courses/trame/>`_: Learn how to confidently use trame from the expert developers at Kitware.
* `Support <https://www.kitware.com/trame/support/>`_: Our experts can assist your team as you build your web application and establish in-house expertise.
* `Custom Development <https://www.kitware.com/trame/support/>`_: Leverage Kitware’s 25+ years of experience to quickly build your web application.
