File tree Expand file tree Collapse file tree 3 files changed +20
-16
lines changed
Expand file tree Collapse file tree 3 files changed +20
-16
lines changed Original file line number Diff line number Diff line change 11from __future__ import annotations
22
33import sys
4- import uuid
54from abc import ABC , abstractmethod
65from types import TracebackType
76from typing import Optional , Type , TYPE_CHECKING
@@ -24,10 +23,20 @@ class Panel(ABC):
2423
2524 __slots__ = ["_stub" , "_panel_uri" , "_panel_id" , "__weakref__" ]
2625
27- def __init__ (self , panel_uri : str ) -> None :
26+ def __init__ (self , panel_uri : str , panel_id : str ) -> None :
2827 """Initialize the panel."""
2928 self ._panel_uri = panel_uri
30- self ._panel_id = str (uuid .uuid4 ())
29+ self ._panel_id = panel_id
30+
31+ @property
32+ def panel_uri (self ) -> str :
33+ """Read-only accessor for the panel URI."""
34+ return self ._panel_uri
35+
36+ @property
37+ def panel_id (self ) -> str :
38+ """Read-only accessor for the panel ID."""
39+ return self ._panel_id
3140
3241 def __enter__ (self ) -> Self :
3342 """Enter the runtime context related to this object."""
Original file line number Diff line number Diff line change @@ -6,16 +6,17 @@ class StreamlitPanel(Panel):
66
77 __slots__ = ()
88
9- def __init__ (self , streamlit_script_uri : str ) -> None :
9+ def __init__ (self , streamlit_script_uri : str , panel_id : str ) -> None :
1010 """Create a panel using a Streamlit script for the user interface.
1111
1212 Args:
1313 streamlit_script_uri: The file path of the Streamlit script.
14+ panel_id: A unique identifier for the panel.
1415
1516 Returns:
1617 A new StreamlitPanel instance.
1718 """
18- super ().__init__ (streamlit_script_uri )
19+ super ().__init__ (streamlit_script_uri , panel_id )
1920
2021 def _resolve_service_location (self ) -> str :
2122 # TODO: AB#3095680 - resolve to the Streamlit PythonPanelService
Original file line number Diff line number Diff line change 22
33
44def test___streamlit_panel___has_panel_id_and_panel_uri () -> None :
5- panel = nipanel .StreamlitPanel ("path/to/script" )
6- assert panel ._panel_id is not None
7- assert panel ._panel_uri == "path/to/script"
8-
9-
10- def test___two_panels___have_different_panel_ids () -> None :
11- panel1 = nipanel .StreamlitPanel ("path/to/script1" )
12- panel2 = nipanel .StreamlitPanel ("path/to/script2" )
13- assert panel1 ._panel_id != panel2 ._panel_id
5+ panel = nipanel .StreamlitPanel ("path/to/script" , "my_panel" )
6+ assert panel .panel_uri == "path/to/script"
7+ assert panel .panel_id == "my_panel"
148
159
1610def test___connected_panel___set_value___gets_same_value () -> None :
17- panel = nipanel .StreamlitPanel ("path/to/script" )
11+ panel = nipanel .StreamlitPanel ("path/to/script" , "my_panel" )
1812 panel .connect ()
1913
2014 panel .set_value ("test_id" , "test_value" )
@@ -25,7 +19,7 @@ def test___connected_panel___set_value___gets_same_value() -> None:
2519
2620
2721def test___with_panel___set_value___gets_same_value () -> None :
28- with nipanel .StreamlitPanel ("path/to/script" ) as panel :
22+ with nipanel .StreamlitPanel ("path/to/script" , "my_panel" ) as panel :
2923
3024 panel .set_value ("test_id" , "test_value" )
3125
You can’t perform that action at this time.
0 commit comments