Nyx Node
Loading...
Searching...
No Matches
indi_text.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 TEXT_MESSAGE_PY Nyx Text Message
22# @brief Nyx / INDI Text 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 'value',
36 '$',
37)
39 """!
40 @ingroup TEXT_MESSAGE_PY
41 @brief INDI / Nyx text property.
42 """
43
44 ####################################################################################################################
45
46 def __init__(self, name: str, label: str | None = None, value: str | None = None):
47 """!
48 @brief Allocates a new INDI / Nyx text property.
49
50 @param name Property name.
51 @param label Property label.
52 @param value Initial text value.
53 """
54
55 super().__init__(bind.lib.nyx_text_prop_new(
56 bind.as_bytes(name, allow_none = False),
57 bind.as_bytes(label, allow_none = True),
58 bind.as_bytes(value, allow_none = True),
59 ))
60
61 ####################################################################################################################
62
63 @obj.nyx_callback(bind.nyx_callback_str_t)
64 def _nyx_callback_func(self, _vector, _prop, new_value, old_value) -> bool:
65
66 return all(self._dispatch_callbacks(
67 new_value.decode('utf-8') if new_value is not None else None,
68 old_value.decode('utf-8') if old_value is not None else None,
69 ))
70
71########################################################################################################################
72
73@utils.nyx_property(
74 'device',
75 '@device',
76)
77@utils.nyx_property(
78 'name',
79 '@name',
80)
81@utils.nyx_property(
82 'state',
83 '@state',
84 kind = enums.NyxState,
85 getter = enums.NyxState.to_int,
86 setter = enums.NyxState.to_str,
87)
88@utils.nyx_property(
89 'perm',
90 '@perm',
91 kind = enums.NyxPerm,
92 getter = enums.NyxPerm.to_int,
93 setter = enums.NyxPerm.to_str,
94)
96 """!
97 @ingroup TEXT_MESSAGE_PY
98 @brief INDI / Nyx text vector.
99 """
100
101 ####################################################################################################################
102
103 def __init__(self, device: str, name: str, state: enums.NyxState | int | str, perm: enums.NyxPerm | int | str, props: typing.Iterable[NyxTextProp], **opts: typing.Any):
104 """!
105 @brief Allocates a new INDI / Nyx text vector.
106
107 @param device Device name.
108 @param name Vector name.
109 @param state Vector state.
110 @param perm Vector permissions.
111 @param props Properties.
112 @param opts Options (group, label, hints, timeout, message).
113 """
114
115 ################################################################################################################
116
117 super().__init__(bind.lib.nyx_text_vector_new(
118 bind.as_bytes(device, allow_none = False),
119 bind.as_bytes(name, allow_none = False),
120 enums.NyxState.to_int(state),
121 enums.NyxPerm.to_int(perm),
122 bind.nyx_dict_p(),
123 bind.as_opts(opts),
124 ))
125
126 ################################################################################################################
128 # noinspection PyTypeChecker
129 children: json.NyxList = self['children']
131 for prop in props:
132
133 if not isinstance(prop, NyxTextProp):
134
135 raise TypeError('Expected NyxTextProp')
136
137 children.append(prop)
138
139 ####################################################################################################################
140
141 @obj.nyx_callback(bind.nyx_callback_vector_t)
142 def _nyx_callback_func(self, _vector: json.json_dict.NyxDict, modified: bool) -> None:
143
144 self._dispatch_callbacks(bool(modified))
145
146########################################################################################################################
147
148__all__ = [name for name in globals() if name.lower().startswith('nyx')]
149
150########################################################################################################################
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 device, str name, enums.NyxState|int|str state, enums.NyxPerm|int|str perm, typing.Iterable[NyxTextProp] props, **typing.Any opts)
Allocates a new INDI / Nyx text vector.
Definition indi_text.py:112
__init__(self, str name, str|None label=None, str|None value=None)
Allocates a new INDI / Nyx text property.
Definition indi_text.py:46
INDI / Nyx text property.
Definition indi_text.py:38
INDI / Nyx text vector.
Definition indi_text.py:104