|
18 | 18 |
|
19 | 19 | import configparser as cp |
20 | 20 | import importlib |
| 21 | +import json |
21 | 22 | import os |
22 | 23 | import os.path as osp |
23 | 24 | import sys |
@@ -167,6 +168,27 @@ def items_to_json(items: list) -> str | None: |
167 | 168 | return None |
168 | 169 |
|
169 | 170 |
|
| 171 | +def json_to_items(json_str: str | None) -> list: |
| 172 | + """Convert JSON string to plot items. |
| 173 | +
|
| 174 | + Args: |
| 175 | + json_str (str): JSON string or None |
| 176 | +
|
| 177 | + Returns: |
| 178 | + list: list of plot items |
| 179 | + """ |
| 180 | + from plotpy.io import load_items # pylint: disable=import-outside-toplevel |
| 181 | + |
| 182 | + items = [] |
| 183 | + if json_str: |
| 184 | + try: |
| 185 | + for item in load_items(JSONReader(json_str)): |
| 186 | + items.append(item) |
| 187 | + except json.decoder.JSONDecodeError: |
| 188 | + pass |
| 189 | + return items |
| 190 | + |
| 191 | + |
170 | 192 | class SimpleRemoteProxy(SimpleBaseProxy): |
171 | 193 | """Object representing a proxy/client to DataLab XML-RPC server. |
172 | 194 | This object is used to call DataLab functions from a Python script. |
@@ -355,6 +377,29 @@ def calc(self, name: str, param: gds.DataSet | None = None) -> gds.DataSet: |
355 | 377 | return self._cdl.calc(name) |
356 | 378 | return self._cdl.calc(name, dataset_to_json(param)) |
357 | 379 |
|
| 380 | + def get_object_shapes( |
| 381 | + self, |
| 382 | + index: int | None = None, |
| 383 | + group_index: int | None = None, |
| 384 | + panel: str | None = None, |
| 385 | + ) -> list: |
| 386 | + """Get plot item shapes associated to object (signal/image). |
| 387 | +
|
| 388 | + Args: |
| 389 | + index: Object index in current panel. Defaults to None. |
| 390 | + group_index: Group index. Defaults to None. |
| 391 | + panel: Panel name. Defaults to None. |
| 392 | +
|
| 393 | + If ``index`` is not specified, returns the currently selected object. |
| 394 | + If ``group_index`` is not specified, return an object from the current group. |
| 395 | + If ``panel`` is not specified, return an object from the current panel. |
| 396 | +
|
| 397 | + Returns: |
| 398 | + List of plot item shapes |
| 399 | + """ |
| 400 | + items_json = self._cdl.get_object_shapes(index, group_index, panel) |
| 401 | + return json_to_items(items_json) |
| 402 | + |
358 | 403 | def add_annotations_from_items( |
359 | 404 | self, items: list, refresh_plot: bool = True, panel: str | None = None |
360 | 405 | ) -> None: |
|
0 commit comments