From b68cb4d309d4b2e05d6c482ddb4d91cc12d78a0f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mose=20M=C3=BCller?= Date: Wed, 2 Aug 2023 12:06:21 +0200 Subject: [PATCH] feat: creating components module, adding docstrings --- src/pyDataInterface/components/__init__.py | 32 +++++++++++++ .../components/number_slider.py | 48 +++++++++++++++++++ .../data_service/number_slider.py | 16 ------- 3 files changed, 80 insertions(+), 16 deletions(-) create mode 100644 src/pyDataInterface/components/__init__.py create mode 100644 src/pyDataInterface/components/number_slider.py delete mode 100644 src/pyDataInterface/data_service/number_slider.py diff --git a/src/pyDataInterface/components/__init__.py b/src/pyDataInterface/components/__init__.py new file mode 100644 index 0000000..a6b3d37 --- /dev/null +++ b/src/pyDataInterface/components/__init__.py @@ -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"] diff --git a/src/pyDataInterface/components/number_slider.py b/src/pyDataInterface/components/number_slider.py new file mode 100644 index 0000000..3dac64e --- /dev/null +++ b/src/pyDataInterface/components/number_slider.py @@ -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__() diff --git a/src/pyDataInterface/data_service/number_slider.py b/src/pyDataInterface/data_service/number_slider.py deleted file mode 100644 index 966f1e4..0000000 --- a/src/pyDataInterface/data_service/number_slider.py +++ /dev/null @@ -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__()