Skip to content

Commit

Permalink
template fully compatible with pymodaq 5.x
Browse files Browse the repository at this point in the history
  • Loading branch information
seb5g committed Sep 19, 2024
1 parent c756e67 commit 433de3a
Show file tree
Hide file tree
Showing 14 changed files with 106 additions and 36 deletions.
10 changes: 10 additions & 0 deletions hatch_build.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
from pathlib import Path

from pymodaq_utils.resources.hatch_build_plugins import PluginInfoTomlHook

here = Path(__file__).absolute().parent


class PluginInfoTomlHook(PluginInfoTomlHook):
def update(self, metadata: dict) -> None:
super().update_custom(metadata, here)
2 changes: 1 addition & 1 deletion plugin_info.toml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ license = 'MIT'

[plugin-install]
#packages required for your plugin:
packages-required = ['pymodaq>=4.3.0']
packages-required = ['pymodaq>=5.0.1']

[features] # defines the plugin features contained into this plugin
instruments = true # true if plugin contains instrument classes (else false, notice the lowercase for toml files)
Expand Down
38 changes: 38 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
[build-system]
requires = ["hatchling>=1.9.0", "hatch-vcs", "toml", "pymodaq_utils"]
build-backend = "hatchling.build"

[project]
dynamic = ["version", "authors", "dependencies", "description", "urls", "entry-points"]
readme = "README.rst"
license = { file="LICENSE" }
requires-python = ">=3.8"

name = "pymodaq_plugins_template"

classifiers = [
"Development Status :: 5 - Production/Stable",
"Environment :: Other Environment",
"Intended Audience :: Science/Research",
"License :: OSI Approved :: MIT License",
"Natural Language :: English",
"Operating System :: OS Independent",
"Programming Language :: Python :: 3.8",
"Programming Language :: Python :: 3.9",
"Programming Language :: Python :: 3.10",
"Programming Language :: Python :: 3.11",
"Topic :: Scientific/Engineering :: Human Machine Interfaces",
"Topic :: Scientific/Engineering :: Visualization",
"Topic :: Software Development :: Libraries :: Python Modules",
"Topic :: Software Development :: User Interfaces",
]

[tool.hatch.metadata.hooks.custom]

[tool.hatch.version]
source = "vcs"

[tool.hatch.build.targets.sdist]
include = [
"/src",
]
4 changes: 0 additions & 4 deletions setup.py

This file was deleted.

2 changes: 1 addition & 1 deletion src/pymodaq_plugins_template/__init__.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
from pathlib import Path
from pymodaq.utils.logger import set_logger # to be imported by other modules.
from pymodaq_utils.logger import set_logger # to be imported by other modules.

from .utils import Config
config = Config()
Expand Down
6 changes: 3 additions & 3 deletions src/pymodaq_plugins_template/app/custom_app_template.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
from qtpy import QtWidgets

from pymodaq.utils import gui_utils as gutils
from pymodaq.utils.config import Config
from pymodaq.utils.logger import set_logger, get_module_name
from pymodaq_gui import utils as gutils
from pymodaq_utils.config import Config
from pymodaq_utils.logger import set_logger, get_module_name

# todo: replace here *pymodaq_plugins_template* by your plugin package name
from pymodaq_plugins_template.utils import Config as PluginConfig
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
from pymodaq.control_modules.move_utility_classes import DAQ_Move_base, comon_parameters_fun, main, DataActuatorType,\
DataActuator # common set of parameters for all actuators
from pymodaq.utils.daq_utils import ThreadCommand # object used to send info back to the main thread
from pymodaq.utils.parameter import Parameter
from pymodaq.control_modules.move_utility_classes import (DAQ_Move_base, comon_parameters_fun,
main, DataActuatorType, DataActuator)

from pymodaq_utils.utils import ThreadCommand # object used to send info back to the main thread
from pymodaq_gui.parameter import Parameter


class PythonWrapperOfYourInstrument:
Expand Down Expand Up @@ -40,7 +41,7 @@ class DAQ_Move_Template(DAQ_Move_base):
is_multiaxes = False # TODO for your plugin set to True if this plugin is controlled for a multiaxis controller
_axis_names = ['Axis1', 'Axis2'] # TODO for your plugin: complete the list
_epsilon = 0.1 # TODO replace this by a value that is correct depending on your controller
data_actuator_type = DataActuatorType['DataActuator'] # wether you use the new data style for actuator otherwise set this
data_actuator_type = DataActuatorType.DataActuator # wether you use the new data style for actuator otherwise set this
# as DataActuatorType['float'] (or entirely remove the line)

