Nyx Node
Loading...
Searching...
No Matches
indi_number.py
1# -*- coding: utf-8 -*-
2########################################################################################################################
3# NyxNode
4# Author: Jérôme ODIER <jerome.odier@lpsc.in2p3.fr>
5# SPDX-License-Identifier: GPL-3.0+
6########################################################################################################################
7
8import typing
9
10########################################################################################################################
11
12from .. import obj
13from .. import bind
14from .. import json
15
16from . import enums
17from . import utils
18
19########################################################################################################################
20
21## @defgroup NUMBER_MESSAGE_PY Nyx Number Message
22# @brief Nyx / INDI Number Message.
23
24########################################################################################################################
25
26@utils.nyx_property(
27 'name',
28 '@name',
29)
30@utils.nyx_property(
31 'label',
32 '@label',
33)
34@utils.nyx_property(
35 'format',
36 '@format',
37)
39 """!
40 @ingroup NUMBER_MESSAGE_PY
41 @brief Base class for INDI / Nyx number properties.
42 """
43
44 ####################################################################################################################
45
46 def __init__(self, ptr = None):
47
48 super().__init__(ptr)
50########################################################################################################################
51
53 """!
54 @ingroup NUMBER_MESSAGE_PY
55 @brief INDI / Nyx `int32_t` number property.
56 """
57
58 ####################################################################################################################
59
60 def __init__(self, name: str, label: str | None, fmt: str, min: int, max: int, step: int, value: int):
61 """!
62 @brief Allocates a new INDI / Nyx `int32_t` number property.
63
64 @param name Property name.
65 @param label Property label.
66 @param fmt Printf-style formatting string (%[flags][width]d).
67 @param min Range min, ignored if min == max.
68 @param max Range max, ignored if min == max.
69 @param step Step size, ignored if step == 0.
70 @param value Initial `int32_t` value.
71 """
72
73 super().__init__(bind.lib.nyx_number_prop_new_int(
74 bind.as_bytes(name, allow_none = False),
75 bind.as_bytes(label, allow_none = False),
76 bind.as_bytes(fmt, allow_none = False),
77 min,
78 max,
79 step,
80 value,
81 ))
82
83 ####################################################################################################################
84
85 @obj.nyx_callback(bind.nyx_callback_int_t)
86 def _nyx_callback_func(self, _vector, _prop, new_value, old_value) -> bool:
87
88 return all(self._dispatch_callbacks(new_value, old_value))
89
90 ####################################################################################################################
91
92 @property
93 def value(self) -> int:
94 """!
95 @property NyxNumberIntProp::value
96 @brief Gets / sets the value of this property object.
97
98 @return The value.
99 """
100
101 return bind.lib.nyx_number_prop_get_int(self.ptr)
102
103 ####################################################################################################################
104
105 @value.setter
106 def value(self, value: int) -> None:
107
108 bind.lib.nyx_number_prop_set_int(
109 self.ptr,
110 value,
111 )
112
113########################################################################################################################
114
116 """!
117 @ingroup NUMBER_MESSAGE_PY
118 @brief INDI / Nyx `uint32_t` number property.
119 """
120
121 ####################################################################################################################
122
123 def __init__(self, name: str, label: str | None, fmt: str, min: int, max: int, step: int, value: int):
124 """!
125 @brief Allocates a new INDI / Nyx `uint32_t` number property.
126
127 @param name Property name.
128 @param label Property label.
129 @param fmt Printf-style formatting string (%[flags][width]{uoxX}).
130 @param min Range min, ignored if min == max.
131 @param max Range max, ignored if min == max.
132 @param step Step size, ignored if step == 0.
133 @param value Initial `uint32_t` value.
134 """
135
136 super().__init__(bind.lib.nyx_number_prop_new_uint(
137 bind.as_bytes(name, allow_none = False),
138 bind.as_bytes(label, allow_none = True),
139 bind.as_bytes(fmt, allow_none = False),
140 min,
141 max,
142 step,
143 value,
144 ))
145
146 ####################################################################################################################
147
148 @obj.nyx_callback(bind.nyx_callback_uint_t)
149 def _nyx_callback_func(self, _vector, _prop, new_value, old_value) -> bool:
150
151 return all(self._dispatch_callbacks(new_value, old_value))
152
153 ####################################################################################################################
154
155 @property
156 def value(self) -> int:
157 """!
158 @property NyxNumberUIntProp::value
159 @brief Gets the value of this property object.
160
161 @return The value.
162 """
163
164 return bind.lib.nyx_number_prop_get_uint(self.ptr)
165
166 ####################################################################################################################
167
168 @value.setter
169 def value(self, value: int) -> None:
170
171 bind.lib.nyx_number_prop_set_uint(
172 self.ptr,
173 value,
174 )
175
176########################################################################################################################
177
179 """!
180 @ingroup NUMBER_MESSAGE_PY
181 @brief INDI / Nyx `int64_t` number property.
182 """
183
184 ####################################################################################################################
185
186 def __init__(self, name: str, label: str | None, fmt: str, min: int, max: int, step: int, value: int):
187 """!
188 @brief Allocates a new INDI / Nyx `int64_t` number property.
189
190 @param name Property name.
191 @param label Property label.
192 @param fmt Printf-style formatting string (%[flags][width]ld).
193 @param min Range min, ignored if min == max.
194 @param max Range max, ignored if min == max.
195 @param step Step size, ignored if step == 0.
196 @param value Initial `int64_t` value.
197 """
198
199 super().__init__(bind.lib.nyx_number_prop_new_long(
200 bind.as_bytes(name, allow_none = False),
201 bind.as_bytes(label, allow_none = True),
202 bind.as_bytes(fmt, allow_none = False),
203 min,
204 max,
205 step,
206 value,
207 ))
208
209 ####################################################################################################################
210
211 @obj.nyx_callback(bind.nyx_callback_long_t)
212 def _nyx_callback_func(self, _vector, _prop, new_value, old_value) -> bool:
213
214 return all(self._dispatch_callbacks(new_value, old_value))
215
216 ####################################################################################################################
217
218 @property
219 def value(self) -> int:
220 """!
221 @property NyxNumberLongProp::value
222 @brief Gets the value of this property object.
223
224 @return The value.
225 """
226
227 return bind.lib.nyx_number_prop_get_long(self.ptr)
228
229 ####################################################################################################################
230
231 @value.setter
232 def value(self, value: int) -> None:
233
234 bind.lib.nyx_number_prop_set_long(
235 self.ptr,
236 value,
237 )
238
239########################################################################################################################
240
242 """!
243 @ingroup NUMBER_MESSAGE_PY
244 @brief INDI / Nyx `uint64_t` number property.
245 """
246
247 ####################################################################################################################
248
249 def __init__(self, name: str, label: str | None, fmt: str, min: int, max: int, step: int, value: int):
250 """!
251 @brief Allocates a new INDI / Nyx `uint64_t` number property.
252
253 @param name Property name.
254 @param label Property label.
255 @param fmt Printf-style formatting string (%[flags][width]l{uoxX}).
256 @param min Range min, ignored if min == max.
257 @param max Range max, ignored if min == max.
258 @param step Step size, ignored if step == 0.
259 @param value Initial `uint64_t` value.
260 """
261
262 super().__init__(bind.lib.nyx_number_prop_new_ulong(
263 bind.as_bytes(name, allow_none = False),
264 bind.as_bytes(label, allow_none = True),
265 bind.as_bytes(fmt, allow_none = False),
266 min,
267 max,
268 step,
269 value,
270 ))
271
272 ####################################################################################################################
273
274 @obj.nyx_callback(bind.nyx_callback_ulong_t)
275 def _nyx_callback_func(self, _vector, _prop, new_value, old_value) -> bool:
276
277 return all(self._dispatch_callbacks(new_value, old_value))
278
279 ####################################################################################################################
280
281 @property
282 def value(self) -> int:
283 """!
284 @property NyxNumberULongProp::value
285 @brief Gets the value of this property object.
286
287 @return The value.
288 """
289
290 return bind.lib.nyx_number_prop_get_ulong(self.ptr)
291
292 ####################################################################################################################
293
294 @value.setter
295 def value(self, value: int) -> None:
296
297 bind.lib.nyx_number_prop_set_ulong(
298 self.ptr,
299 value,
300 )
301
302########################################################################################################################
303
305 """!
306 @ingroup NUMBER_MESSAGE_PY
307 @brief INDI / Nyx `double` number property.
308 """
309
310 ####################################################################################################################
311
312 def __init__(self, name: str, label: str | None, fmt: str, min: float, max: float, step: float, value: float):
313 """!
314 @brief Allocates a new INDI / Nyx `double` number property.
315
316 @param name Property name.
317 @param label Property label.
318 @param fmt Printf-style formatting string (%[flags][width]l?{fFeEgGaAm}).
319 @param min Range min, ignored if min == max.
320 @param max Range max, ignored if min == max.
321 @param step Step size, ignored if step == 0.
322 @param value Initial `double` value.
323 """
324
325 super().__init__(bind.lib.nyx_number_prop_new_double(
326 bind.as_bytes(name, allow_none = False),
327 bind.as_bytes(label, allow_none = True),
328 bind.as_bytes(fmt, allow_none = False),
329 min,
330 max,
331 step,
332 value,
333 ))
334
335 ####################################################################################################################
336
337 @obj.nyx_callback(bind.nyx_callback_double_t)
338 def _nyx_callback_func(self, _vector, _prop, new_value, old_value) -> bool:
339
340 return all(self._dispatch_callbacks(new_value, old_value))
341
342 ####################################################################################################################
343
344 @property
345 def value(self) -> float:
346 """!
347 @property NyxNumberDoubleProp::value
348 @brief Gets the value of this property object.
349
350 @return The value.
351 """
352
353 return bind.lib.nyx_number_prop_get_double(self.ptr)
354
355 ####################################################################################################################
356
357 @value.setter
358 def value(self, value: float) -> None:
359
360 bind.lib.nyx_number_prop_set_double(
361 self.ptr,
362 value,
363 )
364
365########################################################################################################################
366
367@utils.nyx_property(
368 'device',
369 '@device',
370)
371@utils.nyx_property(
372 'name',
373 '@name',
374)
375@utils.nyx_property(
376 'state',
377 '@state',
378 getter = enums.NyxState.to_int,
379 setter = enums.NyxState.to_str,
380)
381@utils.nyx_property(
382 'perm',
383 '@perm',
384 getter = enums.NyxPerm.to_int,
385 setter = enums.NyxPerm.to_str,
386)
388 """!
389 @ingroup NUMBER_MESSAGE_PY
390 @brief INDI / Nyx number vector.
391 """
392
393 ####################################################################################################################
394
395 def __init__(self, device: str, name: str, state: enums.NyxState | int | str, perm: enums.NyxPerm | int | str, props: typing.Iterable[NyxNumberProp], **opts: typing.Any):
396 """!
397 @brief Allocates a new INDI / Nyx number vector.
398
399 @param device Device name.
400 @param name Vector name.
401 @param state Vector state.
402 @param perm Vector permissions.
403 @param props Properties.
404 @param opts Options (group, label, hints, timeout, message).
405 """
406
407 ################################################################################################################
408
409 super().__init__(bind.lib.nyx_number_vector_new(
410 bind.as_bytes(device, allow_none = False),
411 bind.as_bytes(name, allow_none = False),
412 enums.NyxState.to_int(state),
413 enums.NyxPerm.to_int(perm),
414 bind.nyx_dict_p(),
415 bind.as_opts(opts),
416 ))
417
418 ################################################################################################################
420 # noinspection PyTypeChecker
421 children: json.NyxList = self['children']
423 for prop in props:
424
425 if not isinstance(prop, NyxNumberProp):
426
427 raise TypeError('Expected NyxNumberProp')
428
429 children.append(prop)
430
431 ####################################################################################################################
432
433 @obj.nyx_callback(bind.nyx_callback_vector_t)
434 def _nyx_callback_func(self, _vector: json.json_dict.NyxDict, modified: bool) -> None:
435
436 self._dispatch_callbacks(bool(modified))
437
438########################################################################################################################
439
440__all__ = [name for name in globals() if name.lower().startswith('nyx')]
441
442########################################################################################################################
JSON dict object.
Definition json_dict.py:22
JSON list object.
Definition json_list.py:22
_dispatch_callbacks(self, *args)
Definition obj.py:154
Vector permission hint.
Definition enums.py:81
Vector state hint.
Definition enums.py:24
__init__(self, str name, str|None label, str fmt, int min, int max, int step, int value)
Allocates a new INDI / Nyx uint64_t number property.
__init__(self, str name, str|None label, str fmt, int min, int max, int step, int value)
Allocates a new INDI / Nyx int32_t number property.
__init__(self, str name, str|None label, str fmt, float min, float max, float step, float value)
Allocates a new INDI / Nyx double number property.
__init__(self, str name, str|None label, str fmt, int min, int max, int step, int value)
Allocates a new INDI / Nyx uint32_t number property.
__init__(self, str device, str name, enums.NyxState|int|str state, enums.NyxPerm|int|str perm, typing.Iterable[NyxNumberProp] props, **typing.Any opts)
Allocates a new INDI / Nyx number vector.
__init__(self, str name, str|None label, str fmt, int min, int max, int step, int value)
Allocates a new INDI / Nyx int64_t number property.
INDI / Nyx double number property.
INDI / Nyx int32_t number property.
INDI / Nyx int64_t number property.
Base class for INDI / Nyx number properties.
INDI / Nyx uint32_t number property.
INDI / Nyx uint64_t number property.
INDI / Nyx number vector.