Merge pull request #116 from tiqi-group/feat/customisable_frontend_src

feat: adds option for custom frontend_src directory
This commit is contained in:
Mose Müller 2024-03-14 16:45:04 +01:00 committed by GitHub
commit a606194c48
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 28 additions and 2 deletions

View File

@ -18,6 +18,8 @@
- [DataService Instances (Nested Classes)](#dataservice-instances-nested-classes)
- [Custom Components (`pydase.components`)](#custom-components-pydasecomponents)
- [`DeviceConnection`](#deviceconnection)
- [Customizing Connection Logic](#customizing-connection-logic)
- [Reconnection Interval](#reconnection-interval)
- [`Image`](#image)
- [`NumberSlider`](#numberslider)
- [`ColouredEnum`](#colouredenum)
@ -30,6 +32,7 @@
- [Customizing the Web Interface](#customizing-the-web-interface)
- [Enhancing the Web Interface Style with Custom CSS](#enhancing-the-web-interface-style-with-custom-css)
- [Tailoring Frontend Component Layout](#tailoring-frontend-component-layout)
- [Specifying a Custom Frontend Source](#specifying-a-custom-frontend-source)
- [Logging in pydase](#logging-in-pydase)
- [Changing the Log Level](#changing-the-log-level)
- [Documentation](#documentation)
@ -836,6 +839,28 @@ Please ensure that the CSS file path is accessible from the server's running loc
The `web_settings.json` file will be stored in the directory specified by `SERVICE_CONFIG_DIR`. You can generate a `web_settings.json` file by setting the `GENERATE_WEB_SETTINGS` to `True`. For more information, see the [configuration section](#configuring-pydase-via-environment-variables).
### Specifying a Custom Frontend Source
To further personalize your web interface, you can provide `pydase` with a custom frontend GUI. To do so, you can use the `frontend_src` keyword in the `pydase.Server`:
```python
from pathlib import Path
import pydase
class MyService(pydase.DataService):
# Service definition
if __name__ == "__main__":
service = MyService()
pydase.Server(
service,
frontend_src=Path("path/to/your/frontend/directory"),
).run()
```
## Logging in pydase
The `pydase` library organizes its loggers on a per-module basis, mirroring the Python package hierarchy. This structured approach allows for granular control over logging levels and behaviour across different parts of the library.

View File

@ -70,7 +70,7 @@ class WebServer:
enable_cors: bool = True,
config_dir: Path = ServiceConfig().config_dir,
generate_web_settings: bool = WebServerConfig().generate_web_settings,
**kwargs: Any,
frontend_src: Path = Path(__file__).parent.parent.parent / "frontend",
) -> None:
self.observer = data_service_observer
self.state_manager = self.observer.state_manager
@ -79,6 +79,7 @@ class WebServer:
self.host = host
self.css = css
self.enable_cors = enable_cors
self.frontend_src = frontend_src
self._service_config_dir = config_dir
self._generate_web_settings = generate_web_settings
self._loop: asyncio.AbstractEventLoop
@ -181,7 +182,7 @@ class WebServer:
app.mount(
"/",
StaticFiles(
directory=Path(__file__).parent.parent.parent / "frontend",
directory=self.frontend_src,
html=True,
),
)