Skip to content

Commit 89d9c2e

Browse files
author
Dilmi Wickramanayake
committed
Merge branch 'main' of https://github.com/ni/nipanel-python
2 parents 6d2ec85 + dcaf336 commit 89d9c2e

24 files changed

+569
-209
lines changed

.github/renovate.json

Lines changed: 0 additions & 11 deletions
This file was deleted.

.github/renovate.json5

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
{
2+
"$schema": "https://docs.renovatebot.com/renovate-schema.json",
3+
"branchPrefix": "users/renovate/",
4+
"timezone": "US/Central",
5+
"extends": [
6+
"config:recommended",
7+
"helpers:pinGitHubActionDigestsToSemver",
8+
":enableVulnerabilityAlerts"
9+
],
10+
"packageRules": [
11+
{
12+
// Update GitHub Actions on weekends.
13+
"matchCategories": ["github-actions"],
14+
"groupName": "GitHub Actions",
15+
"groupSlug": "github",
16+
"schedule": [
17+
"* * * * 0,6"
18+
]
19+
},
20+
{
21+
// Update Python packages on weekends, separate from lockFileMaintenance.
22+
"matchCategories": ["python"],
23+
"matchUpdateTypes": ["major", "minor", "patch", "rollback", "replacement"],
24+
"groupName": "Python packages",
25+
"groupSlug": "python",
26+
"schedule": [
27+
"* * * * 0,6"
28+
]
29+
}
30+
],
31+
"lockFileMaintenance": {
32+
// Maintain lock files on early Tuesday mornings. This is primarily to
33+
// update indirect dependencies that aren't handled by the Python packages
34+
// group.
35+
"enabled": true,
36+
"schedule": [
37+
"* 0-3 * * 2"
38+
]
39+
},
40+
"osvVulnerabilityAlerts": true
41+
}

