Skip to content

Commit

Permalink
Allow setting to_str on enum slider
Browse files Browse the repository at this point in the history
  • Loading branch information
harskish committed Apr 28, 2024
1 parent 37679bb commit 271432a
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 5 deletions.
3 changes: 2 additions & 1 deletion pyviewer/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

# Check imgui version
import imgui
assert hasattr(imgui, 'plot'), \
plot = getattr(imgui, 'plot')
assert plot, \
'Pyviewer requires a custom version of imgui that comes bundled with implot (github.com/harskish/pyimgui).\n' + \
'Please reinstall pyviewer to get the correct version.'
7 changes: 4 additions & 3 deletions pyviewer/params.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import imgui
from pyviewer.utils import enum_slider, combo_box_vals, slider_range_int, slider_range_float, strict_dataclass
from typing import Tuple
from typing import Tuple, Callable

""" Small param wrappers for automatically creating UI widgets """

Expand Down Expand Up @@ -48,12 +48,13 @@ def draw_widget(self):
return combo_box_vals(self.label, self.opts, self.value)

class EnumSliderParam(Param):
def __init__(self, label, default_val, valid_vals=(), tooltip: str = None) -> None:
def __init__(self, label, default_val, valid_vals=(), to_str: Callable[..., str] = str, tooltip: str = None) -> None:
super().__init__(type(default_val), label, default_val, tooltip)
self.opts = list(valid_vals)
self.to_str = to_str

def draw_widget(self):
return enum_slider(self.label, self.opts, self.value)
return enum_slider(self.label, self.opts, self.value, self.to_str)

class BoolParam(Param):
def __init__(self, label, default_val: bool, tooltip: str = None) -> None:
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
# or with: `rm -r build\ && pip wheel . && unzip -l pyviewer-*.whl`
# (not same environment, but good first step)
setup(name='pyviewer',
version='1.4.0',
version='1.4.1',
description='Interactyive python viewers',
author='Erik Härkönen',
author_email='[email protected]',
Expand Down

0 comments on commit 271432a

Please sign in to comment.