Skip to content

Commit 2731464

Browse files
Mike ProsserMike Prosser
authored andcommitted
cosmetic improvements for the nidaqmx example panel
1 parent 285401f commit 2731464

File tree

1 file changed

+179
-176
lines changed

1 file changed

+179
-176
lines changed

examples/nidaqmx/nidaqmx_continuous_analog_input_panel.py

Lines changed: 179 additions & 176 deletions
Original file line numberDiff line numberDiff line change
@@ -13,37 +13,36 @@
1313
import nipanel
1414

1515

16-
st.set_page_config(page_title="NI-DAQmx Example", page_icon="📈", layout="wide")
17-
st.title("Analog Input - Voltage and Thermocouple in a Single Task")
18-
19-
panel = nipanel.get_panel_accessor()
20-
21-
is_running = panel.get_value("is_running", False)
22-
if is_running:
23-
st.button("Stop", key="stop_button")
24-
else:
25-
st.button("Run", key="run_button")
26-
2716
st.markdown(
2817
"""
2918
<style>
3019
div[data-baseweb="select"] {
31-
width: 190px !important; /* Adjust the width as needed */
20+
max-width: 250px !important;
3221
}
3322
div.stNumberInput {
34-
width: 190px !important;
23+
max-width: 250px !important;
3524
}
3625
div.stTextInput {
37-
width: 190px !important;
26+
max-width: 250px !important;
3827
}
3928
</style>
4029
""",
4130
unsafe_allow_html=True,
4231
)
4332

33+
st.set_page_config(page_title="NI-DAQmx Example", page_icon="📈", layout="wide")
34+
st.title("Analog Input - Voltage and Thermocouple in a Single Task")
35+
36+
panel = nipanel.get_panel_accessor()
37+
is_running = panel.get_value("is_running", False)
38+
39+
if is_running:
40+
st.button(r"⏹️ $\large{\textbf{Stop}}$", key="stop_button")
41+
else:
42+
st.button(r"▶️ $\large{\textbf{Run}}$", key="run_button")
43+
4444
thermocouple_data = panel.get_value("thermocouple_data", [0.0])
4545
voltage_data = panel.get_value("voltage_data", [0.0])
46-
4746
sample_rate = panel.get_value("sample_rate", 0.0)
4847

4948
# Create two-column layout for the entire interface
@@ -52,182 +51,186 @@
5251
# Left column - Channel tabs and Timing Settings
5352
with left_col:
5453
# Channel Settings tabs
55-
st.header("Channel Settings")
56-
voltage_tab, thermocouple_tab = st.tabs(["Voltage", "Thermocouple"])
54+
with st.container(border=True):
55+
st.header("Channel Settings")
56+
voltage_tab, thermocouple_tab = st.tabs(["Voltage", "Thermocouple"])
57+
58+
voltage_tab.header("Voltage")
59+
with voltage_tab:
60+
channel_left, channel_right = st.columns(2)
61+
with channel_left:
62+
st.selectbox(options=["Dev1/ai0"], label="Physical Channels", disabled=True)
63+
st.number_input(
64+
"Min Value",
65+
value=-5.0,
66+
step=0.1,
67+
disabled=panel.get_value("is_running", False),
68+
key="voltage_min_value",
69+
)
70+
st.number_input(
71+
"Max Value",
72+
value=5.0,
73+
step=0.1,
74+
disabled=panel.get_value("is_running", False),
75+
key="voltage_max_value",
76+
)
77+
with channel_right:
78+
nipanel.enum_selectbox(
79+
panel,
80+
label="Terminal Configuration",
81+
value=TerminalConfiguration.DEFAULT,
82+
disabled=panel.get_value("is_running", False),
83+
key="terminal_configuration",
84+
)
85+
86+
thermocouple_tab.header("Thermocouple")
87+
with thermocouple_tab:
88+
channel_left, channel_middle, channel_right = st.columns(3)
89+
with channel_left:
90+
st.selectbox(options=["Dev1/ai1"], label="Physical Channel", disabled=True)
91+
st.number_input(
92+
"Min Value",
93+
value=0.0,
94+
step=1.0,
95+
disabled=panel.get_value("is_running", False),
96+
key="thermocouple_min_value",
97+
)
98+
st.number_input(
99+
"Max Value",
100+
value=100.0,
101+
step=1.0,
102+
disabled=panel.get_value("is_running", False),
103+
key="thermocouple_max_value",
104+
)
105+
with channel_middle:
106+
nipanel.enum_selectbox(
107+
panel,
108+
label="Units",
109+
value=TemperatureUnits.DEG_C,
110+
disabled=panel.get_value("is_running", False),
111+
key="thermocouple_units",
112+
)
113+
nipanel.enum_selectbox(
114+
panel,
115+
label="Thermocouple Type",
116+
value=ThermocoupleType.K,
117+
disabled=panel.get_value("is_running", False),
118+
key="thermocouple_type",
119+
)
120+
with channel_right:
121+
nipanel.enum_selectbox(
122+
panel,
123+
label="CJC Source",
124+
value=CJCSource.CONSTANT_USER_VALUE,
125+
disabled=panel.get_value("is_running", False),
126+
key="thermocouple_cjc_source",
127+
)
128+
st.number_input(
129+
"CJC Value",
130+
value=25.0,
131+
step=1.0,
132+
disabled=panel.get_value("is_running", False),
133+
key="thermocouple_cjc_val",
134+
)
57135