CONTRIBUTING.md

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,18 @@ poetry run sphinx-build docs docs/_build --builder html --fail-on-warning
5454
start docs\_build\index.html
5555
```
5656

57+
## Running examples
58+
59+
1. First, run the PythonPanelService (not part of this repo, provided seperately)
60+
2. Run the command `poetry run python examples/hello/hello.py`
61+
3. Open http://localhost:42001/panel-service/panels/hello_panel/ in your browser
62+
4. If there is an error about missing imports (especially nipanel), execute this
63+
command (from the nipanel-python directory) to install the dependencies into the venv:
64+
`%localappdata%\Temp\python_panel_service_venv\Scripts\python.exe -m pip install .\[examples,dev]`,
65+
then restart the PythonPanelService and re-run hello.py.
66+
67+
You can see all running panels (and stop them) at: http://localhost:42001/panel-service/
68+
5769
# Debugging on the streamlit side
5870

5971
Debugging the measurement script can be done using standard Python debugging

examples/all_types/README.md

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
## All Types Example
2+
3+
This is an example for `nipanel` that demonstrates all supported data types
4+
5+
### Feature
6+
7+
- Demonstrates support for all data types
8+
9+
### Required Software
10+
11+
- Python 3.9 or later
12+
13+
### Usage
14+
15+
Run `poetry run python examples/all_types/all_types.py`

examples/all_types/all_types.py

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
"""An example that demonstrates the supported data types for nipanel scripts."""
2+
3+
from pathlib import Path
4+
5+
from define_types import all_types_with_values
6+
7+
import nipanel
8+
9+
panel_script_path = Path(__file__).with_name("all_types_panel.py")
10+
panel = nipanel.create_panel(panel_script_path)
11+
12+
print("Setting values")
13+
for name, value in all_types_with_values.items():
14+
print(f"{name:>15} {value}")
15+
panel.set_value(name, value)
16+
17+
print()
18+
print("Getting values")
19+
for name in all_types_with_values.keys():
20+
the_value = panel.get_value(name)
21+
print(f"{name:>20} {the_value}")
22+
23+
print(f"Panel URL: {panel.panel_url}")
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
"""A Streamlit visualization panel for the all_types.py example script."""
2+
3+
import streamlit as st
4+
from define_types import all_types_with_values
5+
6+
import nipanel
7+
8+
panel = nipanel.get_panel_accessor()
9+
10+
st.set_page_config(page_title="All Types Example", page_icon="📊", layout="wide")
11+
st.title("All Types Example")
12+
13+
for name in all_types_with_values.keys():
14+
col1, col2 = st.columns([0.4, 0.6])
15+
16+
with col1:
17+
st.write(name)
18+
19+
with col2:
20+
st.write(panel.get_value(name))

examples/all_types/define_types.py

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
"""Define types."""
2+
3+
import enum
4+
5+
import numpy as np
6+
from nitypes.scalar import Scalar
7+
from nitypes.waveform import AnalogWaveform
8+
9+
10+
class MyIntFlags(enum.IntFlag):
11+
"""Example of an IntFlag enum."""
12+
13+
VALUE1 = 1
14+
VALUE2 = 2
15+
VALUE4 = 4
16+
17+
18+
class MyIntEnum(enum.IntEnum):
19+
"""Example of an IntEnum enum."""
20+
21+
VALUE10 = 10
22+
VALUE20 = 20
23+
VALUE30 = 30
24+
25+
26+
class MyStrEnum(str, enum.Enum):
27+
"""Example of a mixin string enum."""
28+
29+
VALUE1 = "value1"
30+
VALUE2 = "value2"
31+
VALUE3 = "value3"
32+
33+
34+
all_types_with_values = {
35+
# supported scalar types
36+
"bool": True,
37+
"bytes": b"robotext",
38+
"float": 13.12,
39+
"int": 42,
40+
"str": "sample string",
41+
# supported collection types
42+
"bool_collection": [True, False, True],
43+
"bytes_collection": [b"one", b"two", b"three"],
44+
"float_collection": [1.1, 2.2, 3.3],
45+
"int_collection": [1, 2, 3],
46+
"str_collection": ["one", "two", "three"],
47+
# supported enum and flag types
48+
"intflags": MyIntFlags.VALUE1 | MyIntFlags.VALUE4,
49+
"intenum": MyIntEnum.VALUE20,
50+
"strenum": MyStrEnum.VALUE3,
51+
"intflags_collection": [MyIntFlags.VALUE1, MyIntFlags.VALUE2, MyIntFlags.VALUE4],
52+
"intenum_collection": [MyIntEnum.VALUE10, MyIntEnum.VALUE20, MyIntEnum.VALUE30],
53+
"strenum_collection": [MyStrEnum.VALUE1, MyStrEnum.VALUE2, MyStrEnum.VALUE3],
54+
# supported collections
55+
"list": [1, 2, 3],
56+
"tuple": (4, 5, 6),
57+
"set": {7, 8, 9},
58+
"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])),
62+
}

examples/hello/README.md

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
## Hello
2+
3+
This is a simple nipanel example that displays a Streamlit app.
4+
5+
### Feature
6+
7+
- Just a Hello World
8+
9+
### Required Software
10+
11+
- Python 3.9 or later
12+
13+
### Usage
14+
15+
Run `poetry run python examples/hello/hello.py`

examples/hello/hello.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
"""This example demonstrates how to open/update a Streamlit application using nipanel package."""
2+
3+
from pathlib import Path
4+
5+
import nipanel
6+
7+
panel_script_path = Path(__file__).with_name("hello_panel.py")
8+
panel = nipanel.create_panel(panel_script_path)
9+
10+
panel.set_value("hello_string", "Hello, World!")
11+
12+
print(f"Panel URL: {panel.panel_url}")

examples/hello/hello_panel.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
"""A Streamlit visualization panel for the hello.py example script."""
2+
3+
import streamlit as st
4+
5+
import nipanel
6+
7+
panel = nipanel.get_panel_accessor()
8+
9+
st.set_page_config(page_title="Hello World Example", page_icon="📊", layout="wide")
10+
st.title("Hello World Example")
11+
st.write(panel.get_value("hello_string", ""))

0 commit comments

Comments
 (0)