Skip to content

Commit e77345e

Browse files
Mike ProsserMike Prosser
authored andcommitted
cleanup
1 parent 3de247e commit e77345e

File tree

3 files changed

+14
-11
lines changed

3 files changed

+14
-11
lines changed

examples/all_types/define_types.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,9 @@ class MyIntFlags(enum.IntFlag):
1818
class MyIntableFlags(enum.Flag):
1919
"""Example of an Flag enum with int values."""
2020

21-
VALUE1 = 1
22-
VALUE2 = 2
23-
VALUE4 = 4
21+
VALUE8 = 8
22+
VALUE16 = 16
23+
VALUE32 = 32
2424

2525

2626
class MyIntEnum(enum.IntEnum):
@@ -75,7 +75,7 @@ class MyMixedEnum(enum.Enum):
7575
"intenum": MyIntEnum.VALUE20,
7676
"strenum": MyStrEnum.VALUE3,
7777
"intableenum": MyIntableEnum.VALUE200,
78-
"intableflags": MyIntableFlags.VALUE1 | MyIntableFlags.VALUE2,
78+
"intableflags": MyIntableFlags.VALUE8 | MyIntableFlags.VALUE32,
7979
"stringableenum": MyStringableEnum.VALUE2,
8080
"mixedenum": MyMixedEnum.VALUE2,
8181
# NI types
@@ -98,6 +98,6 @@ class MyMixedEnum(enum.Enum):
9898
# supported 2D collections
9999
"list_list_float": [[1.0, 2.0], [3.0, 4.0]],
100100
"tuple_tuple_float": ((1.0, 2.0), (3.0, 4.0)),
101-
"set_tuple_float": set([(1.0, 2.0), (3.0, 4.0)]),
101+
"set_list_float": set([(1.0, 2.0), (3.0, 4.0)]),
102102
"frozenset_frozenset_float": frozenset([frozenset([1.0, 2.0]), frozenset([3.0, 4.0])]),
103103
}

src/nipanel/controls/_flag_checkboxes.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
"""A set of checkboxes for selecting Flag enum values."""
22

33
from enum import Flag
4-
from typing import TypeVar
4+
from typing import TypeVar, Callable
55

66
import streamlit as st
77

@@ -16,6 +16,7 @@ def flag_checkboxes(
1616
value: T,
1717
key: str,
1818
disabled: bool = False,
19+
label_formatter: Callable[[Flag], str] = lambda x: str(x.name),
1920
) -> T:
2021
"""Create a set of checkboxes for a Flag enum.
2122
@@ -29,6 +30,8 @@ def flag_checkboxes(
2930
value: The default Flag enum value (also determines the specific Flag enum type)
3031
key: Key to use for storing the Flag value in the panel
3132
disabled: Whether the checkboxes should be disabled
33+
label_formatter: Function that formats the flag to a string for display. Default
34+
uses flag.name.
3235
3336
Returns:
3437
The selected Flag enum value with all selected flags combined
@@ -56,7 +59,7 @@ def flag_checkboxes(
5659
for flag in flag_values:
5760
is_selected = bool(selected_flags & flag)
5861
if flag_container.checkbox(
59-
label=str(flag.name),
62+
label=label_formatter(flag),
6063
value=is_selected,
6164
key=f"{key}_{flag.name}",
6265
disabled=disabled,

tests/unit/test_streamlit_panel.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -403,7 +403,7 @@ def test___set_int_enum_value___get_value___returns_int_enum(
403403
assert retrieved_value.name == enum_value.name
404404

405405

406-
def test___set_intable_enum_value___get_value___returns_enum(
406+
def test___set_intable_enum_value___get_value___returns_intable_enum(
407407
fake_panel_channel: grpc.Channel,
408408
) -> None:
409409
panel = StreamlitPanel("my_panel", "path/to/script", grpc_channel=fake_panel_channel)
@@ -435,7 +435,7 @@ def test___set_string_enum_value___get_value___returns_string_enum(
435435
assert retrieved_value.name == enum_value.name
436436

437437

438-
def test___set_stringable_enum_value___get_value___returns_enum(
438+
def test___set_stringable_enum_value___get_value___returns_stringable_enum(
439439
fake_panel_channel: grpc.Channel,
440440
) -> None:
441441
panel = StreamlitPanel("my_panel", "path/to/script", grpc_channel=fake_panel_channel)
@@ -451,7 +451,7 @@ def test___set_stringable_enum_value___get_value___returns_enum(
451451
assert retrieved_value.name == enum_value.name
452452

453453

454-
def test___set_mixed_enum_value___get_value___returns_enum(
454+
def test___set_mixed_enum_value___get_value___returns_mixed_enum(
455455
fake_panel_channel: grpc.Channel,
456456
) -> None:
457457
panel = StreamlitPanel("my_panel", "path/to/script", grpc_channel=fake_panel_channel)
@@ -482,7 +482,7 @@ def test___set_int_flags_value___get_value___returns_int_flags(
482482
assert retrieved_value.value == flags_value.value
483483

484484

485-
def test___set_intable_flags_value___get_value___returns_flags(
485+
def test___set_intable_flags_value___get_value___returns_intable_flags(
486486
fake_panel_channel: grpc.Channel,
487487
) -> None:
488488
panel = StreamlitPanel("my_panel", "path/to/script", grpc_channel=fake_panel_channel)

0 commit comments

Comments
 (0)