58-
voltage_tab.header("Voltage")
59-
with voltage_tab:
60-
channel_left, channel_right = st.columns(2)
61-
with channel_left:
62-
st.selectbox(options=["Dev1/ai0"], label="Physical Channels", disabled=True)
63-
st.number_input(
64-
"Min Value",
65-
value=-5.0,
66-
step=0.1,
67-
disabled=panel.get_value("is_running", False),
68-
key="voltage_min_value",
69-
)
70-
st.number_input(
71-
"Max Value",
72-
value=5.0,
73-
step=0.1,
74-
disabled=panel.get_value("is_running", False),
75-
key="voltage_max_value",
76-
)
77-
with channel_right:
78-
nipanel.enum_selectbox(
79-
panel,
80-
label="Terminal Configuration",
81-
value=TerminalConfiguration.DEFAULT,
82-
disabled=panel.get_value("is_running", False),
83-
key="terminal_configuration",
136+
# Timing Settings section in left column
137+
with st.container(border=True):
138+
st.header("Timing Settings")
139+
timing_left, timing_right = st.columns(2)
140+
with timing_left:
141+
st.selectbox(
142+
options=["OnboardClock"],
143+
label="Sample Clock Source",
144+
disabled=True,
84145
)
85-
86-
thermocouple_tab.header("Thermocouple")
87-
with thermocouple_tab:
88-
channel_left, channel_middle, channel_right = st.columns(3)
89-
with channel_left:
90-
st.selectbox(options=["Dev1/ai1"], label="Physical Channel", disabled=True)
91146
st.number_input(
92-
"Min Value",
93-
value=0.0,
94-
step=1.0,
147+
"Sample Rate",
148+
value=1000.0,
149+
step=100.0,
150+
min_value=1.0,
95151
disabled=panel.get_value("is_running", False),
96-
key="thermocouple_min_value",
152+
key="sample_rate_input",
97153
)
154+
with timing_right:
98155
st.number_input(
99-
"Max Value",
100-
value=100.0,
101-
step=1.0,
156+
"Samples per Loop",
157+
value=3000,
158+
step=100,
159+
min_value=10,
102160
disabled=panel.get_value("is_running", False),
103-
key="thermocouple_max_value",
161+
key="samples_per_channel",
104162
)
105-
with channel_middle:
106-
nipanel.enum_selectbox(
107-
panel,
108-
label="Units",
109-
value=TemperatureUnits.DEG_C,
110-
disabled=panel.get_value("is_running", False),
111-
key="thermocouple_units",
163+
st.text_input(
164+
label="Actual Sample Rate",
165+
value=str(sample_rate) if sample_rate else "",
166+
key="actual_sample_rate_display",
112167
)
113-
nipanel.enum_selectbox(
114-
panel,
115-
label="Thermocouple Type",
116-
value=ThermocoupleType.K,
117-
disabled=panel.get_value("is_running", False),
118-
key="thermocouple_type",
119-
)
120-
with channel_right:
121-
nipanel.enum_selectbox(
122-
panel,
123-
label="CJC Source",
124-
value=CJCSource.CONSTANT_USER_VALUE,
125-
disabled=panel.get_value("is_running", False),
126-
key="thermocouple_cjc_source",
127-
)
128-
st.number_input(
129-
"CJC Value",
130-
value=25.0,
131-
step=1.0,
132-
disabled=panel.get_value("is_running", False),
133-
key="thermocouple_cjc_val",
134-
)
135-
136-
# Timing Settings section in left column
137-
st.header("Timing Settings")
138-
timing_left, timing_right = st.columns(2)
139-
with timing_left:
140-
st.selectbox(
141-
options=["OnboardClock"],
142-
label="Sample Clock Source",
143-
disabled=True,
144-
)
145-
st.number_input(
146-
"Sample Rate",
147-
value=1000.0,
148-
step=100.0,
149-
min_value=1.0,
150-
disabled=panel.get_value("is_running", False),
151-
key="sample_rate_input",
152-
)
153-
with timing_right:
154-
st.number_input(
155-
"Samples per Loop",
156-
value=3000,
157-
step=100,
158-
min_value=10,
159-
disabled=panel.get_value("is_running", False),
160-
key="samples_per_channel",
161-
)
162-
st.text_input(
163-
label="Actual Sample Rate",
164-
value=str(sample_rate) if sample_rate else "",
165-
key="actual_sample_rate_display",
166-
)
167168

168169
# Right column - Graph and Logging Settings
169170
with right_col:
170-
# Graph section
171-
st.header("Voltage & Thermocouple")
172-
voltage_therm_graph = {
173-
"animation": False,
174-
"tooltip": {"trigger": "axis"},
175-
"legend": {"data": ["Voltage (V)", "Temperature (C)"]},
176-
"xAxis": {
177-
"type": "category",
178-
"data": [
179-
x / sample_rate if sample_rate > 0.001 else x for x in range(len(voltage_data))
180-
],
181-
"name": "Time",
182-
"nameLocation": "center",
183-
"nameGap": 40,
184-
},
185-
"yAxis": {
186-
"type": "value",
187-
"name": "Measurement",
188-
"nameRotate": 90,
189-
"nameLocation": "center",
190-
"nameGap": 40,
191-
},
192-
"series": [
193-
{
194-
"name": "voltage_amplitude",
195-
"type": "line",
196-
"data": voltage_data,
197-
"emphasis": {"focus": "series"},
198-
"smooth": True,
199-
"seriesLayoutBy": "row",
171+
with st.container(border=True):
172+
# Graph section
173+
st.header("Voltage & Thermocouple")
174+
voltage_therm_graph = {
175+
"animation": False,
176+
"tooltip": {"trigger": "axis"},
177+
"legend": {"data": ["Voltage (V)", "Temperature (C)"]},
178+
"xAxis": {
179+
"type": "category",
180+
"data": [
181+
x / sample_rate if sample_rate > 0.001 else x for x in range(len(voltage_data))
182+
],
183+
"name": "Time",
184+
"nameLocation": "center",
185+
"nameGap": 40,
200186
},
201-
{
202-
"name": "thermocouple_amplitude",
203-
"type": "line",
204-
"data": thermocouple_data,
205-
"color": "red",
206-
"emphasis": {"focus": "series"},
207-
"smooth": True,
208-
"seriesLayoutBy": "row",
187+
"yAxis": {
188+
"type": "value",
189+
"name": "Measurement",
190+
"nameRotate": 90,
191+
"nameLocation": "center",
192+
"nameGap": 40,
209193
},
210-
],
211-
}
212-
st_echarts(options=voltage_therm_graph, height="400px", key="voltage_therm_graph")
194+
"series": [
195+
{
196+
"name": "voltage_amplitude",
197+
"type": "line",
198+
"data": voltage_data,
199+
"emphasis": {"focus": "series"},
200+
"smooth": True,
201+
"seriesLayoutBy": "row",
202+
},
203+
{
204+
"name": "thermocouple_amplitude",
205+
"type": "line",
206+
"data": thermocouple_data,
207+
"color": "red",
208+
"emphasis": {"focus": "series"},
209+
"smooth": True,
210+
"seriesLayoutBy": "row",
211+
},
212+
],
213+
}
214+
st_echarts(options=voltage_therm_graph, height="446px", key="voltage_therm_graph")
213215

214216
# Logging Settings section in right column
215-
st.header("Logging Settings")
216-
logging_left, logging_right = st.columns(2)
217-
with logging_left:
218-
nipanel.enum_selectbox(
219-
panel,
220-
label="Logging Mode",
221-
value=LoggingMode.OFF,
222-
disabled=panel.get_value("is_running", False),
223-
key="logging_mode",
224-
)
225-
with logging_right:
226-
col1, col2 = st.columns([3, 1])
227-
with col1:
228-
tdms_file_path = st.text_input(
229-
label="TDMS File Path",
217+
with st.container(border=True):
218+
st.header("Logging Settings")
219+
logging_left, logging_right = st.columns(2)
220+
with logging_left:
221+
nipanel.enum_selectbox(
222+
panel,
223+
label="Logging Mode",
224+
value=LoggingMode.OFF,
230225
disabled=panel.get_value("is_running", False),
231-
value="data.tdms",
232-
key="tdms_file_path",
226+
key="logging_mode",
233227
)
228+
with logging_right:
229+
col1, col2 = st.columns([3, 1])
230+
with col1:
231+
tdms_file_path = st.text_input(
232+
label="TDMS File Path",
233+
disabled=panel.get_value("is_running", False),
234+
value="data.tdms",
235+
key="tdms_file_path",
236+
)

0 commit comments

Comments
 (0)