1818class Panel (ABC ):
1919 """This class allows you to connect to a panel and specify values for its controls."""
2020
21+ _stub : PythonPanelServiceStub | None
22+ _panel_uri : str
23+ _panel_id : str
24+
25+ __slots__ = ["_stub" , "_panel_uri" , "_panel_id" , "__weakref__" ]
26+
27+ def __init__ (self , panel_uri : str ) -> None :
28+ """Initialize the panel."""
29+ self ._panel_uri = panel_uri
30+ self ._panel_id = str (uuid .uuid4 ())
31+
2132 def __enter__ (self ) -> Self :
2233 """Enter the runtime context related to this object."""
2334 self .connect ()
@@ -33,17 +44,16 @@ def __exit__(
3344 self .disconnect ()
3445 return None
3546
36- @abstractmethod
3747 def connect (self ) -> None :
3848 """Connect to the panel and open it."""
39- pass
49+ # TODO: AB#3095680 - Use gRPC pool management, create the _stub, and call _stub.Connect
50+ self ._resolve_service_location ()
4051
41- @abstractmethod
4252 def disconnect (self ) -> None :
4353 """Disconnect from the panel (does not close the panel)."""
54+ # TODO: AB#3095680 - Use gRPC pool management, call _stub.Disconnect
4455 pass
4556
46- @abstractmethod
4757 def get_value (self , value_id : str ) -> object :
4858 """Get the value for a control on the panel.
4959
@@ -53,56 +63,20 @@ def get_value(self, value_id: str) -> object:
5363 Returns:
5464 The value
5565 """
56- pass
66+ # TODO: AB#3095681 - get the Any from _stub.GetValue and convert it to the correct type
67+ return "placeholder value"
5768
58- @abstractmethod
5969 def set_value (self , value_id : str , value : object ) -> None :
6070 """Set the value for a control on the panel.
6171
6272 Args:
6373 value_id: The id of the value
6474 value: The value
6575 """
66- pass
67-
68- @classmethod
69- def streamlit_panel (cls , streamlit_script_path : str ) -> Panel :
70- """Create a panel using a streamlit script for the user interface.
71-
72- Args:
73- streamlit_script_path: The file path of the Streamlit script.
74-
75- Returns:
76- A new StreamlitPanel instance.
77- """
78- return _StreamlitPanel (streamlit_script_path )
79-
80-
81- class _StreamlitPanel (Panel ):
82-
83- _stub : PythonPanelServiceStub | None
84- _streamlit_script_uri : str
85- _panel_id : str
86-
87- __slots__ = ["_stub" , "_streamlit_script_uri" , "_panel_id" ]
88-
89- def __init__ (self , streamlit_script_uri : str ):
90- self ._streamlit_script_uri = streamlit_script_uri
91- self ._panel_id = str (uuid .uuid4 ())
92- self ._stub = None # Initialize the gRPC stub
93-
94- def connect (self ) -> None :
95- # TODO: AB#3095680 - Use gRPC pool management, create the _stub, and call _stub.Connect
96- pass
97-
98- def disconnect (self ) -> None :
99- # TODO: AB#3095680 - Use gRPC pool management, call _stub.Disconnect
100- pass
101-
102- def get_value (self , value_id : str ) -> object :
103- # TODO: AB#3095681 - get the Any from _stub.GetValue and convert it to the correct type
104- return "placeholder value"
105-
106- def set_value (self , value_id : str , value : object ) -> None :
10776 # TODO: AB#3095681 - Convert the value to an Any and pass it to _stub.SetValue
10877 pass
78+
79+ @abstractmethod
80+ def _resolve_service_location (self ) -> str :
81+ """Resolve the service location for the panel."""
82+ raise NotImplementedError
0 commit comments