params = [ # TODO for your custom plugin: elements to be added here as dicts in order to control your custom stage
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
import numpy as np
from pymodaq.utils.daq_utils import ThreadCommand
from pymodaq.utils.data import DataFromPlugins, DataToExport
from pymodaq.control_modules.viewer_utility_classes import DAQ_Viewer_base, comon_parameters, main
from pymodaq.utils.parameter import Parameter

from pymodaq_utils.utils import ThreadCommand
from pymodaq_data.data import DataToExport
from pymodaq_gui.parameter import Parameter

from pymodaq.control_modules.viewer_utility_classes import DAQ_Viewer_base, comon_parameters, main
from pymodaq.utils.data import DataFromPlugins

class PythonWrapperOfYourInstrument:
# TODO Replace this fake class with the import of the real python wrapper of your instrument
Expand All @@ -15,6 +17,7 @@ class PythonWrapperOfYourInstrument:
# for the class name and the file name.)
# (3) this file should then be put into the right folder, namely IN THE FOLDER OF THE PLUGIN YOU ARE DEVELOPING:
# pymodaq_plugins_my_plugin/daq_viewer_plugins/plugins_0D

class DAQ_0DViewer_Template(DAQ_Viewer_base):
""" Instrument plugin class for a OD viewer.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
import numpy as np
from pymodaq.utils.daq_utils import ThreadCommand
from pymodaq.utils.data import DataFromPlugins, Axis, DataToExport

from pymodaq_utils.utils import ThreadCommand
from pymodaq_data.data import DataToExport, Axis
from pymodaq_gui.parameter import Parameter

from pymodaq.control_modules.viewer_utility_classes import DAQ_Viewer_base, comon_parameters, main
from pymodaq.utils.parameter import Parameter
from pymodaq.utils.data import DataFromPlugins


class PythonWrapperOfYourInstrument:
Expand All @@ -15,6 +18,8 @@ class PythonWrapperOfYourInstrument:
# for the class name and the file name.)
# (3) this file should then be put into the right folder, namely IN THE FOLDER OF THE PLUGIN YOU ARE DEVELOPING:
# pymodaq_plugins_my_plugin/daq_viewer_plugins/plugins_1D


class DAQ_1DViewer_Template(DAQ_Viewer_base):
""" Instrument plugin class for a 1D viewer.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
from pymodaq.utils.daq_utils import ThreadCommand
from pymodaq.utils.data import DataFromPlugins, Axis, DataToExport
from pymodaq.control_modules.viewer_utility_classes import DAQ_Viewer_base, comon_parameters, main
from pymodaq.utils.parameter import Parameter
import numpy as np

from pymodaq_utils.utils import ThreadCommand
from pymodaq_data.data import DataToExport, Axis
from pymodaq_gui.parameter import Parameter

from pymodaq.control_modules.viewer_utility_classes import DAQ_Viewer_base, comon_parameters, main
from pymodaq.utils.data import DataFromPlugins
class PythonWrapperOfYourInstrument:
# TODO Replace this fake class with the import of the real python wrapper of your instrument
pass
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,12 @@
from qtpy import QtWidgets

from pymodaq.utils import gui_utils as gutils
from pymodaq.utils.config import Config, get_set_preset_path, ConfigError
from pymodaq.utils.logger import set_logger, get_module_name
from pymodaq_gui import utils as gutils
from pymodaq_utils.config import Config, ConfigError
from pymodaq_utils.logger import set_logger, get_module_name

from pymodaq.utils.config import get_set_preset_path
from pymodaq.extensions.utils import CustomExt


# todo: replace here *pymodaq_plugins_template* by your plugin package name
from pymodaq_plugins_template.utils import Config as PluginConfig
Expand All @@ -20,7 +24,7 @@

# todo: modify the name of this class to reflect its application and change the name in the main
# method at the end of the script
class CustomExtensionTemplate(gutils.CustomApp):
class CustomExtensionTemplate(CustomExt):

# todo: if you wish to create custom Parameter and corresponding widgets. These will be
# automatically added as children of self.settings. Morevover, the self.settings_tree will
Expand Down Expand Up @@ -131,5 +135,6 @@ def main():
f"preset_for_{CLASS_NAME.lower()} = {'a name for an existing preset'}"
)


if __name__ == '__main__':
main()
20 changes: 15 additions & 5 deletions src/pymodaq_plugins_template/models/PIDModelTemplate.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
from pymodaq.extensions.pid.utils import PIDModelGeneric, OutputToActuator, InputFromDetector, main
from pymodaq.utils.data import DataToExport
import numpy as np

from pymodaq.extensions.pid.utils import PIDModelGeneric, DataToActuatorPID, main
from pymodaq_data.data import DataToExport, DataCalculated

from pymodaq.utils.data import DataActuator

from typing import List


Expand Down Expand Up @@ -62,9 +67,12 @@ def convert_input(self, measurements: DataToExport):
"""

x, y = some_function_to_convert_the_data(measurements)
return InputFromDetector([y, x])
return DataToExport('pid inputs',
data=[DataCalculated('pid calculated',
data=[np.array([x]),
np.array([y])])])

def convert_output(self, outputs: List[float], dt: float, stab=True):
def convert_output(self, outputs: List[float], dt: float, stab=True) -> DataToActuatorPID:
"""
Convert the output of the PID in units to be fed into the actuator
Parameters
Expand All @@ -81,7 +89,9 @@ def convert_output(self, outputs: List[float], dt: float, stab=True):
"""
outputs = some_function_to_convert_the_pid_outputs(outputs, dt, stab)
return OutputToActuator(mode='rel', values=outputs)
return DataToActuatorPID('pid output', mode='rel',
data=[DataActuator(self.actuators_name[ind], data=outputs[ind])
for ind in range(len(outputs))])


if __name__ == '__main__':
Expand Down
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
#this is the configuration file of the plugin
title = 'this is the configuration file of the plugin XXX'

2 changes: 1 addition & 1 deletion src/pymodaq_plugins_template/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
"""
from pathlib import Path

from pymodaq.utils.config import BaseConfig, USER
from pymodaq_utils.config import BaseConfig, USER


class Config(BaseConfig):
Expand Down

0 comments on commit 433de3a

Please sign in to comment.