1- """NI Panel."""
1+ from __future__ import annotations
22
3+ import sys
34import uuid
45from types import TracebackType
5- from typing import Optional , Type
6+ from typing import Optional , Type , TYPE_CHECKING
67
8+ from ni .pythonpanel .v1 .python_panel_service_pb2_grpc import PythonPanelServiceStub
79
8- class NiPanel :
9- """This class allows you to access controls on the panel."""
10+ if TYPE_CHECKING :
11+ if sys .version_info >= (3 , 11 ):
12+ from typing import Self
13+ else :
14+ from typing_extensions import Self
1015
11- def __init__ (self ) -> None :
12- """Initialize the NiPanel instance."""
13- self ._stub = None # will be a PythonPanelServiceStub
14- self .panel_uri = ""
15- self .panel_id = ""
1616
17- def __enter__ (self ) -> "NiPanel" :
17+ class Panel :
18+ """This class allows you to connect to a panel and specify values for its controls."""
19+
20+ _stub : PythonPanelServiceStub | None
21+ _panel_uri : str
22+ _panel_id : str
23+
24+ __slots__ = ["_stub" , "_panel_uri" , "_panel_id" , "__weakref__" ]
25+
26+ def __enter__ (self ) -> Self :
1827 """Enter the runtime context related to this object."""
1928 self .connect ()
2029 return self
@@ -30,18 +39,18 @@ def __exit__(
3039 return None
3140
3241 @classmethod
33- def streamlit_panel (cls , streamlit_script_path : str ) -> "NiPanel" :
42+ def streamlit_panel (cls , streamlit_script_path : str ) -> Self :
3443 """Create a panel using a streamlit script for the user interface.
3544
3645 Args:
3746 streamlit_script_path: The file path of the streamlit script
3847
3948 Returns:
40- NiPanel: A new panel associated with the streamlit script
49+ A new panel associated with the streamlit script
4150 """
4251 panel = cls ()
43- panel .panel_uri = streamlit_script_path
44- panel .panel_id = str (uuid .uuid4 ())
52+ panel ._panel_uri = streamlit_script_path
53+ panel ._panel_id = str (uuid .uuid4 ())
4554 return panel
4655
4756 def connect (self ) -> None :
@@ -61,7 +70,7 @@ def get_value(self, value_id: str) -> object:
6170 value_id: The id of the value
6271
6372 Returns:
64- object: The value
73+ The value
6574 """
6675 # TODO: AB#3095681 - get the Any from _stub.GetValue and convert it to the correct type
6776 return "placeholder value"
0 commit comments