Skip to content
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"python.testing.pytestArgs": [
"tests"
],
"python.testing.unittestEnabled": false,
"python.testing.pytestEnabled": true
}
4 changes: 4 additions & 0 deletions src/nipanel/__init__.py
Original file line number Diff line number Diff line change
@@ -1 +1,5 @@
"""The NI Panel."""

from nipanel.nipanel import NiPanel

__all__ = ["NiPanel"]
77 changes: 77 additions & 0 deletions src/nipanel/nipanel.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
"""NI Panel."""

import uuid
from types import TracebackType
from typing import Optional, Type


class NiPanel:
"""This class allows you to access controls on the panel."""

def __init__(self) -> None:
"""Initialize the NiPanel instance."""
self._stub = None # will be a PythonPanelServiceStub
self.panel_uri = ""
self.panel_id = ""

def __enter__(self) -> "NiPanel":
"""Enter the runtime context related to this object."""
self.connect()
return self

def __exit__(
self,
exctype: Optional[Type[BaseException]],
excinst: Optional[BaseException],
exctb: Optional[TracebackType],
) -> Optional[bool]:
"""Exit the runtime context related to this object."""
self.disconnect()
return None

@classmethod
def streamlit_panel(cls, streamlit_script_path: str) -> "NiPanel":
"""Create a panel using a streamlit script for the user interface.
Args:
streamlit_script_path: The file path of the streamlit script
Returns:
NiPanel: A new panel associated with the streamlit script
"""
panel = cls()
panel.panel_uri = streamlit_script_path
panel.panel_id = str(uuid.uuid4())
return panel

def connect(self) -> None:
"""Connect to the panel and open it."""
# TODO: AB#3095680 - Use gRPC pool management, create the _stub, and call _stub.Connect
pass

def disconnect(self) -> None:
"""Disconnect from the panel (does not close the panel)."""
# TODO: AB#3095680 - Use gRPC pool management, call _stub.Disconnect
pass

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:
object: The value
"""
# TODO: AB#3095681 - get the Any from _stub.GetValue and convert it to the correct type
return "placeholder value"

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
"""
# TODO: AB#3095681 - Convert the value to an Any and pass it to _stub.SetValue
pass
1 change: 1 addition & 0 deletions tests/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
"""Tests for the `nipanel` package."""
19 changes: 19 additions & 0 deletions tests/unit/test_nipanel.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
from nipanel import NiPanel


def test_streamlit_panel() -> None:
panel = NiPanel.streamlit_panel("path/to/script")
assert panel.panel_uri == "path/to/script"
assert panel.panel_id is not None
panel.connect()
panel.set_value("test_id", "test_value")
assert panel.get_value("test_id") == "placeholder value"
panel.disconnect()


def test_with_streamlit_panel() -> None:
with NiPanel.streamlit_panel("path/to/script") as panel:
assert panel.panel_uri == "path/to/script"
assert panel.panel_id is not None
panel.set_value("test_id", "test_value")
assert panel.get_value("test_id") == "placeholder value"
2 changes: 0 additions & 2 deletions tests/unit/test_placeholder.py

This file was deleted.