Skip to content

Commit d3a1df8

Browse files
Mike ProsserMike Prosser
authored andcommitted
add nitypes to all_types, and update comments
1 parent 81a4c57 commit d3a1df8

File tree

5 files changed

+26
-15
lines changed

5 files changed

+26
-15
lines changed

examples/all_types/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
## All Types Example
22

3-
This is a nipanel example that demonstrates all supported data types
3+
This is an example for `nipanel` that demonstrates all supported data types
44

55
### Feature
66

examples/all_types/all_types.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
"""example script for nipanel package demonstrating various data types."""
1+
"""An example that demonstrates the supported data types for nipanel scripts."""
22

33
from pathlib import Path
44

examples/all_types/all_types_panel.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
"""A Streamlit panel to demonstrate various types and their values."""
1+
"""A Streamlit visualization panel for the all_types.py example script."""
22

33
import streamlit as st
44
from define_types import all_types_with_values

examples/all_types/define_types.py

Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,10 @@
22

33
import enum
44

5+
import numpy as np
6+
from nitypes.scalar import Scalar
7+
from nitypes.waveform import AnalogWaveform
8+
59

610
class MyIntFlags(enum.IntFlag):
711
"""Example of an IntFlag enum."""
@@ -29,21 +33,21 @@ class MyStrEnum(str, enum.Enum):
2933

3034
all_types_with_values = {
3135
# supported scalar types
32-
"bool_scalar": True,
33-
"bytes_scalar": b"robotext",
34-
"float_scalar": 13.12,
35-
"int_scalar": 42,
36-
"str_scalar": "sample string",
36+
"bool": True,
37+
"bytes": b"robotext",
38+
"float": 13.12,
39+
"int": 42,
40+
"str": "sample string",
3741
# supported collection types
3842
"bool_collection": [True, False, True],
3943
"bytes_collection": [b"one", b"two", b"three"],
4044
"float_collection": [1.1, 2.2, 3.3],
4145
"int_collection": [1, 2, 3],
4246
"str_collection": ["one", "two", "three"],
4347
# supported enum and flag types
44-
"intflags_scalar": MyIntFlags.VALUE1 | MyIntFlags.VALUE4,
45-
"intenum_scalar": MyIntEnum.VALUE20,
46-
"strenum_scalar": MyStrEnum.VALUE3,
48+
"intflags": MyIntFlags.VALUE1 | MyIntFlags.VALUE4,
49+
"intenum": MyIntEnum.VALUE20,
50+
"strenum": MyStrEnum.VALUE3,
4751
"intflags_collection": [MyIntFlags.VALUE1, MyIntFlags.VALUE2, MyIntFlags.VALUE4],
4852
"intenum_collection": [MyIntEnum.VALUE10, MyIntEnum.VALUE20, MyIntEnum.VALUE30],
4953
"strenum_collection": [MyStrEnum.VALUE1, MyStrEnum.VALUE2, MyStrEnum.VALUE3],
@@ -52,4 +56,7 @@ class MyStrEnum(str, enum.Enum):
5256
"tuple": (4, 5, 6),
5357
"set": {7, 8, 9},
5458
"frozenset": frozenset([10, 11, 12]),
59+
# NI types
60+
"nitypes_Scalar": Scalar(42, "m"),
61+
"nitypes_AnalogWaveform": AnalogWaveform.from_array_1d(np.array([1.0, 2.0, 3.0])),
5562
}

src/nipanel/_streamlit_panel_initializer.py

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,13 @@
1313
def create_panel(streamlit_script_path: Path) -> StreamlitPanel:
1414
"""Create a Streamlit panel with the specified script path.
1515
16-
This function initializes a Streamlit panel using the provided script path.
17-
The panel ID will be derived from the script path, which is expected to be a valid Streamlit script.
18-
It is typically used to create a new panel instance for use in a Streamlit application.
16+
This function initializes a Streamlit panel using the provided script path. It derives the panel
17+
ID from the script's path, which it expects to be a valid Streamlit script. For example, if the
18+
value for streamlit_script_path is "c:/example/some_example.py", then the panel's ID becomes
19+
"some_example".
20+
21+
Use this function when you want to create a new panel instance to use in a Streamlit
22+
application.
1923
2024
Args:
2125
streamlit_script_path: The file path of the Streamlit script to be used for the panel.
@@ -29,7 +33,7 @@ def create_panel(streamlit_script_path: Path) -> StreamlitPanel:
2933
"The provided script path must be a valid Streamlit script ending with '.py'."
3034
)
3135

32-
panel_id = path_str.replace("\\", "/").split("/")[-1].replace(".py", "")
36+
panel_id = streamlit_script_path.stem
3337
return StreamlitPanel(panel_id, path_str)
3438

3539

0 commit comments

Comments
 (0)