-
Couldn't load subscription status.
- Fork 0
Add a panel accessor class for streamlit scripts to call #31
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
mikeprosserni
merged 16 commits into
main
from
users/mprosser/task-3121341-panel-accessor
May 27, 2025
Merged
Changes from 10 commits
Commits
Show all changes
16 commits
Select commit
Hold shift + click to select a range
6861bfc
streamlit panel accessor
fb93400
cleanup
470cc61
add streamlit dependency
24ef502
try python ^3.11
859832d
try python = "^3.9.13"
eb832d1
use Poetry 1.8.2
49b10e0
python = "^3.9.8" (since streamlit is incompatible with 3.9.7)
b682599
lock file for 3.9.8
77069e6
cleanup - we aren't doing the component initialization in this PR
5fc6993
python = ">=3.9,<4.0,!=3.9.7" # Exclude 3.9.7 due to streamlit not su…
ce4f0f5
Johann's feedback
76a79e5
clean up __slots__
d4526a9
rename to PanelValueAccessor
72865e5
Merge branch 'main' of https://github.com/ni/nipanel-python into user…
cc73ce5
test___different_panels___have_different_panel_ids_and_uris
816d98d
remove class-level type declarations
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,61 @@ | ||
| from __future__ import annotations | ||
|
|
||
| import grpc | ||
| from ni_measurement_plugin_sdk_service.discovery import DiscoveryClient | ||
| from ni_measurement_plugin_sdk_service.grpc.channelpool import GrpcChannelPool | ||
|
|
||
| from nipanel._panel_client import PanelClient | ||
|
|
||
|
|
||
| class PanelAccessor: | ||
mikeprosserni marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
csjall marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| """This class allows you to access values for a panel's controls.""" | ||
|
|
||
| _panel_client: PanelClient | ||
| _panel_id: str | ||
|
|
||
| __slots__ = ["_panel_client", "_panel_id"] | ||
mikeprosserni marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
| def __init__( | ||
| self, | ||
| *, | ||
| panel_id: str, | ||
| provided_interface: str, | ||
| service_class: str, | ||
| discovery_client: DiscoveryClient | None = None, | ||
| grpc_channel_pool: GrpcChannelPool | None = None, | ||
| grpc_channel: grpc.Channel | None = None, | ||
| ) -> None: | ||
| """Initialize the accessor.""" | ||
| self._panel_client = PanelClient( | ||
| provided_interface=provided_interface, | ||
| service_class=service_class, | ||
| discovery_client=discovery_client, | ||
| grpc_channel_pool=grpc_channel_pool, | ||
| grpc_channel=grpc_channel, | ||
| ) | ||
| self._panel_id = panel_id | ||
|
|
||
| @property | ||
| def panel_id(self) -> str: | ||
| """Read-only accessor for the panel ID.""" | ||
| return self._panel_id | ||
|
|
||
| def get_value(self, value_id: str) -> object: | ||
| """Get the value for a control on the panel. | ||
| Args: | ||
| value_id: The id of the value | ||
| Returns: | ||
| The value | ||
| """ | ||
| return self._panel_client.get_value(self._panel_id, value_id) | ||
|
|
||
| def set_value(self, value_id: str, value: object) -> None: | ||
| """Set the value for a control on the panel. | ||
| Args: | ||
| value_id: The id of the value | ||
| value: The value | ||
| """ | ||
| self._panel_client.set_value(self._panel_id, value_id, value) | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| STREAMLIT_PYTHON_PANEL_SERVICE = "ni.pythonpanel.v1.PythonPanelService" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,38 @@ | ||
| from __future__ import annotations | ||
|
|
||
| import grpc | ||
| from ni_measurement_plugin_sdk_service.discovery import DiscoveryClient | ||
| from ni_measurement_plugin_sdk_service.grpc.channelpool import GrpcChannelPool | ||
|
|
||
| from nipanel._panel_accessor import PanelAccessor | ||
| from nipanel._streamlit_constants import STREAMLIT_PYTHON_PANEL_SERVICE | ||
|
|
||
|
|
||
| class StreamlitPanelAccessor(PanelAccessor): | ||
mikeprosserni marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| """This class provides access to values for a Streamlit panel's controls.""" | ||
|
|
||
| def __init__( | ||
| self, | ||
| panel_id: str, | ||
| *, | ||
| discovery_client: DiscoveryClient | None = None, | ||
| grpc_channel_pool: GrpcChannelPool | None = None, | ||
| grpc_channel: grpc.Channel | None = None, | ||
| ) -> None: | ||
| """Create an accessor for a Streamlit panel. | ||
| Args: | ||
| panel_id: A unique identifier for the panel. | ||
| grpc_channel: An optional gRPC channel to use for communication with the panel service. | ||
| Returns: | ||
| A new StreamlitPanelAccessor instance. | ||
| """ | ||
| super().__init__( | ||
| panel_id=panel_id, | ||
| provided_interface=STREAMLIT_PYTHON_PANEL_SERVICE, | ||
| service_class=STREAMLIT_PYTHON_PANEL_SERVICE, | ||
| discovery_client=discovery_client, | ||
| grpc_channel_pool=grpc_channel_pool, | ||
| grpc_channel=grpc_channel, | ||
| ) | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.