tango-milonga 0.1.0__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- milonga/__init__.py +3 -0
- milonga/cli.py +51 -0
- milonga/compat.py +17 -0
- milonga/core/__init__.py +5 -0
- milonga/core/backend/__init__.py +5 -0
- milonga/core/backend/demo.py +251 -0
- milonga/core/backend/fake.py +1144 -0
- milonga/core/backend/formats.py +138 -0
- milonga/core/backend/protocol.py +182 -0
- milonga/core/backend/pytango_backend.py +1166 -0
- milonga/core/backend/readonly.py +80 -0
- milonga/core/commands/__init__.py +59 -0
- milonga/core/commands/attributes.py +76 -0
- milonga/core/commands/base.py +135 -0
- milonga/core/commands/devices.py +180 -0
- milonga/core/commands/polling.py +64 -0
- milonga/core/commands/properties.py +283 -0
- milonga/core/commands/servers.py +221 -0
- milonga/core/enums.py +238 -0
- milonga/core/errors.py +95 -0
- milonga/core/model.py +318 -0
- milonga/core/monitor.py +228 -0
- milonga/core/names.py +153 -0
- milonga/core/services/__init__.py +1 -0
- milonga/core/services/control.py +346 -0
- milonga/core/services/diagnostics.py +75 -0
- milonga/core/services/groups.py +71 -0
- milonga/core/services/inventory.py +85 -0
- milonga/core/services/starter_protocol.py +95 -0
- milonga/core/store.py +208 -0
- milonga/core/tasks.py +57 -0
- milonga/ui/__init__.py +1 -0
- milonga/ui/app.py +149 -0
- milonga/ui/context.py +170 -0
- milonga/ui/dialogs.py +357 -0
- milonga/ui/format.py +170 -0
- milonga/ui/live.py +87 -0
- milonga/ui/live_hosts.py +91 -0
- milonga/ui/mainwindow.py +474 -0
- milonga/ui/menus.py +56 -0
- milonga/ui/models/__init__.py +8 -0
- milonga/ui/models/delegate.py +90 -0
- milonga/ui/models/properties.py +230 -0
- milonga/ui/models/tables.py +93 -0
- milonga/ui/models/tree.py +212 -0
- milonga/ui/models/values.py +142 -0
- milonga/ui/navigator.py +671 -0
- milonga/ui/panel_window.py +63 -0
- milonga/ui/panels/__init__.py +42 -0
- milonga/ui/panels/base.py +145 -0
- milonga/ui/panels/class_panel.py +56 -0
- milonga/ui/panels/columns.py +110 -0
- milonga/ui/panels/device.py +641 -0
- milonga/ui/panels/host.py +398 -0
- milonga/ui/panels/node_tiles.py +287 -0
- milonga/ui/panels/object_panel.py +39 -0
- milonga/ui/panels/overview.py +180 -0
- milonga/ui/panels/server.py +90 -0
- milonga/ui/plots.py +144 -0
- milonga/ui/process.py +117 -0
- milonga/ui/property_editor.py +297 -0
- milonga/ui/search.py +120 -0
- milonga/ui/tasks.py +109 -0
- milonga/ui/theme.py +387 -0
- milonga/ui/tiles.py +230 -0
- milonga/ui/widgets.py +241 -0
- milonga/ui/wizards.py +343 -0
- milonga/ui/write.py +93 -0
- tango_milonga-0.1.0.dist-info/METADATA +195 -0
- tango_milonga-0.1.0.dist-info/RECORD +74 -0
- tango_milonga-0.1.0.dist-info/WHEEL +4 -0
- tango_milonga-0.1.0.dist-info/entry_points.txt +2 -0
- tango_milonga-0.1.0.dist-info/licenses/LICENSE +674 -0
- tango_milonga-0.1.0.dist-info/licenses/LICENSE.LESSER +165 -0
milonga/__init__.py
ADDED
milonga/cli.py
ADDED
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
"""Command line entry point."""
|
|
2
|
+
|
|
3
|
+
import argparse
|
|
4
|
+
import sys
|
|
5
|
+
from collections.abc import Sequence
|
|
6
|
+
|
|
7
|
+
from milonga.ui.app import AppOptions, run
|
|
8
|
+
from milonga.ui.navigator import Scope
|
|
9
|
+
from milonga.ui.theme import Theme
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
def parse_args(argv: Sequence[str] | None = None) -> AppOptions:
|
|
13
|
+
parser = argparse.ArgumentParser(
|
|
14
|
+
prog="milonga", description="Administration console for Tango Controls"
|
|
15
|
+
)
|
|
16
|
+
parser.add_argument(
|
|
17
|
+
"--demo", action="store_true", help="use the in-memory demo control system"
|
|
18
|
+
)
|
|
19
|
+
parser.add_argument(
|
|
20
|
+
"--tango-host",
|
|
21
|
+
default=None,
|
|
22
|
+
help="control system to connect to, host:port (default: TANGO_HOST or ~/.tangorc)",
|
|
23
|
+
)
|
|
24
|
+
parser.add_argument("--read-only", action="store_true", help="refuse every write")
|
|
25
|
+
parser.add_argument(
|
|
26
|
+
"--theme", choices=[theme.value for theme in Theme], default=Theme.DARK.value
|
|
27
|
+
)
|
|
28
|
+
parser.add_argument(
|
|
29
|
+
"--scope",
|
|
30
|
+
choices=[scope.name.lower() for scope in Scope],
|
|
31
|
+
default=Scope.DEVICES.name.lower(),
|
|
32
|
+
help="navigator scope to start in",
|
|
33
|
+
)
|
|
34
|
+
parser.add_argument("open", nargs="*", help="devices or servers to open at startup")
|
|
35
|
+
namespace = parser.parse_args(argv)
|
|
36
|
+
return AppOptions(
|
|
37
|
+
demo=namespace.demo,
|
|
38
|
+
tango_host=namespace.tango_host,
|
|
39
|
+
read_only=namespace.read_only,
|
|
40
|
+
theme=Theme(namespace.theme),
|
|
41
|
+
scope=Scope[namespace.scope.upper()],
|
|
42
|
+
open=tuple(namespace.open),
|
|
43
|
+
)
|
|
44
|
+
|
|
45
|
+
|
|
46
|
+
def main(argv: Sequence[str] | None = None) -> int:
|
|
47
|
+
return run(parse_args(argv))
|
|
48
|
+
|
|
49
|
+
|
|
50
|
+
if __name__ == "__main__":
|
|
51
|
+
sys.exit(main())
|
milonga/compat.py
ADDED
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
"""Names this code uses that Python 3.10 does not have.
|
|
2
|
+
|
|
3
|
+
``StrEnum`` is defined here rather than taken from :mod:`enum` on the versions
|
|
4
|
+
that ship it, so that every supported version runs the same class: a mixed-in
|
|
5
|
+
``str`` enum formats as ``Class.MEMBER`` unless ``__str__`` and ``__format__``
|
|
6
|
+
come from ``str``, and enum values end up in user-visible text throughout.
|
|
7
|
+
"""
|
|
8
|
+
|
|
9
|
+
from enum import Enum
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
class StrEnum(str, Enum):
|
|
13
|
+
def __str__(self) -> str:
|
|
14
|
+
return str.__str__(self)
|
|
15
|
+
|
|
16
|
+
def __format__(self, format_spec: str) -> str:
|
|
17
|
+
return str.__format__(self, format_spec)
|
milonga/core/__init__.py
ADDED
|
@@ -0,0 +1,251 @@
|
|
|
1
|
+
"""A populated :class:`FakeBackend`, used by the tests and by demo mode."""
|
|
2
|
+
|
|
3
|
+
from datetime import datetime, timedelta
|
|
4
|
+
|
|
5
|
+
import numpy as np
|
|
6
|
+
|
|
7
|
+
from milonga.core.backend.fake import FakeBackend
|
|
8
|
+
from milonga.core.enums import (
|
|
9
|
+
AttrDataFormat,
|
|
10
|
+
AttrWriteType,
|
|
11
|
+
DisplayLevel,
|
|
12
|
+
PropertyScope,
|
|
13
|
+
ServerRunState,
|
|
14
|
+
TangoType,
|
|
15
|
+
)
|
|
16
|
+
from milonga.core.model import AlarmConfig, AttributeSpec, CommandSpec, EventConfig
|
|
17
|
+
from milonga.core.names import DeviceName, ServerName
|
|
18
|
+
|
|
19
|
+
BEAMLINE = "Beamline"
|
|
20
|
+
ACCELERATOR = "Accelerator"
|
|
21
|
+
|
|
22
|
+
|
|
23
|
+
def build_demo_backend(**kwargs: object) -> FakeBackend:
|
|
24
|
+
backend = FakeBackend(tango_host="tango-cs.id09:10000", **kwargs) # type: ignore[arg-type]
|
|
25
|
+
_build_beamline(backend)
|
|
26
|
+
_build_accelerator(backend)
|
|
27
|
+
_age_running_servers(backend)
|
|
28
|
+
return backend
|
|
29
|
+
|
|
30
|
+
|
|
31
|
+
def _age_running_servers(backend: FakeBackend) -> None:
|
|
32
|
+
"""Give the demo plausible uptimes instead of everything starting at once."""
|
|
33
|
+
started = datetime.now()
|
|
34
|
+
for index, server in enumerate(sorted(backend.servers, key=str)):
|
|
35
|
+
entry = backend.servers[server]
|
|
36
|
+
if entry.run_state is not ServerRunState.RUNNING:
|
|
37
|
+
continue
|
|
38
|
+
age = timedelta(hours=6 * (index % 13) + 1, minutes=7 * (index % 9))
|
|
39
|
+
entry.started_at = started - age
|
|
40
|
+
admin = backend.devices.get(server.admin_device)
|
|
41
|
+
if admin is not None:
|
|
42
|
+
admin.exported_at = entry.started_at
|
|
43
|
+
|
|
44
|
+
|
|
45
|
+
def _build_beamline(backend: FakeBackend) -> None:
|
|
46
|
+
for host in ("id09-srv-01", "id09-srv-02", "id09-det-01", "id09-vac-01"):
|
|
47
|
+
backend.register_host(host, group=BEAMLINE)
|
|
48
|
+
backend.install_starter(host)
|
|
49
|
+
|
|
50
|
+
for name, level in (("Databaseds/2", 1), ("TangoAccessControl/1", 1), ("PyAlarm/id09", 3)):
|
|
51
|
+
backend.register_server(name, "id09-srv-02", level=level, controlled=True, running=True)
|
|
52
|
+
backend.register_server("IcePAP/id09", "id09-srv-02", level=2, controlled=True, running=True)
|
|
53
|
+
vacuum = backend.register_server(
|
|
54
|
+
"Vacuum/id09-front", "id09-srv-02", level=2, controlled=True
|
|
55
|
+
)
|
|
56
|
+
vacuum.log.extend(
|
|
57
|
+
[
|
|
58
|
+
"12:41:02 starting Vacuum/id09-front (level 2, attempt 1)",
|
|
59
|
+
"12:41:05 failed serial port /dev/ttyR03: device or resource busy",
|
|
60
|
+
"12:41:05 process exited with code 1",
|
|
61
|
+
"12:41:35 auto-restart window expires in 24 min",
|
|
62
|
+
]
|
|
63
|
+
)
|
|
64
|
+
backend.register_server(
|
|
65
|
+
"LimaCCDs/pilatus", "id09-srv-02", level=2, controlled=True, running=True
|
|
66
|
+
)
|
|
67
|
+
backend.register_server("TangoTest/test", "id09-srv-02", level=3, controlled=True, running=True)
|
|
68
|
+
|
|
69
|
+
backend.register_device("sys/database/2", "DataBase", "Databaseds/2")
|
|
70
|
+
backend.register_device("sys/access_control/1", "TangoAccessControl", "TangoAccessControl/1")
|
|
71
|
+
backend.register_device("id09/alarm/main", "PyAlarm", "PyAlarm/id09")
|
|
72
|
+
backend.register_device("id09/icepap/ctrl", "IcePAPController", "IcePAP/id09")
|
|
73
|
+
backend.register_device("id09/motor/phi", "IcePAPMotor", "IcePAP/id09", alias="phi")
|
|
74
|
+
backend.register_device("id09/motor/theta", "IcePAPMotor", "IcePAP/id09", alias="theta")
|
|
75
|
+
backend.register_device("id09/vac/gauge-1", "VacuumGauge", "Vacuum/id09-front")
|
|
76
|
+
backend.register_device("id09/det/pilatus", "LimaCCDs", "LimaCCDs/pilatus")
|
|
77
|
+
backend.register_device("sys/tg_test/1", "TangoTest", "TangoTest/test")
|
|
78
|
+
|
|
79
|
+
_build_tango_test(backend, DeviceName.parse("sys/tg_test/1"))
|
|
80
|
+
_build_motor(backend, DeviceName.parse("id09/motor/phi"), position=41.233)
|
|
81
|
+
_build_motor(backend, DeviceName.parse("id09/motor/theta"), position=-12.5)
|
|
82
|
+
|
|
83
|
+
backend.set_properties(
|
|
84
|
+
PropertyScope.DEVICE,
|
|
85
|
+
"id09/motor/phi",
|
|
86
|
+
{
|
|
87
|
+
"AxisNumber": ["3"],
|
|
88
|
+
"Velocity": ["2.5"],
|
|
89
|
+
"polled_attr": ["position", "200", "state", "1000"],
|
|
90
|
+
"__SubDevices": ["id09/icepap/ctrl"],
|
|
91
|
+
},
|
|
92
|
+
)
|
|
93
|
+
backend.set_properties(
|
|
94
|
+
PropertyScope.DEVICE, "id09/motor/theta", {"AxisNumber": ["4"], "Velocity": ["1.0"]}
|
|
95
|
+
)
|
|
96
|
+
backend.set_properties(
|
|
97
|
+
PropertyScope.CLASS,
|
|
98
|
+
"IcePAPMotor",
|
|
99
|
+
{"EncoderType": ["ABSOLUTE"], "Velocity": ["1.0"], "Description": ["IcePAP axis"]},
|
|
100
|
+
)
|
|
101
|
+
backend.set_properties(
|
|
102
|
+
PropertyScope.FREE,
|
|
103
|
+
"Milonga",
|
|
104
|
+
{"HostGroups": [f"{BEAMLINE}:id09-*", f"{ACCELERATOR}:sr-*"]},
|
|
105
|
+
)
|
|
106
|
+
|
|
107
|
+
backend.set_host_reachable("id09-vac-01", False)
|
|
108
|
+
|
|
109
|
+
for index, name in enumerate(("Undulator/id09", "Frontend/id09"), start=1):
|
|
110
|
+
backend.register_server(name, "id09-vac-01", level=index, controlled=True)
|
|
111
|
+
for index in range(1, 5):
|
|
112
|
+
backend.register_server(
|
|
113
|
+
f"Camera/det-{index}", "id09-det-01", level=1, controlled=True, running=True
|
|
114
|
+
)
|
|
115
|
+
for index in range(1, 8):
|
|
116
|
+
backend.register_server(
|
|
117
|
+
f"Beamline/srv-{index}",
|
|
118
|
+
"id09-srv-01",
|
|
119
|
+
level=1 + index % 3,
|
|
120
|
+
controlled=True,
|
|
121
|
+
running=True,
|
|
122
|
+
)
|
|
123
|
+
|
|
124
|
+
|
|
125
|
+
def _build_accelerator(backend: FakeBackend) -> None:
|
|
126
|
+
for host in ("sr-ctl-01", "sr-ctl-02"):
|
|
127
|
+
backend.register_host(host, group=ACCELERATOR)
|
|
128
|
+
backend.install_starter(host)
|
|
129
|
+
for index in range(1, 12):
|
|
130
|
+
backend.register_server(
|
|
131
|
+
f"Machine/sr-{index}", "sr-ctl-01", level=1 + index % 5, controlled=True, running=True
|
|
132
|
+
)
|
|
133
|
+
for index in range(1, 9):
|
|
134
|
+
backend.register_server(
|
|
135
|
+
f"Booster/br-{index}",
|
|
136
|
+
"sr-ctl-02",
|
|
137
|
+
level=1 + index % 4,
|
|
138
|
+
controlled=True,
|
|
139
|
+
running=index > 4,
|
|
140
|
+
)
|
|
141
|
+
|
|
142
|
+
|
|
143
|
+
def _build_tango_test(backend: FakeBackend, device: DeviceName) -> None:
|
|
144
|
+
scalars = (
|
|
145
|
+
("double_scalar", TangoType.DOUBLE, 12.8741, "mm", AttrWriteType.READ_WRITE),
|
|
146
|
+
("long_scalar", TangoType.LONG, 143, "counts", AttrWriteType.READ_WRITE),
|
|
147
|
+
("boolean_scalar", TangoType.BOOLEAN, True, "", AttrWriteType.READ_WRITE),
|
|
148
|
+
("string_scalar", TangoType.STRING, "idle", "", AttrWriteType.READ_WRITE),
|
|
149
|
+
("throughput", TangoType.DOUBLE, 418.2, "MB/s", AttrWriteType.READ),
|
|
150
|
+
)
|
|
151
|
+
for name, data_type, value, unit, writable in scalars:
|
|
152
|
+
backend.register_attribute(
|
|
153
|
+
device,
|
|
154
|
+
AttributeSpec(
|
|
155
|
+
name,
|
|
156
|
+
data_type,
|
|
157
|
+
AttrDataFormat.SCALAR,
|
|
158
|
+
writable,
|
|
159
|
+
label=name.replace("_", " "),
|
|
160
|
+
unit=unit,
|
|
161
|
+
alarms=AlarmConfig(max_alarm="900") if unit == "MB/s" else AlarmConfig(),
|
|
162
|
+
events=EventConfig(change_abs="0.01"),
|
|
163
|
+
),
|
|
164
|
+
value,
|
|
165
|
+
)
|
|
166
|
+
|
|
167
|
+
index = np.arange(1024, dtype=float)
|
|
168
|
+
spectrum = 2.4 * np.exp(-0.5 * ((index - 512) / 90) ** 2) + 0.05 * np.sin(index / 12)
|
|
169
|
+
backend.register_attribute(
|
|
170
|
+
device,
|
|
171
|
+
AttributeSpec(
|
|
172
|
+
"double_spectrum",
|
|
173
|
+
TangoType.DOUBLE,
|
|
174
|
+
AttrDataFormat.SPECTRUM,
|
|
175
|
+
unit="a.u.",
|
|
176
|
+
max_dim_x=1024,
|
|
177
|
+
),
|
|
178
|
+
spectrum,
|
|
179
|
+
)
|
|
180
|
+
|
|
181
|
+
rows, columns = np.mgrid[0:256, 0:256]
|
|
182
|
+
image = 4096 * np.exp(-0.5 * (((rows - 120) / 21) ** 2 + ((columns - 112) / 17) ** 2))
|
|
183
|
+
backend.register_attribute(
|
|
184
|
+
device,
|
|
185
|
+
AttributeSpec(
|
|
186
|
+
"double_image",
|
|
187
|
+
TangoType.DOUBLE,
|
|
188
|
+
AttrDataFormat.IMAGE,
|
|
189
|
+
unit="ADU",
|
|
190
|
+
max_dim_x=256,
|
|
191
|
+
max_dim_y=256,
|
|
192
|
+
display_level=DisplayLevel.EXPERT,
|
|
193
|
+
),
|
|
194
|
+
image,
|
|
195
|
+
)
|
|
196
|
+
|
|
197
|
+
backend.register_command(device, CommandSpec("DevVoid"))
|
|
198
|
+
backend.register_command(
|
|
199
|
+
device,
|
|
200
|
+
CommandSpec("DevDouble", TangoType.DOUBLE, TangoType.DOUBLE, "echoed value"),
|
|
201
|
+
lambda _backend, argin: argin,
|
|
202
|
+
)
|
|
203
|
+
backend.register_command(
|
|
204
|
+
device,
|
|
205
|
+
CommandSpec("DevString", TangoType.STRING, TangoType.STRING),
|
|
206
|
+
lambda _backend, argin: str(argin).upper(),
|
|
207
|
+
)
|
|
208
|
+
|
|
209
|
+
|
|
210
|
+
def _build_motor(backend: FakeBackend, device: DeviceName, *, position: float) -> None:
|
|
211
|
+
backend.register_attribute(
|
|
212
|
+
device,
|
|
213
|
+
AttributeSpec(
|
|
214
|
+
"position",
|
|
215
|
+
TangoType.DOUBLE,
|
|
216
|
+
AttrDataFormat.SCALAR,
|
|
217
|
+
AttrWriteType.READ_WRITE,
|
|
218
|
+
label="Position",
|
|
219
|
+
unit="deg",
|
|
220
|
+
min_value="-180",
|
|
221
|
+
max_value="180",
|
|
222
|
+
alarms=AlarmConfig(min_alarm="-179", max_alarm="179"),
|
|
223
|
+
),
|
|
224
|
+
position,
|
|
225
|
+
)
|
|
226
|
+
backend.register_attribute(
|
|
227
|
+
device,
|
|
228
|
+
AttributeSpec(
|
|
229
|
+
"velocity",
|
|
230
|
+
TangoType.DOUBLE,
|
|
231
|
+
AttrDataFormat.SCALAR,
|
|
232
|
+
AttrWriteType.READ_WRITE,
|
|
233
|
+
unit="deg/s",
|
|
234
|
+
),
|
|
235
|
+
2.5,
|
|
236
|
+
)
|
|
237
|
+
backend.register_command(device, CommandSpec("Stop"))
|
|
238
|
+
backend.register_command(device, CommandSpec("MoveRelative", TangoType.DOUBLE, TangoType.VOID))
|
|
239
|
+
|
|
240
|
+
|
|
241
|
+
DEMO_STARTER_HOSTS: tuple[str, ...] = (
|
|
242
|
+
"id09-srv-01",
|
|
243
|
+
"id09-srv-02",
|
|
244
|
+
"id09-det-01",
|
|
245
|
+
"id09-vac-01",
|
|
246
|
+
"sr-ctl-01",
|
|
247
|
+
"sr-ctl-02",
|
|
248
|
+
)
|
|
249
|
+
|
|
250
|
+
DEMO_SERVER: ServerName = ServerName("TangoTest", "test")
|
|
251
|
+
DEMO_DEVICE: DeviceName = DeviceName("sys", "tg_test", "1")
|