mirror of
https://github.com/tiqi-group/pydase.git
synced 2025-04-22 09:10:01 +02:00
feat: creating components module, adding docstrings
This commit is contained in:
parent
21eb7d4c26
commit
b68cb4d309
32
src/pyDataInterface/components/__init__.py
Normal file
32
src/pyDataInterface/components/__init__.py
Normal file
@ -0,0 +1,32 @@
|
|||||||
|
"""
|
||||||
|
The `components` module is a collection of specialized subclasses of the `DataService`
|
||||||
|
class that are designed to model different types of user interface components. These
|
||||||
|
classes can be used to represent the state of various UI elements in a data interface,
|
||||||
|
and provide a simple way to interact with these elements programmatically.
|
||||||
|
|
||||||
|
Each class in the `components` module corresponds to a specific type of UI element, such
|
||||||
|
as a slider, a file upload, a graph, etc. The state of these UI elements is maintained
|
||||||
|
by the instance variables of the respective classes. This allows you to keep track of
|
||||||
|
the user's interactions with the UI elements and update your application's state
|
||||||
|
accordingly.
|
||||||
|
|
||||||
|
You can use the classes in the `components` module as attributes of a `DataService`
|
||||||
|
subclass to model the state of your application's UI. Here is an example of how to use
|
||||||
|
the `NumberSlider` class:
|
||||||
|
|
||||||
|
```python
|
||||||
|
from components import NumberSlider
|
||||||
|
|
||||||
|
class MyService(DataService):
|
||||||
|
voltage = NumberSlider(1, 0, 10, 0.1)
|
||||||
|
|
||||||
|
# Then, you can modify or access the voltage value like this:
|
||||||
|
my_service = MyService()
|
||||||
|
my_service.voltage.value = 5
|
||||||
|
print(my_service.voltage.value) # Output: 5
|
||||||
|
```
|
||||||
|
"""
|
||||||
|
|
||||||
|
from .number_slider import NumberSlider
|
||||||
|
|
||||||
|
__all__ = ["NumberSlider"]
|
48
src/pyDataInterface/components/number_slider.py
Normal file
48
src/pyDataInterface/components/number_slider.py
Normal file
@ -0,0 +1,48 @@
|
|||||||
|
from pyDataInterface import DataService
|
||||||
|
|
||||||
|
|
||||||
|
class NumberSlider(DataService):
|
||||||
|
"""
|
||||||
|
The `NumberSlider` class models and represents a UI component, such as a slider or
|
||||||
|
a dial, in the context of a data interface. This could be useful in various
|
||||||
|
applications, such as a lab setting where you might want to adjust a parameter
|
||||||
|
(e.g., temperature, voltage) within a certain range, and want to ensure that the
|
||||||
|
value is only adjusted in certain increments (`step_size`).
|
||||||
|
|
||||||
|
You can use it as an attribute of a `DataService` subclass to model the state of a
|
||||||
|
particular UI component. Here is an example of how to use the `NumberSlider` class:
|
||||||
|
|
||||||
|
```python
|
||||||
|
class MyService(DataService):
|
||||||
|
voltage = NumberSlider(1, 0, 10, 0.1)
|
||||||
|
|
||||||
|
# Then, you can modify or access the voltage value like this:
|
||||||
|
my_service = MyService()
|
||||||
|
my_service.voltage.value = 5
|
||||||
|
print(my_service.voltage.value) # Output: 5
|
||||||
|
```
|
||||||
|
|
||||||
|
Parameters:
|
||||||
|
-----------
|
||||||
|
value (float | int, optional):
|
||||||
|
The initial value of the slider. Defaults to 0.
|
||||||
|
min (int, optional):
|
||||||
|
The minimum value of the slider. Defaults to 0.
|
||||||
|
max (int, optional):
|
||||||
|
The maximum value of the slider. Defaults to 100.
|
||||||
|
step_size (float, optional):
|
||||||
|
The increment/decrement step size of the slider. Defaults to 1.0.
|
||||||
|
"""
|
||||||
|
|
||||||
|
def __init__(
|
||||||
|
self,
|
||||||
|
value: float | int = 0,
|
||||||
|
min: int = 0,
|
||||||
|
max: int = 100,
|
||||||
|
step_size: float = 1.0,
|
||||||
|
) -> None:
|
||||||
|
self.min = min
|
||||||
|
self.max = max
|
||||||
|
self.value = value
|
||||||
|
self.step_size = step_size
|
||||||
|
super().__init__()
|
@ -1,16 +0,0 @@
|
|||||||
from .data_service import DataService
|
|
||||||
|
|
||||||
|
|
||||||
class NumberSlider(DataService):
|
|
||||||
def __init__(
|
|
||||||
self,
|
|
||||||
value: float | int = 0,
|
|
||||||
min: int = 0,
|
|
||||||
max: int = 100,
|
|
||||||
step_size: float = 1.0,
|
|
||||||
) -> None:
|
|
||||||
self.min = min
|
|
||||||
self.max = max
|
|
||||||
self.value = value
|
|
||||||
self.step_size = step_size
|
|
||||||
super().__init__()
|
|
Loading…
x
Reference in New Issue
Block a user