|
1 | 1 | import asyncio
|
2 | 2 | import sys
|
3 | 3 | from inspect import isawaitable, iscoroutinefunction
|
| 4 | +from typing import Dict, List |
4 | 5 | from IPython import get_ipython
|
5 | 6 | from queue import Queue
|
6 | 7 | from imjoy_rpc.utils import FuturePromise
|
|
9 | 10 |
|
10 | 11 |
|
11 | 12 | class Viewers(object):
|
| 13 | + """This class is designed to track each instance of the Viewer class that |
| 14 | + is instantiated as well as whether or not that instance is available for |
| 15 | + updates or requests. |
| 16 | + """ |
12 | 17 | def __init__(self):
|
13 | 18 | self._data = {}
|
14 | 19 |
|
15 | 20 | @property
|
16 |
| - def data(self): |
| 21 | + def data(self) -> Dict[str, Dict[str, bool]]: |
| 22 | + """Get the underlying data dict containg all viewer data |
| 23 | +
|
| 24 | + :return: The data object that contains all created Viewer information. |
| 25 | + :rtype: Dict[str, Dict[str, bool]] |
| 26 | + """ |
17 | 27 | return self._data
|
18 | 28 |
|
19 | 29 | @property
|
20 |
| - def not_created(self): |
21 |
| - # Return a list of names of viewers that have not been created yet |
| 30 | + def not_created(self) -> List[str]: |
| 31 | + """Return a list of all unavailable viewers |
| 32 | +
|
| 33 | + :return: A list of names of viewers that have not yet been created. |
| 34 | + :rtype: List[str] |
| 35 | + """ |
22 | 36 | return [k for k in self.data.keys() if not self.viewer_ready(k)]
|
23 | 37 |
|
24 | 38 | def add_viewer(self, view: str) -> None:
|
| 39 | + """Add a new Viewer object to track. |
| 40 | +
|
| 41 | + :param view: The unique string identifier for the Viewer object |
| 42 | + :type view: str |
| 43 | + """ |
25 | 44 | self.data[view] = {"ready": False}
|
26 | 45 |
|
27 |
| - def update_viewer_status(self, view, status): |
| 46 | + def update_viewer_status(self, view: str, status: bool) -> None: |
| 47 | + """Update a Viewer's 'ready' status. |
| 48 | +
|
| 49 | + :param view: The unique string identifier for the Viewer object |
| 50 | + :type view: str |
| 51 | + :param status: Boolean value indicating whether or not the viewer is |
| 52 | + available for requests or updates. This should be false when the plugin |
| 53 | + API is not yet available or new data is not yet rendered. |
| 54 | + :type status: bool |
| 55 | + """ |
28 | 56 | if view not in self.data.keys():
|
29 | 57 | self.add_viewer(view)
|
30 | 58 | self.data[view]["ready"] = status
|
31 | 59 |
|
32 | 60 | def viewer_ready(self, view: str) -> bool:
|
| 61 | + """Request the 'ready' status of a viewer. |
| 62 | +
|
| 63 | + :param view: The unique string identifier for the Viewer object |
| 64 | + :type view: str |
| 65 | +
|
| 66 | + :return: Boolean value indicating whether or not the viewer is |
| 67 | + available for requests or updates. This will be false when the plugin |
| 68 | + API is not yet available or new data is not yet rendered. |
| 69 | + :rtype: bool |
| 70 | + """ |
33 | 71 | return self.data.get(view, {}).get("ready", False)
|
34 | 72 |
|
35 | 73 |
|
|
0 commit comments