22
33import sys
44import uuid
5+ from abc import ABC , abstractmethod
56from types import TracebackType
67from typing import Optional , Type , TYPE_CHECKING
78
1415 from typing_extensions import Self
1516
1617
17- class Panel :
18+ class Panel ( ABC ) :
1819 """This class allows you to connect to a panel and specify values for its controls."""
1920
20- _stub : PythonPanelServiceStub | None
21- _panel_uri : str
22- _panel_id : str
23-
24- __slots__ = ["_stub" , "_panel_uri" , "_panel_id" , "__weakref__" ]
25-
2621 def __enter__ (self ) -> Self :
2722 """Enter the runtime context related to this object."""
2823 self .connect ()
@@ -38,31 +33,17 @@ def __exit__(
3833 self .disconnect ()
3934 return None
4035
41- @classmethod
42- def streamlit_panel (cls , streamlit_script_path : str ) -> Self :
43- """Create a panel using a streamlit script for the user interface.
44-
45- Args:
46- streamlit_script_path: The file path of the streamlit script
47-
48- Returns:
49- A new panel associated with the streamlit script
50- """
51- panel = cls ()
52- panel ._panel_uri = streamlit_script_path
53- panel ._panel_id = str (uuid .uuid4 ())
54- return panel
55-
36+ @abstractmethod
5637 def connect (self ) -> None :
5738 """Connect to the panel and open it."""
58- # TODO: AB#3095680 - Use gRPC pool management, create the _stub, and call _stub.Connect
5939 pass
6040
41+ @abstractmethod
6142 def disconnect (self ) -> None :
6243 """Disconnect from the panel (does not close the panel)."""
63- # TODO: AB#3095680 - Use gRPC pool management, call _stub.Disconnect
6444 pass
6545
46+ @abstractmethod
6647 def get_value (self , value_id : str ) -> object :
6748 """Get the value for a control on the panel.
6849
@@ -72,15 +53,56 @@ def get_value(self, value_id: str) -> object:
7253 Returns:
7354 The value
7455 """
75- # TODO: AB#3095681 - get the Any from _stub.GetValue and convert it to the correct type
76- return "placeholder value"
56+ pass
7757
58+ @abstractmethod
7859 def set_value (self , value_id : str , value : object ) -> None :
7960 """Set the value for a control on the panel.
8061
8162 Args:
8263 value_id: The id of the value
8364 value: The value
8465 """
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 :
85107 # TODO: AB#3095681 - Convert the value to an Any and pass it to _stub.SetValue
86108 pass
0 commit comments